UIPainterEditor.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using UnityEngine;
  2. #if UNITY_5_3_OR_NEWER
  3. using UnityEditor.SceneManagement;
  4. #endif
  5. using UnityEditor;
  6. using FairyGUI;
  7. namespace FairyGUIEditor
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. [CustomEditor(typeof(UIPainter))]
  13. public class UIPainterEditor : Editor
  14. {
  15. SerializedProperty packageName;
  16. SerializedProperty componentName;
  17. SerializedProperty renderCamera;
  18. SerializedProperty fairyBatching;
  19. SerializedProperty touchDisabled;
  20. SerializedProperty sortingOrder;
  21. string[] propertyToExclude;
  22. void OnEnable()
  23. {
  24. packageName = serializedObject.FindProperty("packageName");
  25. componentName = serializedObject.FindProperty("componentName");
  26. renderCamera = serializedObject.FindProperty("renderCamera");
  27. fairyBatching = serializedObject.FindProperty("fairyBatching");
  28. touchDisabled = serializedObject.FindProperty("touchDisabled");
  29. sortingOrder = serializedObject.FindProperty("sortingOrder");
  30. propertyToExclude = new string[] { "m_Script", "packageName", "componentName", "packagePath",
  31. "renderCamera", "fairyBatching", "touchDisabled","sortingOrder"
  32. };
  33. }
  34. public override void OnInspectorGUI()
  35. {
  36. serializedObject.Update();
  37. UIPainter panel = target as UIPainter;
  38. DrawPropertiesExcluding(serializedObject, propertyToExclude);
  39. EditorGUILayout.BeginHorizontal();
  40. EditorGUILayout.PrefixLabel("Package Name");
  41. if (GUILayout.Button(packageName.stringValue, "ObjectField"))
  42. EditorWindow.GetWindow<PackagesWindow>(true, "Select a UI Component").SetSelection(packageName.stringValue, componentName.stringValue);
  43. if (GUILayout.Button("Clear", GUILayout.Width(50)))
  44. {
  45. #if UNITY_2018_3_OR_NEWER
  46. bool isPrefab = PrefabUtility.GetPrefabAssetType(panel) != PrefabAssetType.NotAPrefab;
  47. #else
  48. bool isPrefab = PrefabUtility.GetPrefabType(panel) == PrefabType.Prefab;
  49. #endif
  50. panel.SendMessage("OnUpdateSource", new object[] { null, null, null, !isPrefab });
  51. #if UNITY_5_3_OR_NEWER
  52. EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
  53. #elif UNITY_5
  54. EditorApplication.MarkSceneDirty();
  55. #else
  56. EditorUtility.SetDirty(panel);
  57. #endif
  58. }
  59. EditorGUILayout.EndHorizontal();
  60. EditorGUILayout.BeginHorizontal();
  61. EditorGUILayout.PrefixLabel("Component Name");
  62. if (GUILayout.Button(componentName.stringValue, "ObjectField"))
  63. EditorWindow.GetWindow<PackagesWindow>(true, "Select a UI Component").SetSelection(packageName.stringValue, componentName.stringValue);
  64. EditorGUILayout.EndHorizontal();
  65. int oldSortingOrder = panel.sortingOrder;
  66. EditorGUILayout.PropertyField(sortingOrder);
  67. EditorGUILayout.PropertyField(renderCamera);
  68. EditorGUILayout.PropertyField(fairyBatching);
  69. EditorGUILayout.PropertyField(touchDisabled);
  70. if (serializedObject.ApplyModifiedProperties())
  71. {
  72. #if UNITY_2018_3_OR_NEWER
  73. bool isPrefab = PrefabUtility.GetPrefabAssetType(panel) != PrefabAssetType.NotAPrefab;
  74. #else
  75. bool isPrefab = PrefabUtility.GetPrefabType(panel) == PrefabType.Prefab;
  76. #endif
  77. if (!isPrefab)
  78. {
  79. panel.ApplyModifiedProperties(sortingOrder.intValue != oldSortingOrder);
  80. }
  81. }
  82. }
  83. }
  84. }