示例#1
0
        private static Dictionary <string, string> CreateReplaceNamePairDictionary(TemplateProperty property, Dictionary <string, string> replaceList)
        {
            var dic = new Dictionary <string, string>();

            if (property.replaceList != null)
            {
                foreach (var def in property.replaceList)
                {
                    var serchStr   = string.Format(replceStringFormat, def.searchString);
                    var replaceStr = replaceList.ContainsKey(def.ID) ? replaceList[def.ID] : string.Empty;
                    dic.Add(serchStr, replaceStr);
                }
            }
            return(dic);
        }
示例#2
0
        private static string CreateReplacedDistinationPath(TemplateProperty property, string destinationPath, Dictionary <string, string> replaceLsit)
        {
            var replacedPath = destinationPath;

            if (property.replaceList != null)
            {
                foreach (var def in property.replaceList)
                {
                    var serchStr   = string.Format(replceStringFormat, def.searchString);
                    var replaceStr = replaceLsit.ContainsKey(def.ID) ? replaceLsit[def.ID] : string.Empty;
                    replacedPath = replacedPath.Replace(serchStr, replaceStr);
                }
            }
            return(replacedPath);
        }
示例#3
0
        /// <summary>
        /// テンプレート情報を取得する
        /// </summary>
        /// <param name="name">テンプレートのフォルダ名</param>
        /// <returns><テンプレート情報オブジェクト</returns>
        public static TemplateProperty GetTemplateProperty(string name)
        {
            var rootPath = GetTemplatesFolderPath() + Path.AltDirectorySeparatorChar + name;
            var guids    = AssetDatabase.FindAssets("t:TemplateProperty", new string[] { rootPath });
            TemplateProperty property = null;

            if (guids.Length >= 2)
            {
                Debug.LogWarning("複数のテンプレート情報ファイルが存在します。");
            }
            else if (guids.Length == 1)
            {
                var propertyFilePath = AssetDatabase.GUIDToAssetPath(guids[0]);
                property = AssetDatabase.LoadAssetAtPath <TemplateProperty>(propertyFilePath);
            }
            else
            {
                Debug.LogWarning("テンプレート情報ファイルがみつかりませんでした。");
            }
            return(property ?? ScriptableObject.CreateInstance <TemplateProperty>());
        }
        /// <summary>
        /// テンプレート情報を取得する
        /// </summary>
        /// <param name="name">テンプレートのフォルダ名</param>
        /// <returns><テンプレート情報オブジェクト</returns>
        public static TemplateProperty GetTemplateProperty(string name)
        {
            var rootPath = GetTemplatesFolderPath() + Path.AltDirectorySeparatorChar + name;
            var guids    = AssetDatabase.FindAssets("t:TemplateProperty", new string[] { rootPath });
            TemplateProperty property = null;

            if (guids.Length >= 2)
            {
                Debug.LogWarning(LocalizedMessage.Get("TemplateLoader.InformationFileDuplicated"));
            }
            else if (guids.Length == 1)
            {
                var propertyFilePath = AssetDatabase.GUIDToAssetPath(guids[0]);
                property = AssetDatabase.LoadAssetAtPath <TemplateProperty>(propertyFilePath);
            }
            else
            {
                Debug.LogWarning(LocalizedMessage.Get("TemplateLoader.InformationFileNotFound"));
            }
            return(property ?? ScriptableObject.CreateInstance <TemplateProperty>());
        }
示例#5
0
        private static void ReplaceObjectReference(Dictionary <string, TemplateAsset> assetDictionary, TemplateProperty property, Dictionary <string, string> replaceList)
        {
            var replaceGuidPairDictionary = CreateReplaceGuidPairDictionary(assetDictionary);
            var replaceNamePairDictionary = CreateReplaceNamePairDictionary(property, replaceList);

            if (replaceGuidPairDictionary.Count > 0)
            {
                foreach (var ta in assetDictionary.Values)
                {
                    IReferenceModifier modifier = BuildReferenceModifier(ta, replaceGuidPairDictionary, replaceNamePairDictionary);
                    if (modifier != null)
                    {
                        modifier.Modify(ta.destinationPath);
                    }
                }
            }
        }
