增加怪物功能,调整灵灯参数
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using IndianOceanAssets.Engine2_5D;
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器工具:基于原始 Enemy Prefab 批量创建 5 个不同外观的敌人预制体。
|
||||
/// 每个预制体使用不同的 Sprite,保留所有原有组件和参数。
|
||||
/// 菜单路径:Assets > 创建5个敌人预制体
|
||||
/// </summary>
|
||||
public static class EnemyPrefabBatchCreator
|
||||
{
|
||||
[MenuItem("Assets/创建5个敌人预制体")]
|
||||
public static void Create()
|
||||
{
|
||||
// 加载原始敌人 Prefab
|
||||
string originalPath = "Assets/2.5D Engine/Enemy.prefab";
|
||||
var originalPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(originalPath);
|
||||
if (originalPrefab == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("错误", "找不到原始敌人 Prefab: " + originalPath, "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保输出目录存在
|
||||
string outputDir = "Assets/enemy/Prefabs";
|
||||
if (!AssetDatabase.IsValidFolder(outputDir))
|
||||
{
|
||||
string parent = "Assets/enemy";
|
||||
AssetDatabase.CreateFolder(parent, "Prefabs");
|
||||
}
|
||||
|
||||
// 5个敌人的 Sprite 路径和名称
|
||||
string[] spritePaths = {
|
||||
"Assets/enemy/sprites/enemy1.png",
|
||||
"Assets/enemy/sprites/enemy2.png",
|
||||
"Assets/enemy/sprites/enemy3.png",
|
||||
"Assets/enemy/sprites/enemy4.png",
|
||||
"Assets/enemy/sprites/enemy5.png",
|
||||
};
|
||||
string[] prefabNames = { "enemy_01", "enemy_02", "enemy_03", "enemy_04", "enemy_05" };
|
||||
|
||||
int created = 0;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
// 加载 Sprite
|
||||
Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(spritePaths[i]);
|
||||
if (sprite == null)
|
||||
{
|
||||
Debug.LogWarning($"[EnemyPrefabCreator] 找不到 Sprite: {spritePaths[i]},跳过");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 实例化原始 Prefab
|
||||
GameObject instance = Object.Instantiate(originalPrefab);
|
||||
instance.name = prefabNames[i];
|
||||
|
||||
// 替换主 Sprite(查找根物体或 GFX 子物体的 SpriteRenderer)
|
||||
SpriteRenderer mainSR = instance.GetComponentInChildren<SpriteRenderer>();
|
||||
if (mainSR != null)
|
||||
{
|
||||
mainSR.sprite = sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果没有 SpriteRenderer,添加一个
|
||||
mainSR = instance.AddComponent<SpriteRenderer>();
|
||||
mainSR.sprite = sprite;
|
||||
mainSR.sortingOrder = 1;
|
||||
}
|
||||
|
||||
// 保存为新 Prefab
|
||||
string prefabPath = $"{outputDir}/{prefabNames[i]}.prefab";
|
||||
PrefabUtility.SaveAsPrefabAsset(instance, prefabPath);
|
||||
Object.DestroyImmediate(instance);
|
||||
|
||||
created++;
|
||||
Debug.Log($"[EnemyPrefabCreator] 创建: {prefabPath} (Sprite: {sprite.name})");
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
// 高亮输出目录
|
||||
var folder = AssetDatabase.LoadAssetAtPath<Object>(outputDir);
|
||||
if (folder != null)
|
||||
{
|
||||
Selection.activeObject = folder;
|
||||
EditorGUIUtility.PingObject(folder);
|
||||
}
|
||||
|
||||
Debug.Log($"[EnemyPrefabCreator] 完成!共创建 {created} 个敌人预制体于 {outputDir}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user