using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; public class Unitil { #if UNITY_EDITOR /// /// 获取创建配置文件的路径【全】 /// /// 泛型 /// AssetDatabase 路径 /// 文件后缀 /// 创建配置文件路径【全】 public static string TryGetName(string str, string buff = ".asset") { int index = 0;//下标 string s = "";//自定义文件名(完整的)【需拼接】 Object obj = null; do//如果能找到 obj就循环,否则停止 { s = str + "/" + typeof(T).Name + "_" + index + buff; //AssetDatabase 路径 + 文件名 + 下标 + 后缀名 obj = AssetDatabase.LoadAssetAtPath(s, typeof(T)); //通过路径、类型进行寻找【找到有就循环,没有停止】 index++;//名字下标+1,取名唯一 } while (obj); return s;//返回 创建配置文件路径【全】 } #endif }