Browse Source

测试新的工具

LiuQilin 7 years ago
parent
commit
87ad65bc8c
30 changed files with 1211 additions and 0 deletions
  1. 9 0
      Assets/RecyclePool.meta
  2. 9 0
      Assets/Tookits.meta
  3. 9 0
      Assets/Tookits/DeleteUtility.meta
  4. 102 0
      Assets/Tookits/DeleteUtility/DeleteUtility.cs
  5. 12 0
      Assets/Tookits/DeleteUtility/DeleteUtility.cs.meta
  6. 54 0
      Assets/Tookits/DeleteUtility/DeleteUtility.prefab
  7. 8 0
      Assets/Tookits/DeleteUtility/DeleteUtility.prefab.meta
  8. 9 0
      Assets/Tookits/DeleteUtility/Editor.meta
  9. 81 0
      Assets/Tookits/DeleteUtility/Editor/DeleteUtilityWindow.cs
  10. 12 0
      Assets/Tookits/DeleteUtility/Editor/DeleteUtilityWindow.cs.meta
  11. 44 0
      Assets/Tookits/DeleteUtility/ExPath.cs
  12. 12 0
      Assets/Tookits/DeleteUtility/ExPath.cs.meta
  13. 37 0
      Assets/Tookits/DeleteUtility/InstanceManager.cs
  14. 12 0
      Assets/Tookits/DeleteUtility/InstanceManager.cs.meta
  15. 9 0
      Assets/Tookits/LabelUtility.meta
  16. 9 0
      Assets/Tookits/LabelUtility/Editor.meta
  17. 37 0
      Assets/Tookits/LabelUtility/Editor/InstanceManager.cs
  18. 12 0
      Assets/Tookits/LabelUtility/Editor/InstanceManager.cs.meta
  19. 100 0
      Assets/Tookits/LabelUtility/Editor/InstanceUtility.cs
  20. 12 0
      Assets/Tookits/LabelUtility/Editor/InstanceUtility.cs.meta
  21. 132 0
      Assets/Tookits/LabelUtility/Editor/LabelSetDrawer.cs
  22. 12 0
      Assets/Tookits/LabelUtility/Editor/LabelSetDrawer.cs.meta
  23. 79 0
      Assets/Tookits/LabelUtility/Editor/LabelUtilityWindow.cs
  24. 12 0
      Assets/Tookits/LabelUtility/Editor/LabelUtilityWindow.cs.meta
  25. 39 0
      Assets/Tookits/LabelUtility/ExPath.cs
  26. 12 0
      Assets/Tookits/LabelUtility/ExPath.cs.meta
  27. 260 0
      Assets/Tookits/LabelUtility/LabelUtility.cs
  28. 12 0
      Assets/Tookits/LabelUtility/LabelUtility.cs.meta
  29. 56 0
      Assets/Tookits/LabelUtility/LabelUtility.prefab
  30. 8 0
      Assets/Tookits/LabelUtility/LabelUtility.prefab.meta

+ 9 - 0
Assets/RecyclePool.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 8ce5835bcad365c4bbf78291013ede92
+folderAsset: yes
+timeCreated: 1512443316
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/Tookits.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: f9f73c12a8331ff4e9baf58398c9bd45
+folderAsset: yes
+timeCreated: 1512443241
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/Tookits/DeleteUtility.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: c6575c83355e8314bbc488fed8443848
+folderAsset: yes
+timeCreated: 1512443283
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 102 - 0
Assets/Tookits/DeleteUtility/DeleteUtility.cs

