feat(wizard): 敌人能力 SO 按能力类型创建正确子类(向导批量创建产出子类 SO)
This commit is contained in:
@@ -171,6 +171,30 @@ namespace BaseGames.Editor
|
||||
return asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按运行时 Type 创建 SO 资产(用于需要动态子类型的场景,如能力子类 SO)。
|
||||
/// 若资产已存在则返回 null(不覆盖);成功后自动 Ping 并选中。
|
||||
/// </summary>
|
||||
public static ScriptableObject CreateSOAsset(System.Type soType, string folder, string assetName)
|
||||
{
|
||||
string dir = folder.TrimEnd('/');
|
||||
string path = $"{dir}/{assetName}.asset";
|
||||
|
||||
if (AssetDatabase.LoadAssetAtPath<ScriptableObject>(path) != null)
|
||||
{
|
||||
Debug.LogWarning($"[EditorScaffoldUtils] 资产已存在,跳过创建:{path}");
|
||||
return null;
|
||||
}
|
||||
|
||||
EnsureFolder(dir);
|
||||
|
||||
var asset = ScriptableObject.CreateInstance(soType);
|
||||
AssetDatabase.CreateAsset(asset, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
PingAndSelect(asset);
|
||||
return asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 SaveFilePanel 让用户选择名称和路径,交互式创建 SO 资产。
|
||||
/// 取消时返回 null。
|
||||
|
||||
Reference in New Issue
Block a user