Пример #1
0
        /// <summary>
        /// Connects to a <see cref="T:UnityEngine.ScriptableObject" /> asset.
        /// If the asset already exists at the given path, loads it and returns it.
        /// Otherwise, either returns NULL or automatically creates it before loading and returning it
        /// (depending on the given parameters).
        /// </summary>
        /// <typeparam name="T">Asset type</typeparam>
        /// <param name="adbFilePath">File path (relative to Unity's project folder)</param>
        /// <param name="createIfMissing">If TRUE and the requested asset doesn't exist, forces its creation</param>
        public static T ConnectToSourceAsset <T>(string adbFilePath, bool createIfMissing = false) where T : ScriptableObject
        {
            if (!EditorUtils.AssetExists(adbFilePath))
            {
                if (!createIfMissing)
                {
                    return(default(T));
                }
                EditorUtils.CreateScriptableAsset <T>(adbFilePath);
            }
            T obj = (T)AssetDatabase.LoadAssetAtPath(adbFilePath, typeof(T));

            if ((UnityEngine.Object)obj == (UnityEngine.Object)null)
            {
                EditorUtils.CreateScriptableAsset <T>(adbFilePath);
                obj = (T)AssetDatabase.LoadAssetAtPath(adbFilePath, typeof(T));
            }
            return(obj);
        }