Beispiel #1
0
    //********************************************************************************************
    //
    //********************************************************************************************

    public static T Load(ASSET_OPTION option)
    {
        T instance = null;

        if ((Exist()) || Create(option))
        {
            string classname = typeof(T).ToString();

            string resname = (option == ASSET_OPTION.CREATE_SUBDIR) ? classname + "/" + classname : classname;

            UnityEngine.Debug.Log("Loading res " + resname);

            instance = Resources.Load <T>(resname);
        }

        return(instance);
    }
Beispiel #2
0
    //********************************************************************************************
    //
    //********************************************************************************************

    public static bool Create(ASSET_OPTION option)
    {
                #if UNITY_EDITOR
        string classname = typeof(T).ToString();

        string filename = classname + ".asset";

        string directory = CreateDirectory(option);

        AssetDatabase.CreateAsset(ScriptableObject.CreateInstance <T>(), directory + "/" + filename);

        AssetDatabase.SaveAssets();

        UnityEngine.Debug.Log("Created asset " + filename);

        return(true);
                #else
        return(false);
                #endif
    }
Beispiel #3
0
    //********************************************************************************************
    //
    //********************************************************************************************

    public static string CreateDirectory(ASSET_OPTION option)
    {
                #if UNITY_EDITOR
        string classname = typeof(T).ToString();

        string directory = Application.dataPath + "/" + m_resourcesDir; if (option == ASSET_OPTION.CREATE_SUBDIR)
        {
            directory += ("/" + classname);
        }

        string unity_directory = UnityEditor.FileUtil.GetProjectRelativePath(directory);

        if (System.IO.Directory.Exists(directory) == false)
        {
            System.IO.Directory.CreateDirectory(directory);
        }

        return(unity_directory);
        #else
        return(string.Empty);
        #endif
    }