46 lines
2.2 KiB
C#
46 lines
2.2 KiB
C#
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Platformer.Mechanics;
|
||
using UnityEditor;
|
||
using UnityEditor.SceneManagement;
|
||
using UnityEngine;
|
||
|
||
/// <summary>
|
||
/// 리뉴얼 2026-11-10 (PD 지시 「무한 스크롤 중 적은 새로 스크롤되는 화면에 랜덤 등장」) —
|
||
/// Ingame 씬의 미리 놓인 적을 끄고 무한 적 생성기를 둔다. 생성 프리팹 = 미리 놓인 적들의 원본 프리팹.
|
||
/// </summary>
|
||
public static class RunnerRenewalSetup
|
||
{
|
||
const string ScenePath = "Assets/Scenes/Ingame.unity";
|
||
const string SpawnerName = "EnemySpawner_Endless";
|
||
|
||
[MenuItem("Tools/Renewal/5. Endless Enemy Spawner")]
|
||
public static string SetupSpawner()
|
||
{
|
||
var scene = EditorSceneManager.GetActiveScene();
|
||
if (scene.path != ScenePath) scene = EditorSceneManager.OpenScene(ScenePath);
|
||
var enemies = Object.FindObjectsByType<EnemyController>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||
var sources = new Dictionary<string, int>();
|
||
var prefabs = new List<GameObject>();
|
||
foreach (var e in enemies)
|
||
{
|
||
var src = PrefabUtility.GetCorrespondingObjectFromSource(e.gameObject);
|
||
string path = src != null ? AssetDatabase.GetAssetPath(src) : "(프리팹 아님)";
|
||
sources[path] = sources.TryGetValue(path, out var n) ? n + 1 : 1;
|
||
if (src != null && !prefabs.Contains(src)) prefabs.Add(src);
|
||
Undo.RecordObject(e.gameObject, "Disable placed enemy");
|
||
e.gameObject.SetActive(false);
|
||
}
|
||
var root = GameObject.Find(SpawnerName);
|
||
if (root == null) root = new GameObject(SpawnerName);
|
||
var sp = root.GetComponent<EndlessEnemySpawner>();
|
||
if (sp == null) sp = root.AddComponent<EndlessEnemySpawner>();
|
||
sp.enemyPrefabs = prefabs.OrderBy(p => p.name).ToArray();
|
||
EditorUtility.SetDirty(sp);
|
||
EditorSceneManager.MarkSceneDirty(scene);
|
||
EditorSceneManager.SaveScene(scene);
|
||
return $"미리 놓인 적 {enemies.Length} 끔 · 원본 프리팹: " + string.Join(", ", sources.Select(kv => $"{kv.Key}×{kv.Value}")) +
|
||
$" · 생성기 프리팹 {sp.enemyPrefabs.Length}종";
|
||
}
|
||
}
|