|
@@ -1,149 +1,332 @@
|
|
|
+using System.Reflection;
|
|
|
+
|
|
|
namespace labelUtility
|
|
|
{
|
|
|
|
|
|
|
|
|
-using System;
|
|
|
-using System.Collections;
|
|
|
-using System.Collections.Generic;
|
|
|
-using UnityEditor;
|
|
|
-using UnityEngine;
|
|
|
+ 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 NameExcludeString;
|
|
|
- private SerializedProperty RegistString;
|
|
|
- //private SerializedProperty RegistPrefix;
|
|
|
- // private SerializedProperty RegistSuffix;
|
|
|
- private SerializedProperty RegistExtraLines;
|
|
|
- private SerializedProperty ComponentScript;
|
|
|
- private SerializedProperty Languages;
|
|
|
- private SerializedProperty Prefabs;
|
|
|
- private SerializedProperty ComponentPurviews;
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
- public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
|
+ [CustomPropertyDrawer(typeof(LabelSet))]
|
|
|
+ public class LabelSetDrawer : PropertyDrawer
|
|
|
{
|
|
|
- Instance = (LabelSet) InstanceUtility.GetObject(fieldInfo, property);
|
|
|
+ #region Config
|
|
|
|
|
|
- return Instance.TotalHeight;
|
|
|
- }
|
|
|
+ private float LineSpan = 2;
|
|
|
+ private float LineHeight = 16;
|
|
|
+ private float ButtonSpan = 4;
|
|
|
+ private float ButtonHeight = 32;
|
|
|
|
|
|
- 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");
|
|
|
- NameExcludeString = property.FindPropertyRelative("NameExcludeString");
|
|
|
+ private LabelSet Instance;
|
|
|
+ private SerializedProperty Name;
|
|
|
+ private SerializedProperty UtilityType;
|
|
|
+ private SerializedProperty LabelScriptPath;
|
|
|
+ private SerializedProperty LabelScriptName;
|
|
|
+ private SerializedProperty LabePrefix;
|
|
|
+ private SerializedProperty LabelScript;
|
|
|
+ private SerializedProperty ComponentScriptPath;
|
|
|
+ private SerializedProperty ComponentScriptName;
|
|
|
+ private SerializedProperty DerivedString;
|
|
|
+ private SerializedProperty RegistMethodString;
|
|
|
+ private SerializedProperty ComponentPrefix;
|
|
|
+ private SerializedProperty NameExcludeString;
|
|
|
+ private SerializedProperty RegistString;
|
|
|
+ private SerializedProperty RegistExtraLines;
|
|
|
+ private SerializedProperty ComponentScript;
|
|
|
+ private SerializedProperty Languages;
|
|
|
+ private SerializedProperty Prefabs;
|
|
|
+ private SerializedProperty Types;
|
|
|
+ private SerializedProperty RegistTargets;
|
|
|
+
|
|
|
+ private bool RegistTargetsChangeFlag;
|
|
|
+ private List<RegistTarget> registTargets = new List<RegistTarget>();
|
|
|
+
|
|
|
+ #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");
|
|
|
+ UtilityType = property.FindPropertyRelative("UtilityType");
|
|
|
+ LabelScriptPath = property.FindPropertyRelative("LabelScriptPath");
|
|
|
+ LabelScriptName = property.FindPropertyRelative("LabelScriptName");
|
|
|
+ LabePrefix = property.FindPropertyRelative("LabePrefix");
|
|
|
+ LabelScript = property.FindPropertyRelative("LabelScript");
|
|
|
+ ComponentScriptPath = property.FindPropertyRelative("ComponentScriptPath");
|
|
|
+ ComponentScriptName = property.FindPropertyRelative("ComponentScriptName");
|
|
|
+ DerivedString = property.FindPropertyRelative("DerivedString");
|
|
|
+ RegistMethodString = property.FindPropertyRelative("RegistMethodString");
|
|
|
+
|
|
|
+ ComponentPrefix = property.FindPropertyRelative("ComponentPrefix");
|
|
|
+ NameExcludeString = property.FindPropertyRelative("NameExcludeString");
|
|
|
|
|
|
RegistString = property.FindPropertyRelative("RegistString");
|
|
|
- //RegistPrefix = property.FindPropertyRelative("RegistPrefix");
|
|
|
- //RegistSuffix = property.FindPropertyRelative("RegistSuffix");
|
|
|
- RegistExtraLines = property.FindPropertyRelative("RegistExtraLines");
|
|
|
- ComponentScript = property.FindPropertyRelative("ComponentScript");
|
|
|
- Languages = property.FindPropertyRelative("Languages");
|
|
|
- Prefabs = property.FindPropertyRelative("Prefabs");
|
|
|
- ComponentPurviews = property.FindPropertyRelative("ComponentPurviews");
|
|
|
+ RegistExtraLines = property.FindPropertyRelative("RegistExtraLines");
|
|
|
+ ComponentScript = property.FindPropertyRelative("ComponentScript");
|
|
|
+ Languages = property.FindPropertyRelative("Languages");
|
|
|
+ Prefabs = property.FindPropertyRelative("Prefabs");
|
|
|
+ Types = property.FindPropertyRelative("RegistTypes");
|
|
|
+ RegistTargets = property.FindPropertyRelative("RegistTargets");
|
|
|
+
|
|
|
+ if (RegistTargetsChangeFlag)
|
|
|
+ {
|
|
|
+ if (Instance.RegistTargets == registTargets)
|
|
|
+ {
|
|
|
+ RegistTargetsChangeFlag = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Instance.RegistTargets = registTargets;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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, UtilityType);
|
|
|
+
|
|
|
+ bool drawRegistArea = Instance.UtilityType == labelUtility.UtilityType.Regist;
|
|
|
+ bool drawXmlArea = Instance.UtilityType == labelUtility.UtilityType.XmlLabel;
|
|
|
+ bool drawLabelArea = Instance.UtilityType == labelUtility.UtilityType.Regist || Instance.UtilityType == labelUtility.UtilityType.XmlLabel || Instance.UtilityType == labelUtility.UtilityType.PrefabLabel;
|
|
|
+
|
|
|
+ if (drawLabelArea)
|
|
|
+ {
|
|
|
+ if (Instance.LabelScript == null)
|
|
|
+ {
|
|
|
+ position = DrawProperty(position, LabelScriptPath);
|
|
|
+ position = DrawProperty(position, LabelScriptName);
|
|
|
+ position = DrawProperty(position, LabePrefix);
|
|
|
+ }
|
|
|
+ position = DrawProperty(position, LabelScript);
|
|
|
+ }
|
|
|
|
|
|
+ if (drawRegistArea)
|
|
|
+ {
|
|
|
+ if (Instance.ComponentScript == null)
|
|
|
+ {
|
|
|
+ position = DrawProperty(position, ComponentScriptPath);
|
|
|
+ position = DrawProperty(position, ComponentScriptName);
|
|
|
+ position = DrawProperty(position, DerivedString);
|
|
|
+ position = DrawProperty(position, RegistMethodString);
|
|
|
+ }
|
|
|
+ position = DrawProperty(position, ComponentScript);
|
|
|
|
|
|
- float originY = position.y;
|
|
|
+ position = DrawProperty(position, ComponentPrefix);
|
|
|
+ position = DrawProperty(position, NameExcludeString);
|
|
|
+ position = DrawProperty(position, RegistString);
|
|
|
+ position = DrawPropertys(position, RegistExtraLines, LineHeight + LineSpan);
|
|
|
+ }
|
|
|
|
|
|
- position.height = LineHeight;
|
|
|
- Instance.FoldOut = EditorGUI.Foldout(position, Instance.FoldOut, new GUIContent(Instance.Name));
|
|
|
- position.y += LineHeight + LineSpan;
|
|
|
+ if (drawXmlArea)
|
|
|
+ {
|
|
|
+ position = DrawPropertys(position, Languages, LineHeight + LineSpan);
|
|
|
+ }
|
|
|
+ else if (drawLabelArea)
|
|
|
+ {
|
|
|
+ EditorGUI.BeginChangeCheck();
|
|
|
+ position = DrawPropertys(position, Prefabs, LineHeight + LineSpan);
|
|
|
+ position = DrawButton(position, "Refresh", () => { registTargets = RefreshRegistTargets(); }, LineHeight);
|
|
|
+ if (EditorGUI.EndChangeCheck())
|
|
|
+ {
|
|
|
+ registTargets = RefreshRegistTargets();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (Instance.FoldOut)
|
|
|
+ if (drawRegistArea)
|
|
|
+ {
|
|
|
+ if (Instance.LabelScript == null && Instance.ComponentScript == null)
|
|
|
+ {
|
|
|
+ position = DrawButton(position, "Create And Regist", () =>
|
|
|
+ {
|
|
|
+ LabelUtility.CreateLabelScript(Instance, false, true);
|
|
|
+ LabelUtility.CreateComponentScript(Instance, false, true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Instance.LabelScript == null)
|
|
|
+ {
|
|
|
+ position = DrawButton(position, "Create Label Script", () => { LabelUtility.CreateLabelScript(Instance); });
|
|
|
+ }
|
|
|
+ if (Instance.ComponentScript == null)
|
|
|
+ {
|
|
|
+ position = DrawButton(position, "Create Component Script", () => { LabelUtility.CreateComponentScript(Instance); });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (drawLabelArea)
|
|
|
+ {
|
|
|
+ if (Instance.LabelScript == null)
|
|
|
+ {
|
|
|
+ position = DrawButton(position, "Create Label Script", () => { LabelUtility.CreateLabelScript(Instance); });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (drawRegistArea)
|
|
|
+ {
|
|
|
+ EditorGUI.BeginChangeCheck();
|
|
|
+ position = DrawPropertys(position, Types, LineHeight + LineSpan);
|
|
|
+ if (EditorGUI.EndChangeCheck())
|
|
|
+ {
|
|
|
+ registTargets = RefreshRegistTargets();
|
|
|
+ }
|
|
|
+ position = DrawPropertys(position, RegistTargets, (LineHeight + LineSpan)*6);
|
|
|
+ position = DrawButton(position, "Create Components From Prefab", () => { LabelUtility.CreateComponentsFromPrefab(Instance); });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (drawXmlArea)
|
|
|
+ {
|
|
|
+ position = DrawButton(position, "Create Label From LanguageXml", () => { LabelUtility.CreateLabelFromLanguageXml(Instance); }); //todo Ôö¼Ó
|
|
|
+ }
|
|
|
+ else if (drawLabelArea)
|
|
|
+ {
|
|
|
+ position = DrawButton(position, "Create Label From Prefab", () => { LabelUtility.CreateLabelFromPrefab(Instance); });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Instance.TotalHeight = position.y - originY;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<RegistTarget> RefreshRegistTargets()
|
|
|
{
|
|
|
- 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, NameExcludeString);
|
|
|
- position = DrawProperty(position, RegistString);
|
|
|
- // position = DrawProperty(position, RegistPrefix);
|
|
|
- //position = DrawProperty(position, RegistSuffix);
|
|
|
- position = DrawPropertys(position, RegistExtraLines);
|
|
|
- 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 = DrawButton(position, "Create Label From LanguageXml", () => { LabelUtility.CreateLabelFromLanguageXml(Instance); }); //todo Ôö¼Ó
|
|
|
- position = DrawPropertys(position, ComponentPurviews);
|
|
|
- position = DrawButton(position, "Create Components From Prefab", () => { LabelUtility.CreateComponentsFromPrefab(Instance); });
|
|
|
+ RegistTargetsChangeFlag = true;
|
|
|
+ List<GameObject> prefabs = new List<GameObject>();
|
|
|
+ for (int i = 0; i < Prefabs.arraySize; i++)
|
|
|
+ {
|
|
|
+ UnityEngine.Object obj = Prefabs.GetArrayElementAtIndex(i).objectReferenceValue;
|
|
|
+ if (obj == null) continue;
|
|
|
+ GameObject go = (GameObject) obj;
|
|
|
+ if (prefabs.Contains(go)) continue;
|
|
|
+ prefabs.Add(go);
|
|
|
+ }
|
|
|
+ List<ComponentType> componentTypes = new List<ComponentType>();
|
|
|
+ for (int i = 0; i < Types.arraySize; i++)
|
|
|
+ {
|
|
|
+ ComponentType componentType = (ComponentType) Types.GetArrayElementAtIndex(i).enumValueIndex;
|
|
|
+ if (componentType == ComponentType.None) continue;
|
|
|
+ if (componentTypes.Contains(componentType)) continue;
|
|
|
+ componentTypes.Add(componentType);
|
|
|
+ }
|
|
|
+ List<Type> types = GetTypes(componentTypes);
|
|
|
+ List<RegistTarget> registTargets = new List<RegistTarget>();
|
|
|
+ for (int i = 0; i < types.Count; i++)
|
|
|
+ {
|
|
|
+ foreach (var prefab in prefabs)
|
|
|
+ {
|
|
|
+ if (prefab == null) continue;
|
|
|
+ foreach (var transform in prefab.GetComponentsInChildren<Transform>(true))
|
|
|
+ {
|
|
|
+ Component component = transform.GetComponent(types[i]);
|
|
|
+ if (component == null) continue;
|
|
|
+ RegistTarget registTarget = GetRegistTarget(transform, componentTypes[i]);
|
|
|
+ if (registTarget == null)
|
|
|
+ {
|
|
|
+ registTarget = new RegistTarget();
|
|
|
+ registTarget.Transform = transform;
|
|
|
+ registTarget.Type = componentTypes[i];
|
|
|
+ registTarget.Name = string.IsNullOrEmpty(Instance.NameExcludeString) ? $"{transform.name}" : $"{transform.name.Replace(Instance.NameExcludeString, "")}";
|
|
|
+ }
|
|
|
+ registTargets.Add(registTarget);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //foreach (var registTarget in registTargets)
|
|
|
+ //{
|
|
|
+ // Debug.Log($"{registTarget.Type} {registTarget.Name}");
|
|
|
+ //}
|
|
|
+ registTargets.AddRange(GetForceRegistTargets());
|
|
|
+ return registTargets;
|
|
|
}
|
|
|
|
|
|
- Instance.TotalHeight = position.y - originY;
|
|
|
- }
|
|
|
+ private RegistTarget GetRegistTarget(Transform transform, ComponentType type)
|
|
|
+ {
|
|
|
+ foreach (var registTarget in Instance.RegistTargets)
|
|
|
+ {
|
|
|
+ if (registTarget.Transform == transform && registTarget.Type == type)
|
|
|
+ {
|
|
|
+ return registTarget;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- private Rect DrawButton(Rect position, string name, Action OnClick)
|
|
|
- {
|
|
|
- Rect contentPosition = position;
|
|
|
- contentPosition.height = ButtonHeight;
|
|
|
- if (GUI.Button(contentPosition, name))
|
|
|
+ private List<RegistTarget> GetForceRegistTargets()
|
|
|
{
|
|
|
- OnClick.Invoke();
|
|
|
+ List<RegistTarget> tempRegistTargets = new List<RegistTarget>();
|
|
|
+ foreach (var registTarget in Instance.RegistTargets)
|
|
|
+ {
|
|
|
+ if (registTarget.Force)
|
|
|
+ {
|
|
|
+ tempRegistTargets.Add(registTarget);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tempRegistTargets;
|
|
|
}
|
|
|
- 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 List<Type> GetTypes(List<ComponentType> componentTypes)
|
|
|
+ {
|
|
|
+ List<Type> types = new List<Type>();
|
|
|
+ foreach (var componentType in componentTypes)
|
|
|
+ {
|
|
|
+ types.Add(LabelUtility.GetType(componentType));
|
|
|
+ }
|
|
|
+ return types;
|
|
|
+ }
|
|
|
|
|
|
- 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)
|
|
|
+ private Rect DrawButton(Rect position, string name, Action OnClick, float? buttonHeight = null)
|
|
|
{
|
|
|
- position.y += (LineHeight + LineSpan)*(property.arraySize + 2);
|
|
|
+ Rect contentPosition = position;
|
|
|
+ contentPosition.height = buttonHeight ?? ButtonHeight;
|
|
|
+ if (GUI.Button(contentPosition, name))
|
|
|
+ {
|
|
|
+ OnClick.Invoke();
|
|
|
+ }
|
|
|
+ position.y += ButtonHeight + ButtonSpan;
|
|
|
+ return position;
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ 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, float itemHeight)
|
|
|
+ {
|
|
|
+ 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 += itemHeight * property.arraySize + (LineHeight + LineSpan)*2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ position.y += LineHeight + LineSpan;
|
|
|
+ }
|
|
|
+ return position;
|
|
|
}
|
|
|
- return position;
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
|
|
}
|