摄像机区域的架构改动
This commit is contained in:
82
Assets/_Game/Scripts/Editor/Shared/EditorScaffoldUtils.cs
Normal file
82
Assets/_Game/Scripts/Editor/Shared/EditorScaffoldUtils.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器工具通用静态方法,供各窗口、向导共享调用。
|
||||
/// </summary>
|
||||
public static class EditorScaffoldUtils
|
||||
{
|
||||
// ── SO 资产创建 ───────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// 在指定文件夹(Assets 相对路径)创建 SO 资产。
|
||||
/// 若资产已存在则返回 null(不覆盖);成功后自动 Ping 并选中。
|
||||
/// </summary>
|
||||
public static T CreateSOAsset<T>(string folder, string assetName) where T : ScriptableObject
|
||||
{
|
||||
string dir = folder.TrimEnd('/');
|
||||
string path = $"{dir}/{assetName}.asset";
|
||||
|
||||
if (AssetDatabase.LoadAssetAtPath<T>(path) != null)
|
||||
{
|
||||
Debug.LogWarning($"[EditorScaffoldUtils] 资产已存在,跳过创建:{path}");
|
||||
return null;
|
||||
}
|
||||
|
||||
EnsureFolder(dir);
|
||||
|
||||
var asset = ScriptableObject.CreateInstance<T>();
|
||||
AssetDatabase.CreateAsset(asset, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
PingAndSelect(asset);
|
||||
return asset;
|
||||
}
|
||||
|
||||
// ── 目录工具 ──────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>确保 Assets 相对路径目录存在(不存在则递归创建)。</summary>
|
||||
public static void EnsureFolder(string assetPath)
|
||||
{
|
||||
string projectRoot = Path.GetDirectoryName(Application.dataPath)!;
|
||||
string fullPath = Path.Combine(projectRoot, assetPath.Replace('/', Path.DirectorySeparatorChar));
|
||||
if (!Directory.Exists(fullPath))
|
||||
Directory.CreateDirectory(fullPath);
|
||||
}
|
||||
|
||||
// ── 资产查找 ──────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// 查找 Project 中所有指定 ScriptableObject 类型的资产(不含 Packages)。
|
||||
/// </summary>
|
||||
public static List<T> FindAllAssetsOfType<T>() where T : ScriptableObject
|
||||
{
|
||||
var result = new List<T>();
|
||||
string[] guids = AssetDatabase.FindAssets($"t:{typeof(T).Name}");
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
// 排除 Packages 目录
|
||||
if (path.StartsWith("Packages/", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
var asset = AssetDatabase.LoadAssetAtPath<T>(path);
|
||||
if (asset != null)
|
||||
result.Add(asset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── 选中 / Ping ───────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Ping 并选中 Project 中的资产。</summary>
|
||||
public static void PingAndSelect(UnityEngine.Object asset)
|
||||
{
|
||||
EditorGUIUtility.PingObject(asset);
|
||||
Selection.activeObject = asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf604376607014a429f588969c75dc57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user