Tanoda
pb_ComponentEditor.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using UnityEngine.UI;
4using System.Collections;
5using System.Collections.Generic;
6using System.Reflection;
7
8namespace GILES.Interface
9{
22 public class pb_ComponentEditor : MonoBehaviour
23 {
25 protected Component target;
26
27 public static readonly HashSet<string> ignoreProperties = new HashSet<string>()
28 {
29 "tag",
30 "name",
31 "hideFlags",
32 "useGUILayout"
33 };
34
39 {
40 foreach(Transform t in transform)
41 pb_ObjectUtility.Destroy(t.gameObject);
42
43 this.target = target;
44
46 }
47
51 public virtual void UpdateGUI()
52 {
53 foreach(pb_TypeInspector inspector in gameObject.GetComponentsInChildren<pb_TypeInspector>(false))
54 inspector.UpdateGUI();
55 }
56
57 protected virtual void InitializeGUI()
58 {
59 pb_GUIUtility.AddVerticalLayoutGroup(gameObject);
60
61 foreach(PropertyInfo prop in pb_Reflection.GetSerializableProperties(target.GetType(), BindingFlags.Instance | BindingFlags.Public))
62 {
63 try
64 {
65 if (ignoreProperties.Contains(prop.Name) || System.Attribute.GetCustomAttribute(prop, typeof(pb_InspectorIgnoreAttribute)) != null)
66 continue;
67 //Debug.Log($"prop.Name = {prop.Name}");
68 pb_TypeInspector typeInspector = pb_InspectorResolver.AddTypeInspector(target, transform, property: prop);
69 typeInspector.onTypeInspectorSetValue = this.OnTypeInspectorSetValue;
70 }
71 catch (Exception e)
72 {
73 //Debug.LogError(e);
74 }
75 }
76
77 foreach(FieldInfo fil in target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
78 {
79 if(System.Attribute.GetCustomAttribute(fil, typeof(pb_InspectorIgnoreAttribute)) != null)
80 continue;
81
82 pb_TypeInspector typeInspector = pb_InspectorResolver.AddTypeInspector(target, transform, field : fil);
83 typeInspector.onTypeInspectorSetValue = this.OnTypeInspectorSetValue;
84 }
85 }
86
90 void OnTypeInspectorSetValue()
91 {
92 foreach(pb_Gizmo gizmo in target.gameObject.GetComponents<pb_Gizmo>())
93 {
94 if ( gizmo.CanEditType(target.GetType()) )
95 {
96 gizmo.OnComponentModified();
97 }
98 }
99 }
100 }
101}
UnityEngine.Component Component
static readonly HashSet< string > ignoreProperties
Component target
The UnityEngine.Component being edited.
bool CanEditType(Type t)
Definition: pb_Gizmo.cs:58
virtual void OnComponentModified()
Definition: pb_Gizmo.cs:55