Пример #1
0
 void AssetUnitBasicIn.SetContent <AssetContentType>(BasicAssetInParam <AssetContentType> settingParam, AssetInResultListener <AssetContentType> listener)
 {
     try {
         var nObj = namedObjects.Find((elem) => settingParam.contentPath == elem.path);
         if (nObj != null)
         {
             if (settingParam.doOverwrite)
             {
                 nObj.path = settingParam.contentPath;
                 listener.OnOverwrite();
                 return;
             }
             //stub
             //string new Path = listener.OnRequestPathChange();
         }
         namedObjects.Add(new AssetContentAndPath {
             content = settingParam.content, path = settingParam.contentPath
         });
         listener.OnSuccess();
     } catch (System.Exception e) {
         Debug.LogError(e);
         listener.OnFail();
     }
 }
Пример #2
0
 AssetAddResult <AssetContentType> BasicAssetIn.SetContent <AssetContentType>(BasicAssetInParam <AssetContentType> settingParam)
 {
     try {
         var assetRootPath = Path.GetDirectoryName(assetUnitInfo.localref);
         if (!Directory.Exists(assetRootPath))
         {
             Directory.CreateDirectory(assetRootPath);
         }
         var assetPath = assetRootPath + "/" + settingParam.assetPath;
         if (typeof(AssetContentType) == typeof(GameObject))
         {
             var        gObj       = (GameObject)Convert.ChangeType(settingParam.content, typeof(GameObject));
             GameObject oldPrefab  = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);
             GameObject newContent = null;
             if (oldPrefab != null && settingParam.doOverwrite)
             {
                 newContent = PrefabUtility.ReplacePrefab(gObj, oldPrefab);
             }
             else
             {
                 newContent = PrefabUtility.CreatePrefab(assetPath, gObj);
             }
             EditorUtility.SetDirty(newContent);
             AssetDatabase.SaveAssets();
             return(new AssetAddResult <AssetContentType> {
                 permanentContent = (AssetContentType)Convert.ChangeType(newContent, typeof(AssetContentType)), didSuccess = true
             });
         }
         else if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(AssetContentType)))
         {
             UnityEngine.Object obj = (UnityEngine.Object)(object) settingParam.content;
             var oldAssetPath       = AssetDatabase.GetAssetPath(obj);
             if (Utilities.IsStringEmpty(oldAssetPath))
             {
                 AssetDatabase.CreateAsset(obj, assetPath);
             }
             else
             {
                 if (oldAssetPath.StartsWith("Assets/"))
                 {
                     AssetDatabase.MoveAsset(oldAssetPath, assetPath);
                 }
                 else
                 {
                     if (typeof(AssetContentType) == typeof(Material))
                     {
                         AssetDatabase.CreateAsset(new Material((Material)(object)obj), assetPath);
                     }
                 }
             }
             EditorUtility.SetDirty(obj);
             AssetDatabase.SaveAssets();
             return(new AssetAddResult <AssetContentType> {
                 permanentContent = settingParam.content, didSuccess = true
             });
         }
         else if (typeof(CommonAssetRef).IsAssignableFrom(typeof(AssetContentType)))
         {
             if (File.Exists(assetPath) && settingParam.doOverwrite)
             {
                 try {
                     return(new AssetAddResult <AssetContentType> {
                         didSuccess = false, permanentContent = RequiredFuncs.FromJsonAtPath <AssetContentType>(assetPath)
                     });
                 } catch { return(new AssetAddResult <AssetContentType> {
                         didSuccess = false
                     }); }
             }
             File.WriteAllText(assetPath, RequiredFuncs.ToJson(settingParam.content));
             //AssetDatabase.Refresh();
             //AssetDatabase.SaveAssets();
             return(new AssetAddResult <AssetContentType> {
                 permanentContent = settingParam.content, didSuccess = true
             });
         }
     } catch (Exception e) { Debug.LogError(e); }
     return(new AssetAddResult <AssetContentType> {
         didSuccess = false
     });
 }
Пример #3
0
 void AssetUnitBasicIn.SetContent <ContentType>(BasicAssetInParam <ContentType> settingParam, AssetInResultListener <ContentType> listener)
 {
     listener.OnFail();
 }