// 프로젝트 전체에서 스크립트 이름으로 에셋 탐색
// 중복된 이름의 스크립트가 있으면 문제 발생할 수 있음
public static string GetScriptAssetNameToPath(string assetName, bool fullPath = false)
{
    string[] paths = AssetDatabase.FindAssets($"t:Script {assetName}");
    if (paths.Length <= 0)
    {
        Debug.LogError("Asset does not exist in the path - " + assetName);
        return null;
    }
    string path = AssetDatabase.GUIDToAssetPath(paths[0]);
    if (fullPath) return path;
    return path.Substring(0, path.LastIndexOf("/"));
}

// Monobehaviour를 상속받는 클래스 타입명으로 에셋 탐색
// Editor 및 Monobehaviour 상속 클래스가 아니면 사용 불가능.
public static string GetMonoScriptAssetPath(MonoBehaviour scriptObj, bool fullPath = false)
{
    string path = AssetDatabase.GetAssetPath(MonoScript.FromMonoBehaviour(scriptObj));
    if (fullPath) return path;
    return path.Substring(0, path.LastIndexOf("/"));
}


// 사용 예시
string findAssetPath = GetScriptAssetNameToPath("UsefulPainterTool") + "Textures/MaskTexture.png";
string findAssetPath = GetMonoScriptAssetPath(this) + "Textures/MaskTexture.png";

 

 

 

 


WRITTEN BY
CatDarkGame
Technical Artist dhwlgn12@gmail.com

,