GQ_Communicate/GQ_URP/GQ/Assets/script/ScriptabLeObject/Unitil.cs

35 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Unitil
{
#if UNITY_EDITOR
/// <summary>
/// 获取创建配置文件的路径【全】
/// </summary>
/// <typeparam name="T">泛型</typeparam>
/// <param name="str">AssetDatabase 路径</param>
/// <param name="buff">文件后缀</param>
/// <returns>创建配置文件路径【全】</returns>
public static string TryGetName<T>(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
}