UIPainterEditor.cs 3.4 KB

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