LocalizationParamsManagerInspector.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using UnityEditor;
  2. using UnityEditorInternal;
  3. using UnityEngine;
  4. namespace I2.Loc
  5. {
  6. [CustomEditor(typeof(LocalizationParamsManager))]
  7. public class LocalizationParamsManagerInspector : Editor
  8. {
  9. private ReorderableList mList;
  10. private SerializedProperty mProp_IsGlobalManager;
  11. private ReorderableList getList(SerializedObject serObject)
  12. {
  13. if (mList == null) {
  14. mList = new ReorderableList (serObject, serObject.FindProperty ("_Params"), true, true, true, true);
  15. mList.drawElementCallback = drawElementCallback;
  16. mList.drawHeaderCallback = drawHeaderCallback;
  17. mList.onAddCallback = addElementCallback;
  18. mList.onRemoveCallback = removeElementCallback;
  19. }
  20. else
  21. {
  22. mList.serializedProperty = serObject.FindProperty ("_Params");
  23. }
  24. return mList;
  25. }
  26. private void addElementCallback( ReorderableList list )
  27. {
  28. serializedObject.ApplyModifiedProperties();
  29. var objParams = target as LocalizationParamsManager;
  30. objParams._Params.Add(new LocalizationParamsManager.ParamValue());
  31. list.index = objParams._Params.Count - 1;
  32. serializedObject.Update();
  33. }
  34. private void removeElementCallback( ReorderableList list )
  35. {
  36. if (list.index < 0)
  37. return;
  38. serializedObject.ApplyModifiedProperties();
  39. var objParams = target as LocalizationParamsManager;
  40. objParams._Params.RemoveAt(list.index);
  41. serializedObject.Update();
  42. }
  43. private void drawHeaderCallback(Rect rect)
  44. {
  45. GUI.Label(rect, "Parameters:");
  46. }
  47. private void drawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
  48. {
  49. var serializedElement = mList.serializedProperty.GetArrayElementAtIndex (index);
  50. var content = new GUIContent ();
  51. Rect r = rect; r.xMax = r.xMin+40;
  52. GUI.Label(r, "Name");
  53. r = rect; r.xMax = (r.xMax + r.xMin)/2 - 2; r.xMin = r.xMin+40;
  54. EditorGUI.PropertyField (r, serializedElement.FindPropertyRelative ("Name"),content);
  55. r = rect; r.xMin = (r.xMax + r.xMin) / 2 + 2; r.xMax = r.xMin+40;
  56. GUI.Label(r, "Value");
  57. r = rect; r.xMin = (r.xMax + r.xMin)/2 + 2 + 40;
  58. EditorGUI.PropertyField (r, serializedElement.FindPropertyRelative ("Value"), content);
  59. }
  60. void OnEnable()
  61. {
  62. mList = getList(serializedObject);
  63. mProp_IsGlobalManager = serializedObject.FindProperty("_IsGlobalManager");
  64. }
  65. public override void OnInspectorGUI()
  66. {
  67. #if UNITY_5_6_OR_NEWER
  68. serializedObject.UpdateIfRequiredOrScript();
  69. #else
  70. serializedObject.UpdateIfDirtyOrScript();
  71. #endif
  72. GUI.backgroundColor = Color.Lerp (Color.black, Color.gray, 1);
  73. GUILayout.BeginVertical(LocalizeInspector.GUIStyle_Background);
  74. GUI.backgroundColor = Color.white;
  75. if (GUILayout.Button("Dynamic Parameters", LocalizeInspector.GUIStyle_Header))
  76. {
  77. Application.OpenURL(LocalizeInspector.HelpURL_Documentation);
  78. }
  79. GUILayout.Space(5);
  80. mProp_IsGlobalManager.boolValue = EditorGUILayout.Popup(new GUIContent("Manager Type", "Local Manager only apply parameters to the Localize component in the same GameObject\n\nGlobal Manager apply parameters to all Localize components"), mProp_IsGlobalManager.boolValue ? 1 : 0, new[] { new GUIContent("Local"), new GUIContent("Global") }) == 1;
  81. GUILayout.Space(5);
  82. mList.DoLayoutList();
  83. //EditorGUILayout.PropertyField(serializedObject.FindProperty("_AutoRegister"), new GUIContent("Auto Register"));
  84. GUILayout.EndVertical();
  85. serializedObject.ApplyModifiedProperties();
  86. }
  87. }
  88. }