@@ -0,0 +1,102 @@
+namespace deleteUtility
+{
+
+
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using UnityEditor;
+using UnityEngine;
+
+public class DeleteUtility : MonoBehaviour
+{
+    #region Config
+
+    public string Folder;
+    
+    #endregion
+
+    [MenuItem("Assets/RecycleAll", false, 0)]
+    public static void RecycleAll()
+    {
+        if (!EditorUtility.DisplayDialog("注意", "回收选择的对象?", "确定", "取消"))
+        {
+            return;
+        }
+
+        for (int i = 0; i < Selection.objects.Length; i++)
+        {
+            string path = AssetDatabase.GetAssetPath(Selection.objects[i]);
+            string metaFilePath = path + ".meta";
+            bool isDirectory = Directory.Exists(path);
+            if (isDirectory)
+            {
+                List<string> childPathes = new List<string>();
+                childPathes = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).ToList();
+                for (int j = 0; j < childPathes.Count; j++)
+                {
+                    BlockObect(childPathes[j]);
+                }
+            }
+            else
+            {
+                BlockObect(path);
+            }
+            DeleteUtility instance = InstanceManager.SearchInstance<DeleteUtility>();
+            if (isDirectory)
+            {
+                string recyclePath = $"{instance.Folder}{Path.DirectorySeparatorChar}{Path.GetFileName(path)}";
+                recyclePath = recyclePath.GetUnRepeatDirectoryName();
+                Directory.Move(path, recyclePath);
+                File.Delete(metaFilePath);
+                Debug.LogWarning($"回收文件夹 {Selection.objects[i].name}");
+                AssetDatabase.Refresh();
+            }
+            else
+            {
+                string recyclePath = $"{instance.Folder}{Path.DirectorySeparatorChar}{Path.GetFileName(path)}";
+                recyclePath = recyclePath.GetUnRepeatFileName();
+                File.Move(path, recyclePath);
+                File.Delete(metaFilePath);
+                Debug.Log($"回收文件 {Selection.objects[i].name}");
+                AssetDatabase.Refresh();
+            }
+        }
+	}
+
+    private static void BlockObect(string path)
+    {
+        if (path.EndsWith(".cs"))
+        {
+            StringBuilder stringBuilder = new StringBuilder();
+            StreamReader streamReader = new StreamReader(path);
+            while (!streamReader.EndOfStream)
+            {
+                stringBuilder.AppendLine("//" + streamReader.ReadLine());
+            }
+            streamReader.Close();
+            StreamWriter streamWriter = new StreamWriter(path);
+            streamWriter.Write(stringBuilder.ToString());
+            streamWriter.Close();
+        }
+
+        AssetImporter assetImporter = AssetImporter.GetAtPath(path);
+        if (assetImporter != null && assetImporter.assetBundleName != "" && assetImporter.assetBundleVariant != "")
+        {
+            assetImporter.SetAssetBundleNameAndVariant("", "");
+            assetImporter.SaveAndReimport();
+        }
+
+        TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
+        if (textureImporter != null && textureImporter.spritePackingTag != "")
+        {
+            textureImporter.spritePackingTag = "";
+            textureImporter.SaveAndReimport();
+        }
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/DeleteUtility/DeleteUtility.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: f43b3657624620d47b877b029db31391
+timeCreated: 1512348444
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 54 - 0
Assets/Tookits/DeleteUtility/DeleteUtility.prefab

@@ -0,0 +1,54 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!1001 &100100000
+Prefab:
+  m_ObjectHideFlags: 1
+  serializedVersion: 2
+  m_Modification:
+    m_TransformParent: {fileID: 0}
+    m_Modifications: []
+    m_RemovedComponents: []
+  m_ParentPrefab: {fileID: 0}
+  m_RootGameObject: {fileID: 1594177319052792}
+  m_IsPrefabParent: 1
+--- !u!1 &1594177319052792
+GameObject:
+  m_ObjectHideFlags: 0
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 100100000}
+  serializedVersion: 5
+  m_Component:
+  - component: {fileID: 4977813053446552}
+  - component: {fileID: 114188865886771778}
+  m_Layer: 0
+  m_Name: DeleteUtility
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &4977813053446552
+Transform:
+  m_ObjectHideFlags: 1
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 100100000}
+  m_GameObject: {fileID: 1594177319052792}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!114 &114188865886771778
+MonoBehaviour:
+  m_ObjectHideFlags: 1
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 100100000}
+  m_GameObject: {fileID: 1594177319052792}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: f43b3657624620d47b877b029db31391, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  Folder: Assets/RecyclePool

+ 8 - 0
Assets/Tookits/DeleteUtility/DeleteUtility.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 6d97438e3c489a940937e5481bf991f4
+timeCreated: 1510531736
+licenseType: Pro
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/Tookits/DeleteUtility/Editor.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 906b7c1eeddc6964ab9f6a4a38404e33
+folderAsset: yes
+timeCreated: 1510531235
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 81 - 0
Assets/Tookits/DeleteUtility/Editor/DeleteUtilityWindow.cs