示例#6
0
        private static void ReplaceAssetFileName(Dictionary <string, TemplateAsset> assetDictionary, TemplateProperty property, Dictionary <string, string> replaceList)
        {
            var log = "Loading (ReplaceAssetFileName)" + Environment.NewLine;
            //置換中一時パスのリスト
            var tempPathDictionary = new Dictionary <string, string>();

            foreach (var ta in assetDictionary.Values)
            {
                tempPathDictionary.Add(ta.destinationPath, ta.destinationPath);
            }

            // 置換前のコピー先パス長の昇順で処理
            IOrderedEnumerable <KeyValuePair <string, TemplateAsset> > ordered =
                assetDictionary.OrderBy(selector =>
            {
                return(selector.Value.destinationPath.Length);
            });

            foreach (KeyValuePair <string, TemplateAsset> pair in ordered)
            {
                var ta = pair.Value;
                //一時パス
                var before = tempPathDictionary[ta.destinationPath];
                //最終パス
                var after      = ta.replacedDestinationPath;
                var moveResult = AssetDatabase.MoveAsset(before, after);
                log += "from:" + ta.destinationPath + " to:" + ta.replacedDestinationPath + Environment.NewLine;
                if (!string.IsNullOrEmpty(moveResult))
                {
                    log += moveResult + Environment.NewLine;
                }
                //一時パスの置換
                if (ta.IsFolder)
                {
                    foreach (var p in ordered)
                    {
                        var tmpPath = tempPathDictionary[p.Value.destinationPath];
                        if (tmpPath.IndexOf(before) == 0 &&
                            (tmpPath.Length == before.Length || tmpPath[before.Length] == Path.AltDirectorySeparatorChar))
                        {
                            tempPathDictionary[p.Value.destinationPath] = tmpPath.Replace(before, after);
                        }
                    }
                }
            }
            Debug.Log(log);
        }
示例#7
0
 private static void ReplaceSceneObjectNames(Dictionary <string, TemplateAsset> assetDictionary, TemplateProperty property, Dictionary <string, string> replaceList)
 {
     foreach (var ta in assetDictionary.Values)
     {
         if (AssetDatabase.GetMainAssetTypeAtPath(ta.replacedDestinationPath) != typeof(SceneAsset))
         {
             continue;
         }
         var scene = EditorSceneManager.OpenScene(ta.replacedDestinationPath, OpenSceneMode.Additive);
         foreach (var rootObject in scene.GetRootGameObjects())
         {
             foreach (var t in rootObject.GetComponentsInChildren <Transform>())
             {
                 //Debug.Log(t.gameObject.name);
                 ReplaceSceneObjectName(t.gameObject, property.replaceList, replaceList);
             }
         }
         EditorSceneManager.SaveScene(scene);
         EditorSceneManager.CloseScene(scene, true);
     }
 }
示例#8
0
        private static void ModifyCopiedAssets(Dictionary <string, TemplateAsset> assetDictionary, TemplateProperty property, Dictionary <string, string> replaceList)
        {
            foreach (var ta in assetDictionary.Values)
            {
                //Remove readonly label
                var asset  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(ta.destinationPath);
                var labels = AssetDatabase.GetLabels(asset);
                labels = labels.Where(label => label != readonlyLabel).ToArray();
                AssetDatabase.SetLabels(asset, labels.ToArray());
                //Delete dummy assets
                if (ta.IsDummyAsset)
                {
                    AssetDatabase.DeleteAsset(ta.destinationPath);
                }
            }

            ReplaceObjectReference(assetDictionary, property, replaceList);

            //Replace Asset file names
            ReplaceAssetFileName(assetDictionary, property, replaceList);

            //Replace Scene object names
            ReplaceSceneObjectNames(assetDictionary, property, replaceList);
        }