Tanoda
pb_LayoutElementTextEditor.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEditor;
3using GILES.Interface;
4
5namespace GILES.UnityEditor
6{
12 [CanEditMultipleObjects, CustomEditor(typeof(pb_LayoutElementText))]
13 public class pb_LayoutElementTextEditor : Editor
14 {
15 SerializedProperty textComponent;
16 SerializedProperty expandWidth, expandHeight;
17 SerializedProperty paddingWidth, paddingHeight;
18 SerializedProperty flexibleWidth, flexibleHeight;
19
20 void OnEnable()
21 {
22 textComponent = serializedObject.FindProperty("text");
23 expandWidth = serializedObject.FindProperty("expandWidth");
24 expandHeight = serializedObject.FindProperty("expandHeight");
25 paddingWidth = serializedObject.FindProperty("paddingWidth");
26 paddingHeight = serializedObject.FindProperty("paddingHeight");
27 flexibleWidth = serializedObject.FindProperty("m_FlexibleWidth");
28 flexibleHeight = serializedObject.FindProperty("m_FlexibleHeight");
29 }
30
31 public override void OnInspectorGUI()
32 {
33 serializedObject.Update();
34
35 EditorGUILayout.PropertyField(textComponent);
36
37 GUILayout.BeginHorizontal();
38 expandWidth.boolValue = EditorGUILayout.Toggle("Expand Width", expandWidth.boolValue);
39 GUI.enabled = expandWidth.boolValue;
40 EditorGUIUtility.labelWidth = 60f;
41 paddingWidth.floatValue = EditorGUILayout.FloatField("Padding", paddingWidth.floatValue);
42 EditorGUIUtility.labelWidth = 0f;
43 GUILayout.EndHorizontal();
44
45 GUILayout.BeginHorizontal();
46 GUI.enabled = true;
47 expandHeight.boolValue = EditorGUILayout.Toggle("Expand Height", expandHeight.boolValue);
48 GUI.enabled = expandHeight.boolValue;
49 EditorGUIUtility.labelWidth = 60f;
50 paddingHeight.floatValue = EditorGUILayout.FloatField("Padding", paddingHeight.floatValue);
51 GUILayout.EndHorizontal();
52
53 bool flexWidth = flexibleWidth.floatValue > 0;
54 bool flexHeight = flexibleHeight.floatValue > 0;
55
56 GUILayout.BeginHorizontal();
57 EditorGUIUtility.labelWidth = 0f;
58 GUI.enabled = true;
59 flexWidth = EditorGUILayout.Toggle("Flexible Width", flexWidth);
60
61 if(flexWidth && flexibleWidth.floatValue < 0f)
62 flexibleWidth.floatValue = 1f;
63 else if(!flexWidth && flexibleWidth.floatValue > 0f)
64 flexibleWidth.floatValue = -1f;
65 GUI.enabled = flexWidth;
66 EditorGUIUtility.labelWidth = 60f;
67 flexibleWidth.floatValue = EditorGUILayout.FloatField("Weight", flexibleWidth.floatValue);
68 GUILayout.EndHorizontal();
69
70 GUILayout.BeginHorizontal();
71 GUI.enabled = true;
72 EditorGUIUtility.labelWidth = 0f;
73 flexHeight = EditorGUILayout.Toggle("Flexible Height", flexHeight);
74
75 if(flexHeight && flexibleHeight.floatValue < 0f)
76 flexibleHeight.floatValue = 1f;
77 else if(!flexHeight && flexibleHeight.floatValue > 0f)
78 flexibleHeight.floatValue = -1f;
79 GUI.enabled = flexHeight;
80 EditorGUIUtility.labelWidth = 60f;
81 flexibleHeight.floatValue = EditorGUILayout.FloatField("Weight", flexibleHeight.floatValue);
82 GUILayout.EndHorizontal();
83
84 GUI.enabled = true;
85
86 serializedObject.ApplyModifiedProperties();
87 }
88 }
89}