Tanoda
pb_GUIStyleApplierEditor.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEditor;
3using UnityEngine.UI;
4using System.Linq;
5
6namespace GILES.Interface
7{
8 [CanEditMultipleObjects, CustomEditor(typeof(pb_GUIStyleApplier))]
9 public class pb_GUIStyleApplierEditor : Editor
10 {
11 SerializedProperty style;
12 SerializedProperty ignore;
13
14 [SerializeField] bool show = true;
15
16 void OnEnable()
17 {
18 style = serializedObject.FindProperty("style");
19 ignore = serializedObject.FindProperty("ignoreStyle");
20 }
21
22 public override void OnInspectorGUI()
23 {
24 serializedObject.Update();
25
26 EditorGUI.BeginChangeCheck();
27
28 if(!ignore.boolValue)
29 EditorGUILayout.PropertyField(style);
30
31 EditorGUILayout.PropertyField(ignore);
32
33 if(!ignore.boolValue && style.objectReferenceValue != null)
34 {
35 show = EditorGUILayout.Foldout(show, style.objectReferenceValue.name);
36
37 if(show)
38 {
39
40 Editor editor = Editor.CreateEditor(style.objectReferenceValue);
41
42 if(editor != null)
43 editor.OnInspectorGUI();
44 }
45 }
46
47
48 if(EditorGUI.EndChangeCheck() || GUILayout.Button("Apply"))
49 {
50 // foreach(pb_GUIStyleApplier applier in serializedObject.targetObjects)
51 // applier.ApplyStyle();
52
53 foreach(pb_GUIStyleApplier applier in Resources.FindObjectsOfTypeAll<pb_GUIStyleApplier>().Where(x => x.style == style.objectReferenceValue))
54 applier.ApplyStyle();
55
56 Canvas.ForceUpdateCanvases();
57 SceneView.RepaintAll();
58 }
59
60 serializedObject.ApplyModifiedProperties();
61 }
62 }
63}