Tanoda
pb_PositionerEditor.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections;
3using System.Reflection;
5using UnityEngine.UI;
6
7namespace GILES.Interface
8{
10 {
11 protected override void InitializeGUI()
12 {
13 pb_GUIUtility.AddVerticalLayoutGroup(gameObject);
14 foreach(PropertyInfo prop in pb_Reflection.GetSerializableProperties(target.GetType(), BindingFlags.Instance | BindingFlags.Public))
15 {
16 if( ignoreProperties.Contains(prop.Name) || System.Attribute.GetCustomAttribute(prop, typeof(pb_InspectorIgnoreAttribute)) != null)
17 continue;
18
19 pb_TypeInspector typeInspector = pb_InspectorResolver.AddTypeInspector(target, transform, property : prop);
20 typeInspector.onTypeInspectorSetValue = this.OnTypeInspectorSetValue;
21 }
22 foreach(FieldInfo fil in target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
23 {
24 if(System.Attribute.GetCustomAttribute(fil, typeof(pb_InspectorIgnoreAttribute)) != null)
25 continue;
26
27 if (fil.Name == "InGoodPosition")
28 continue;
29 pb_TypeInspector typeInspector = pb_InspectorResolver.AddTypeInspector(target, transform, field : fil);
30 typeInspector.onTypeInspectorSetValue = this.OnTypeInspectorSetValue;
31 }
32
33 {
34 var buttonGO = new GameObject("ClickButton");
35 var image = buttonGO.AddComponent<Image>();
36 var button = buttonGO.AddComponent<Button>();
37 var textGO = new GameObject("LabelGO");
38 var text = textGO.AddComponent<Text>();
39 var lec = buttonGO.AddComponent<LayoutElement>();
40 textGO.GetComponent<RectTransform>().sizeDelta = new Vector2(170, 14);
41 lec.minHeight = 24;
42 text.font = Font.CreateDynamicFontFromOSFont("Arial", 24);
43 text.alignment = TextAnchor.MiddleCenter;
44 text.text = "Save Start Position";
45 text.color = Color.white;
46 text.resizeTextForBestFit = true;
47 text.resizeTextMaxSize = 20;
48 textGO.transform.SetParent(buttonGO.transform);
49 image.sprite = GameObject.Find("SaveButton").GetComponent<Image>().sprite;
50 image.type = Image.Type.Sliced;
51 image.color = new Color(255,255,255, 40/255.0f);
52 buttonGO.transform.SetParent(transform);
53 button.onClick.AddListener(target.GetComponent<Positioner>().SaveStartPos);
54 button.onClick.AddListener(UpdateGUI);
55 }
56
57 {
58 var buttonGO = new GameObject("ClickButton2");
59 var image = buttonGO.AddComponent<Image>();
60 var button = buttonGO.AddComponent<Button>();
61 var textGO = new GameObject("LabelGO");
62 var text = textGO.AddComponent<Text>();
63 var lec = buttonGO.AddComponent<LayoutElement>();
64 textGO.GetComponent<RectTransform>().sizeDelta = new Vector2(170, 14);
65 lec.minHeight = 24;
66 text.font = Font.CreateDynamicFontFromOSFont("Arial", 24);
67 text.alignment = TextAnchor.MiddleCenter;
68 text.text = "Save Final Position";
69 text.color = Color.white;
70 text.resizeTextForBestFit = true;
71 text.resizeTextMaxSize = 20;
72 textGO.transform.SetParent(buttonGO.transform);
73 image.sprite = GameObject.Find("SaveButton").GetComponent<Image>().sprite;
74 image.type = Image.Type.Sliced;
75 image.color = new Color(255,255,255, 40/255.0f);
76 buttonGO.transform.SetParent(transform);
77 button.onClick.AddListener(target.GetComponent<Positioner>().SaveFinalPos);
78 button.onClick.AddListener(UpdateGUI);
79 }
80
81 {
82 var buttonGO = new GameObject("ClickButton3");
83 var image = buttonGO.AddComponent<Image>();
84 var button = buttonGO.AddComponent<Button>();
85 var textGO = new GameObject("LabelGO");
86 var text = textGO.AddComponent<Text>();
87 var lec = buttonGO.AddComponent<LayoutElement>();
88 textGO.GetComponent<RectTransform>().sizeDelta = new Vector2(170, 14);
89 lec.minHeight = 24;
90 text.font = Font.CreateDynamicFontFromOSFont("Arial", 24);
91 text.alignment = TextAnchor.MiddleCenter;
92 text.text = "Restore Start Position";
93 text.color = Color.white;
94 text.resizeTextForBestFit = true;
95 text.resizeTextMaxSize = 20;
96 textGO.transform.SetParent(buttonGO.transform);
97 image.sprite = GameObject.Find("SaveButton").GetComponent<Image>().sprite;
98 image.type = Image.Type.Sliced;
99 image.color = new Color(255,255,255, 40/255.0f);
100 buttonGO.transform.SetParent(transform);
101 button.onClick.AddListener(target.GetComponent<Positioner>().RestoreStartPos);
102 }
103
104 {
105 var buttonGO = new GameObject("ClickButton4");
106 var image = buttonGO.AddComponent<Image>();
107 var button = buttonGO.AddComponent<Button>();
108 var textGO = new GameObject("LabelGO");
109 var text = textGO.AddComponent<Text>();
110 var lec = buttonGO.AddComponent<LayoutElement>();
111 textGO.GetComponent<RectTransform>().sizeDelta = new Vector2(170, 14);
112 lec.minHeight = 24;
113 text.font = Font.CreateDynamicFontFromOSFont("Arial", 24);
114 text.alignment = TextAnchor.MiddleCenter;
115 text.text = "Restore Final Position";
116 text.color = Color.white;
117 text.resizeTextForBestFit = true;
118 text.resizeTextMaxSize = 20;
119 textGO.transform.SetParent(buttonGO.transform);
120 image.sprite = GameObject.Find("SaveButton").GetComponent<Image>().sprite;
121 image.type = Image.Type.Sliced;
122 image.color = new Color(255,255,255, 40/255.0f);
123 buttonGO.transform.SetParent(transform);
124 button.onClick.AddListener(target.GetComponent<Positioner>().RestoreFinalPos);
125 }
126 }
127
128 void OnTypeInspectorSetValue()
129 {
130 foreach(pb_Gizmo gizmo in target.gameObject.GetComponents<pb_Gizmo>())
131 {
132 if ( gizmo.CanEditType(target.GetType()) )
133 {
134 gizmo.OnComponentModified();
135 }
136 }
137 }
138 }
139}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32
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