@@ -0,0 +1,81 @@
+namespace deleteUtility
+{
+
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using UnityEditor;
+using UnityEngine;
+
+public class DeleteUtilityWindow : EditorWindow
+{
+    #region Config
+
+    protected DeleteUtility Instance;
+
+    protected SerializedProperty Folder;
+
+    protected SerializedObject SerializedObject;
+
+    #endregion
+
+    [MenuItem("DashGame/DeleteUtility")]
+    protected static void ShowWindow()
+    {
+        Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
+
+        DeleteUtilityWindow window = GetWindow<DeleteUtilityWindow>(inspectorType);
+
+        window.titleContent = new GUIContent("DeleteUtility");
+        window.Show();
+    }
+
+    private void OnEnable()
+    {
+        Instance = InstanceManager.SearchInstance<DeleteUtility>();
+        SerializedObject = new SerializedObject(Instance);
+
+        Folder = SerializedObject.FindProperty("Folder");
+    }
+
+    private void OnGUI()
+    {
+        SerializedObject.Update();
+
+        EditorGUILayout.BeginHorizontal();
+        EditorGUILayout.PropertyField(Folder, new GUIContent("Folder"));
+        if (GUILayout.Button("UseSelectedPath", GUILayout.MaxWidth(120)))
+        {
+            GetSelectedPath(ref Instance.Folder);
+        }
+        EditorGUILayout.EndHorizontal();
+
+        SerializedObject.ApplyModifiedProperties();
+    }
+
+    protected void GetSelectedPath(ref string value)
+    {
+        if (Selection.assetGUIDs.Length > 0)
+        {
+            string path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
+
+            path = Path.GetDirectoryName(path);
+
+            if (string.IsNullOrEmpty(path))
+            {
+                value = "Assets";
+            }
+            else
+            {
+                value = path;
+            }
+        }
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/DeleteUtility/Editor/DeleteUtilityWindow.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 7f5fb24ff3c04b243a8d2c10f8741848
+timeCreated: 1512349621
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 44 - 0
Assets/Tookits/DeleteUtility/ExPath.cs

@@ -0,0 +1,44 @@
+namespace deleteUtility
+{
+
+
+
+    using System.IO;
+
+    using UnityEngine;
+
+public static class ExPath
+{
+    public static string GetRelativePath(this string path)
+    {
+        return "Assets" + path.Replace(Application.dataPath, "");
+    }
+
+    public static string GetUnRepeatFileName(this string fileName)
+    {
+        string extension = Path.GetExtension(fileName);
+        string directory = Path.GetDirectoryName(fileName);
+        string name = Path.GetFileNameWithoutExtension(fileName);
+        int count = 1;
+        string newFileName = $"{directory}{Path.DirectorySeparatorChar}{name}{extension}";
+        while (File.Exists(newFileName))
+        {
+            newFileName = $"{directory}{Path.DirectorySeparatorChar}{name} ({count++}){extension}";
+        }
+        return newFileName;
+    }
+
+    public static string GetUnRepeatDirectoryName(this string directoryName)
+    {
+        int count = 1;
+        string newDirectoryName = directoryName;
+        while (Directory.Exists(newDirectoryName))
+        {
+            newDirectoryName = $"{directoryName} ({count++})";
+        }
+        return newDirectoryName;
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/DeleteUtility/ExPath.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: dda6a8b1e5197fb41bd73da9e0a2c145
+timeCreated: 1511875914
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 37 - 0
Assets/Tookits/DeleteUtility/InstanceManager.cs

@@ -0,0 +1,37 @@
+namespace deleteUtility
+{
+
+
+using System.Collections.Generic;
+
+    using UnityEngine;
+    using UnityEditor;
+
+    using System;
+    using System.IO;
+
+public class InstanceManager
+{
+    public static T SearchInstance<T>()
+    {
+        foreach (var path in Directory.GetFiles(Application.dataPath, "DeleteUtility.prefab", SearchOption.AllDirectories))
+        {
+            T t = AssetDatabase.LoadAssetAtPath<GameObject>(path.GetRelativePath()).GetComponent<T>();
+
+            if (t != null)
+            {
+                return t;
+            }
+        }
+
+        throw new Exception("找不到SerializeObject");
+    }
+
+    public static string[] SearchAllFiles(string pattern)
+    {
+        return Directory.GetFiles(Application.dataPath, pattern, SearchOption.AllDirectories);
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/DeleteUtility/InstanceManager.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 0a483bb16732e3443a5c09004ad607fe
+timeCreated: 1511875859
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/Tookits/LabelUtility.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 56032903362fd424da35d41582540157
+folderAsset: yes
+timeCreated: 1512443896
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Assets/Tookits/LabelUtility/Editor.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: b25e8bc82ba58ed41afd7eaa687db009
+folderAsset: yes
+timeCreated: 1510531235
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 37 - 0
Assets/Tookits/LabelUtility/Editor/InstanceManager.cs

@@ -0,0 +1,37 @@
+namespace labelUtility
+{
+
+
+using System.Collections.Generic;
+
+    using UnityEngine;
+    using UnityEditor;
+
+    using System;
+    using System.IO;
+
+public class InstanceManager
+{
+    public static T SearchInstance<T>()
+    {
+        foreach (var path in Directory.GetFiles(Application.dataPath, "LabelUtility.prefab", SearchOption.AllDirectories))
+        {
+            T t = AssetDatabase.LoadAssetAtPath<GameObject>(path.GetRelativePath()).GetComponent<T>();
+
+            if (t != null)
+            {
+                return t;
+            }
+        }
+
+        throw new Exception("找不到SerializeObject");
+    }
+
+    public static string[] SearchAllFiles(string pattern)
+    {
+        return Directory.GetFiles(Application.dataPath, pattern, SearchOption.AllDirectories);
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/LabelUtility/Editor/InstanceManager.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: b3c745c8eda64e54a94ebeb84c5f596d
+timeCreated: 1511875859
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 100 - 0
Assets/Tookits/LabelUtility/Editor/InstanceUtility.cs

@@ -0,0 +1,100 @@
+namespace labelUtility
+{
+
+
+using UnityEditor;
+using UnityEngine;
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+
+public class InstanceUtility
+{
+    private class RelativeObject
+    {
+        public int EnumerableIndex;
+        public bool IsEnumerable;
+        public string FieldName;
+
+        public RelativeObject(string fieldName, string enumerableIndex = null)
+        {
+            FieldName = fieldName;
+
+            if (enumerableIndex == null)
+            {
+                IsEnumerable = false;
+            }
+            else
+            {
+                EnumerableIndex = int.Parse(enumerableIndex.Substring(5, 1));
+                IsEnumerable = true;
+            }
+        }
+
+        public object GetObject(object originObject)
+        {
+            object relativeObject = originObject.GetType().GetField(FieldName).GetValue(originObject);
+
+            if (IsEnumerable)
+            {
+                int index = 0;
+                
+                foreach (var obj in relativeObject as IEnumerable)
+                {
+                    if (index == EnumerableIndex)
+                        return obj;
+                    else
+                        index++;
+                }
+            }
+            else
+            {
+                return relativeObject;
+            }
+
+            throw new Exception($"{FieldName} {IsEnumerable} {EnumerableIndex}");
+        }
+    }
+
+    public static object GetObject(FieldInfo fieldInfo, SerializedProperty property)
+    {
+        List<string> infos = property.propertyPath.Split('.').ToList();
+
+        List<RelativeObject> relativeObjects = new List<RelativeObject>();
+
+        for (int i = 0; i < infos.Count; i++)
+        {
+            if (i < infos.Count - 1 && infos[i + 1] == "Array")
+            {
+                relativeObjects.Add(new RelativeObject(infos[i], infos[i + 2]));
+                i += 2;
+            }
+            else
+            {
+                relativeObjects.Add(new RelativeObject(infos[i]));
+            }
+        }
+
+        object obj = property.serializedObject.targetObject;
+
+        foreach (var relativeObject in relativeObjects)
+        {
+            obj = relativeObject.GetObject(obj);
+        }
+
+        return obj;
+    }
+
+    public static T GetPropertyDrawerInstance<T>(FieldInfo fieldInfo, SerializedProperty property) where T : class
+    {
+        return GetObject(fieldInfo, property) as T;
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/LabelUtility/Editor/InstanceUtility.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 19b6eb09dca739f42903817e41cd936f
+timeCreated: 1511877134
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 132 - 0
Assets/Tookits/LabelUtility/Editor/LabelSetDrawer.cs

@@ -0,0 +1,132 @@
+namespace labelUtility
+{
+
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+
+[CustomPropertyDrawer(typeof(LabelSet))]
+public class LabelSetDrawer : PropertyDrawer
+{
+    #region Config
+
+    private float LineSpan = 2;
+    private float LineHeight = 16;
+    private float ButtonSpan = 4;
+    private float ButtonHeight = 32;
+
+    private LabelSet Instance;
+    private SerializedProperty Name;
+    private SerializedProperty LabelScriptPath;
+    private SerializedProperty LabelScriptName;
+    private SerializedProperty LabePrefix;
+    private SerializedProperty LabelScript;
+    private SerializedProperty ComponentScriptPath;
+    private SerializedProperty ComponentScriptName;
+    private SerializedProperty ComponentPrefix;
+    private SerializedProperty ComponentScript;
+    private SerializedProperty Languages;
+    private SerializedProperty Prefabs;
+    private SerializedProperty ComponentPurviews;
+    
+    #endregion
+
+    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
+    {
+        Instance = (LabelSet) InstanceUtility.GetObject(fieldInfo, property);
+
+        return Instance.TotalHeight;
+    }
+
+    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
+    {
+        Instance = (LabelSet) InstanceUtility.GetObject(fieldInfo, property);
+        Name = property.FindPropertyRelative("Name");
+        LabelScriptPath = property.FindPropertyRelative("LabelScriptPath");
+        LabelScriptName = property.FindPropertyRelative("LabelScriptName");
+        LabePrefix = property.FindPropertyRelative("LabePrefix");
+        LabelScript = property.FindPropertyRelative("LabelScript");
+        ComponentScriptPath = property.FindPropertyRelative("ComponentScriptPath");
+        ComponentScriptName = property.FindPropertyRelative("ComponentScriptName");
+        ComponentPrefix = property.FindPropertyRelative("ComponentPrefix");
+        ComponentScript = property.FindPropertyRelative("ComponentScript");
+        Languages = property.FindPropertyRelative("Languages");
+        Prefabs = property.FindPropertyRelative("Prefabs");
+        ComponentPurviews = property.FindPropertyRelative("ComponentPurviews");
+
+
+        float originY = position.y;
+
+        position.height = LineHeight;
+        Instance.FoldOut = EditorGUI.Foldout(position, Instance.FoldOut, new GUIContent(Instance.Name));
+        position.y += LineHeight + LineSpan;
+
+        if (Instance.FoldOut)
+        {
+            EditorGUI.indentLevel++;
+            position = DrawProperty(position, Name);
+            position = DrawProperty(position, LabelScriptPath);
+            position = DrawProperty(position, LabelScriptName);
+            position = DrawProperty(position, LabePrefix);
+            position = DrawProperty(position, LabelScript);
+            position = DrawProperty(position, ComponentScriptPath);
+            position = DrawProperty(position, ComponentScriptName);
+            position = DrawProperty(position, ComponentPrefix);
+            position = DrawProperty(position, ComponentScript);
+            position = DrawPropertys(position, Languages);
+            position = DrawPropertys(position, Prefabs);
+            position = DrawButton(position, "Create Label Script", ()=> {LabelUtility.CreateLabelScript(Instance);});
+            position = DrawButton(position, "Create Component Script", ()=> { LabelUtility.CreateComponentScript(Instance); });
+            position = DrawButton(position, "Create Label From Prefab", ()=> { LabelUtility.CreateLabelFromPrefab(Instance); });
+            position = DrawPropertys(position, ComponentPurviews);
+            position = DrawButton(position, "Create Components From Prefab", ()=> { LabelUtility.CreateComponentsFromPrefab(Instance); });
+        }
+
+        Instance.TotalHeight = position.y - originY;
+    }
+
+    private Rect DrawButton(Rect position, string name, Action OnClick)
+    {
+        Rect contentPosition = position;
+        contentPosition.height = ButtonHeight;
+        if (GUI.Button(contentPosition, name))
+        {
+            OnClick.Invoke();
+        }
+        position.y += ButtonHeight + ButtonSpan;
+        return position;
+    }
+
+    private Rect DrawProperty(Rect position, SerializedProperty property)
+    {
+        Rect contentPosition = position;
+        contentPosition.height = LineHeight;
+        contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName));
+        EditorGUI.PropertyField(contentPosition, property, GUIContent.none);
+        position.y += LineHeight + LineSpan;
+        return position;
+    }
+
+    private Rect DrawPropertys(Rect position, SerializedProperty property)
+    {
+        Rect contentPosition = position;
+        contentPosition.height = LineHeight;
+        contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName));
+        EditorGUI.PropertyField(contentPosition, property, GUIContent.none, true);
+        if (property.isExpanded)
+        {
+            position.y += (LineHeight + LineSpan)*(property.arraySize + 2);
+        }
+        else
+        {
+            position.y += LineHeight + LineSpan;
+        }
+        return position;
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/LabelUtility/Editor/LabelSetDrawer.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 93f8d0b9da42900419936401c3a201bb
+timeCreated: 1511876502
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 79 - 0
Assets/Tookits/LabelUtility/Editor/LabelUtilityWindow.cs

@@ -0,0 +1,79 @@
+namespace labelUtility
+{
+
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using UnityEditor;
+using UnityEngine;
+
+public class LabelUtilityWindow : EditorWindow
+{
+    #region Config
+
+        protected Vector2 ScrollPosition;
+    protected LabelUtility Instance;
+
+    protected SerializedProperty LabelSets;
+
+    protected SerializedObject SerializedObject;
+
+    #endregion
+
+    [MenuItem("DashGame/LabelUtility")]
+    protected static void ShowWindow()
+    {
+        Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
+
+        LabelUtilityWindow window = GetWindow<LabelUtilityWindow>(inspectorType);
+
+        window.titleContent = new GUIContent("LabelUtility");
+        window.Show();
+    }
+
+    private void OnEnable()
+    {
+        Instance = InstanceManager.SearchInstance<LabelUtility>();
+        SerializedObject = new SerializedObject(Instance);
+
+        LabelSets = SerializedObject.FindProperty("LabelSets");
+    }
+
+    private void OnGUI()
+    {
+        SerializedObject.Update();
+
+            ScrollPosition = EditorGUILayout.BeginScrollView(ScrollPosition);
+        EditorGUILayout.PropertyField(LabelSets, new GUIContent("LabelSets"), true);
+
+        //if (GUILayout.Button("CreateLabelScript"))
+        //{
+        //    LabelUtility.CreateLabelScript(Instance.LabelSets[0]);
+        //}
+
+        //if (GUILayout.Button("CreateComponentScript"))
+        //{
+        //    LabelUtility.CreateComponentScript(Instance.LabelSets[0]);
+        //}
+
+        //if (GUILayout.Button("CreateLabelFromPrefab"))
+        //{
+        //    LabelUtility.CreateLabelFromPrefab(Instance.LabelSets[0]);
+        //}
+
+        //if (GUILayout.Button("CreateComponentsFromPrefab"))
+        //{
+        //    LabelUtility.CreateComponentsFromPrefab(Instance.LabelSets[0], InitPurview.Text, InitPurview.Button, InitPurview.SpriteRenderer);
+        //}
+
+            EditorGUILayout.EndScrollView();
+        SerializedObject.ApplyModifiedProperties();
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/LabelUtility/Editor/LabelUtilityWindow.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 677f8818c269f17408c361340bc50529
+timeCreated: 1512443421
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 39 - 0
Assets/Tookits/LabelUtility/ExPath.cs

@@ -0,0 +1,39 @@
+namespace labelUtility
+{
+
+
+
+    using System.IO;
+
+    using UnityEngine;
+
+public static class ExPath
+{
+    public static string GetRelativePath(this string path)
+    {
+        return "Assets" + path.Replace(Application.dataPath, "");
+    }
+
+    public static string GetUnRepeatFileName(this string fileName)
+    {
+        string extension = Path.GetExtension(fileName);
+        string directory = Path.GetDirectoryName(fileName);
+        string name = Path.GetFileNameWithoutExtension(fileName);
+
+        int count = 0;
+
+        string newFileName = $"{directory}/{name}{extension}";
+
+        while (File.Exists(newFileName))
+        {
+            count++;
+
+            newFileName = $"{directory}/{name} ({count}){extension}";
+        }
+
+        return newFileName;
+    }
+}
+
+
+}

+ 12 - 0
Assets/Tookits/LabelUtility/ExPath.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d770958666988c940b615cf9f4bc7b1c
+timeCreated: 1511875914
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 260 - 0
Assets/Tookits/LabelUtility/LabelUtility.cs

@@ -0,0 +1,260 @@
+namespace labelUtility
+{
+
+
+#if UNITY_EDITOR
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Xml;
+using UnityEditor;
+using UnityEngine;
+using UnityEngine.UI;
+
+[Serializable]
+public class LabelSet
+{
+    public string Name;
+
+    public string LabelScriptPath;
+    public string LabelScriptName;
+    public string LabePrefix = "public static string";
+    public TextAsset LabelScript;
+
+    public string ComponentScriptPath;
+    public string ComponentScriptName;
+    public string ComponentPrefix = "private";
+    public TextAsset ComponentScript;
+
+    public List<TextAsset> Languages;
+    public List<GameObject> Prefabs;
+
+    public bool FoldOut;
+    public float TotalHeight;
+    public List<ComponentPurview> ComponentPurviews = new List<ComponentPurview>();
+}
+
+public enum ComponentPurview
+{
+    Text,
+    Button,
+    Transform,
+    RectTransform,
+    SpriteRenderer,
+}
+
+public class LabelUtility : MonoBehaviour
+{
+    #region Config
+
+    public List<LabelSet> LabelSets;
+
+    public static string StartMark = "//StartMarkMark-LabelUtility使用-勿删";
+    public static string EndMark = "//EndMarkMark-LabelUtility使用-勿删";
+    public static string Prefix = "public static string ";
+    public static string LanguagePageSeperator = "__";
+
+    #endregion
+
+    public static void CreateLabelScript(LabelSet labelSet)
+    {
+        if (!EditorUtility.DisplayDialog("注意", "新建LabelScript?", "确定", "取消"))
+        {
+            return;
+        }
+
+        labelSet.LabelScript = CreateScript(labelSet.LabelScriptName, labelSet.LabelScriptPath);
+    }
+
+    public static void CreateComponentScript(LabelSet labelSet)
+    {
+        if (!EditorUtility.DisplayDialog("注意", "新建ComponentScript?", "确定", "取消"))
+        {
+            return;
+        }
+
+        labelSet.ComponentScript = CreateScript(labelSet.ComponentScriptName, labelSet.ComponentScriptPath);
+    }
+
+    private static TextAsset CreateScript(string scriptName, string scriptPath)
+    {
+        string directory = scriptPath.TrimEnd('/', '\\') + "/";
+
+        if (directory.Length < 6 || directory.Substring(0, 6).ToLower() != "assets")
+        {
+            throw new Exception("ScripPath必须位置Assets目录内");
+        }
+
+        if (!Directory.Exists(directory))
+        {
+            throw new Exception("文件夹不存在");
+        }
+
+        if (string.IsNullOrEmpty(scriptName) || scriptName.Any(Path.GetInvalidFileNameChars().Contains))
+        {
+            throw new Exception("ScripName包含无效字符");
+        }
+
+        string fullPath = $"{scriptPath}/{scriptName}.cs";
+        if (File.Exists(fullPath))
+        {
+            throw new Exception($"已经存在一个 {fullPath}");
+        }
+
+        string scriptContent = $"public class {scriptName}\r\n{{\r\n\t#region Config\r\n\r\n\t{StartMark}\r\n\t{EndMark}\r\n\r\n\t#endregion\r\n}}";
+        File.WriteAllText(fullPath, scriptContent);
+        AssetDatabase.Refresh();
+        return AssetDatabase.LoadAssetAtPath<TextAsset>(fullPath);
+    }
+
+
+    public static void CreateLabelFromPrefab(LabelSet labelSet)
+    {
+        if (!EditorUtility.DisplayDialog("注意", "重新生成PrefabLabel?", "确定", "取消"))
+        {
+            return;
+        }
+        
+        List<string> labels = new List<string>();
+        List<Transform> transforms = GetAllTransformFromPrefab(labelSet.Prefabs);
+        foreach (var transform in transforms)
+        {
+            labels.Add($"{labelSet.LabePrefix} {transform.name} = \"{transform.name}\";");
+        }
+        InsertLineToScript(labelSet.LabelScript, labels);
+    }
+
+    public static void CreateComponentsFromPrefab(LabelSet labelSet)
+    {
+        if (!EditorUtility.DisplayDialog("注意", "重新生成PrefabComponent?", "确定", "取消"))
+        {
+            return;
+        }
+
+        List<string> textNames = new List<string>();
+        List<string> buttonNames = new List<string>();
+        List<string> transformNames = new List<string>();
+        List<string> rectTransformNames = new List<string>();
+        List<string> spriteRendererNames = new List<string>();
+        List<Transform> transforms = GetAllTransformFromPrefab(labelSet.Prefabs);
+        foreach (var transform in transforms)
+        {
+            if (labelSet.ComponentPurviews.Contains(ComponentPurview.Text) && transform.GetComponent<Text>() != null)
+            {
+                textNames.Add($"{labelSet.ComponentPrefix} Text {transform.name};");
+            }
+            if (labelSet.ComponentPurviews.Contains(ComponentPurview.Button) && transform.GetComponent<Button>() != null)
+            {
+                buttonNames.Add($"{labelSet.ComponentPrefix} Button {transform.name};");
+            }
+            if (labelSet.ComponentPurviews.Contains(ComponentPurview.Transform) && transform.GetComponent<Transform>() != null)
+            {
+                transformNames.Add($"{labelSet.ComponentPrefix} Transform {transform.name};");
+            }
+            if (labelSet.ComponentPurviews.Contains(ComponentPurview.RectTransform) && transform.GetComponent<RectTransform>() != null)
+            {
+                rectTransformNames.Add($"{labelSet.ComponentPrefix} RectTransform {transform.name};");
+            }
+            if (labelSet.ComponentPurviews.Contains(ComponentPurview.SpriteRenderer) && transform.GetComponent<SpriteRenderer>() != null)
+            {
+                spriteRendererNames.Add($"{labelSet.ComponentPrefix} SpriteRenderer {transform.name};");
+            }
+        }
+        List<string> components = new List<string>();
+        components.AddRange(textNames);
+        components.AddRange(buttonNames);
+        components.AddRange(transformNames);
+        components.AddRange(rectTransformNames);
+        components.AddRange(spriteRendererNames);
+        InsertLineToScript(labelSet.ComponentScript, components);
+    }
+
+    private static void InsertLineToScript(TextAsset textAsset, List<string> insertLines)
+    {
+        int? startMarkLineIndex = null;
+        int? endMarkLineIndex = null;
+        List<string> strings = GetScriptContentAfterClearMarks(textAsset, ref startMarkLineIndex, ref endMarkLineIndex);
+        int prefixIndex = strings[startMarkLineIndex.Value].IndexOf("//");
+        string prefix = strings[startMarkLineIndex.Value].Substring(0, prefixIndex);
+        for (int i = 0; i < insertLines.Count; i++)
+        {
+            strings.Insert(startMarkLineIndex.Value + 1, prefix + insertLines[i]);
+            startMarkLineIndex++;
+        }
+        StringBuilder stringBuilder = new StringBuilder();
+        for (int i = 0; i < strings.Count; i++)
+        {
+            stringBuilder.AppendLine(strings[i]);
+        }
+        string content = stringBuilder.ToString();
+        content = content.Substring(0, content.Length - 2);
+        File.WriteAllText(AssetDatabase.GetAssetPath(textAsset), content);
+        AssetDatabase.Refresh();
+    }
+
+    private static List<string> GetScriptContentAfterClearMarks(TextAsset textAsset, ref int? startMarkLineIndex, ref int? endMarkLineIndex)
+    {
+        List<string> strings = textAsset.text.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
+        //List<string> currentDefinedNames = new List<string>();
+        for (int i = 0; i < strings.Count; i++)
+        {
+            if (strings[i].Contains(StartMark))
+            {
+                startMarkLineIndex = i;
+            }
+            else if (strings[i].Contains(EndMark))
+            {
+                endMarkLineIndex = i;
+            }
+
+            //if (startMarkLineIndex != null)
+            //{
+            //    if (endMarkLineIndex != null)
+            //    {
+            //        if (i > startMarkLineIndex.Value && i < endMarkLineIndex.Value)
+            //        {
+            //            currentDefinedNames.Add(GetDefinedName(strings[i]));
+            //        }
+            //    }
+            //    else
+            //    {
+            //        if (i > startMarkLineIndex.Value)
+            //        {
+            //            currentDefinedNames.Add(GetDefinedName(strings[i]));
+            //        }
+            //    }
+            //}
+        }
+        int definedCount = endMarkLineIndex.Value - startMarkLineIndex.Value - 1;
+        for (int i = 0; i < definedCount; i++)
+        {
+            strings.RemoveAt(startMarkLineIndex.Value + 1);
+        }
+        return strings;
+    }
+
+    private static List<Transform> GetAllTransformFromPrefab(List<GameObject> prefabs)
+    {
+        List<Transform> transforms = new List<Transform>();
+        for (int i = 0; i < prefabs.Count; i++)
+        {
+            transforms.AddRange(prefabs[i].GetComponentsInChildren<Transform>(true));
+        }
+        return transforms;
+    }
+}
+
+/*To be delete
+    //private static string GetDefinedName(string str)
+    //{
+    //    return Regex.Match(str, "(?<=string)[^=]+(?=\\=)").Value.Trim();
+    //}
+*/
+#endif
+
+
+}

+ 12 - 0
Assets/Tookits/LabelUtility/LabelUtility.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c191ef3fc5b89274696e54e8d5314e1a
+timeCreated: 1510531596
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 56 - 0
Assets/Tookits/LabelUtility/LabelUtility.prefab

@@ -0,0 +1,56 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!1001 &100100000
+Prefab:
+  m_ObjectHideFlags: 1
+  serializedVersion: 2
+  m_Modification:
+    m_TransformParent: {fileID: 0}
+    m_Modifications: []
+    m_RemovedComponents: []
+  m_ParentPrefab: {fileID: 0}
+  m_RootGameObject: {fileID: 1594177319052792}
+  m_IsPrefabParent: 1
+--- !u!1 &1594177319052792
+GameObject:
+  m_ObjectHideFlags: 0
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 100100000}
+  serializedVersion: 5
+  m_Component:
+  - component: {fileID: 4977813053446552}
+  - component: {fileID: 114188865886771778}
+  m_Layer: 0
+  m_Name: LabelUtility
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &4977813053446552
+Transform:
+  m_ObjectHideFlags: 1
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 100100000}
+  m_GameObject: {fileID: 1594177319052792}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!114 &114188865886771778
+MonoBehaviour:
+  m_ObjectHideFlags: 1
+  m_PrefabParentObject: {fileID: 0}
+  m_PrefabInternal: {fileID: 100100000}
+  m_GameObject: {fileID: 1594177319052792}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: e4a9dafa00b004e4e94c57cd88b01101, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  Script: {fileID: 0}
+  Languages: []
+  Prefabs: []

+ 8 - 0
Assets/Tookits/LabelUtility/LabelUtility.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 65b21c90790033744b032e2e42e62481
+timeCreated: 1510531736
+licenseType: Pro
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: