Skip to content

Commit 6ebba0e

Browse files
authored
Merge pull request fairygui#207 from qiwucwb/displayinfo-editor-change
Update DisplayObjectEditor.cs 增加显示的信息
2 parents 796b75b + 4d49fb6 commit 6ebba0e

File tree

1 file changed

+196
-7
lines changed

1 file changed

+196
-7
lines changed

Assets/Scripts/Editor/DisplayObjectEditor.cs

Lines changed: 196 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,23 @@ namespace FairyGUIEditor
1010
[CustomEditor(typeof(DisplayObjectInfo))]
1111
public class DisplayObjectEditor : Editor
1212
{
13+
bool _guiControllersFoldout = true;
14+
bool _guiTransitionsFoldout = true;
15+
bool _guiTextFormatFoldout = true;
16+
1317
void OnEnable()
1418
{
19+
EditorApplication.update += _onEditorAppUpdate;
20+
}
21+
22+
private void OnDisable()
23+
{
24+
EditorApplication.update -= _onEditorAppUpdate;
25+
}
26+
27+
void _onEditorAppUpdate()
28+
{
29+
Repaint();
1530
}
1631

1732
public override void OnInspectorGUI()
@@ -77,6 +92,11 @@ public override void OnInspectorGUI()
7792
EditorGUILayout.EndHorizontal();
7893
}
7994

95+
EditorGUI.BeginChangeCheck();
96+
float alpha = EditorGUILayout.Slider("Alpha", gObj.alpha, 0, 1);
97+
if (EditorGUI.EndChangeCheck())
98+
gObj.alpha = alpha;
99+
80100
EditorGUI.BeginChangeCheck();
81101
Vector3 position = EditorGUILayout.Vector3Field("Position", gObj.position);
82102
if (EditorGUI.EndChangeCheck())
@@ -121,16 +141,185 @@ public override void OnInspectorGUI()
121141
if (EditorGUI.EndChangeCheck())
122142
gObj.icon = icon;
123143

124-
if (gObj.displayObject != null)
144+
//Draw Color Field
145+
var objType = gObj.GetType();
146+
var colorProperty = objType.GetProperty("color");
147+
if (colorProperty != null)
125148
{
126-
EditorGUI.BeginDisabledGroup(true);
127149
EditorGUI.BeginChangeCheck();
128-
EditorGUILayout.BeginHorizontal();
129-
EditorGUILayout.PrefixLabel("Rendering Order");
130-
EditorGUILayout.IntField(gObj.displayObject.renderingOrder);
131-
EditorGUILayout.EndHorizontal();
132-
EditorGUI.EndDisabledGroup();
150+
Color color = (Color)colorProperty.GetValue(gObj);
151+
color = EditorGUILayout.ColorField("Color", color);
152+
if (EditorGUI.EndChangeCheck())
153+
{
154+
colorProperty.SetValue(gObj, color);
155+
}
156+
}
157+
158+
EditorGUI.BeginChangeCheck();
159+
string tooltips = EditorGUILayout.TextField("Tooltips", gObj.tooltips);
160+
if (EditorGUI.EndChangeCheck())
161+
gObj.tooltips = tooltips;
162+
163+
if (gObj is not (GImage))
164+
{
165+
EditorGUI.BeginChangeCheck();
166+
bool touchable = EditorGUILayout.Toggle("Touchable", gObj.touchable);
167+
if (EditorGUI.EndChangeCheck())
168+
gObj.touchable = touchable;
169+
170+
EditorGUI.BeginChangeCheck();
171+
bool draggable = EditorGUILayout.Toggle("Draggable", gObj.draggable);
172+
if (EditorGUI.EndChangeCheck())
173+
gObj.draggable = draggable;
174+
}
175+
176+
TextFormat textFormat = null;
177+
if (gObj is GTextField gTxt)
178+
{
179+
textFormat = gTxt.textFormat;
180+
}
181+
182+
if (textFormat != null)
183+
{
184+
_guiTextFormatFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_guiTextFormatFoldout, "Text Format");
185+
EditorGUI.BeginChangeCheck();
186+
if (_guiTextFormatFoldout)
187+
{
188+
189+
var initLabelWidth = EditorGUIUtility.labelWidth;
190+
191+
var richStyle = new GUIStyle(GUI.skin.label);
192+
richStyle.richText = true;
193+
EditorGUIUtility.labelWidth = 60;
194+
textFormat.font = EditorGUILayout.TextField("Font", textFormat.font);
195+
textFormat.align = (AlignType)EditorGUILayout.EnumPopup("Align",textFormat.align);
196+
197+
EditorGUIUtility.labelWidth = initLabelWidth;
198+
EditorGUILayout.BeginHorizontal();
199+
EditorGUIUtility.labelWidth = 40;
200+
textFormat.size = EditorGUILayout.IntField("Size", textFormat.size);
201+
textFormat.color = EditorGUILayout.ColorField("Color", textFormat.color);
202+
EditorGUIUtility.labelWidth = initLabelWidth;
203+
EditorGUILayout.EndHorizontal();
204+
205+
EditorGUILayout.BeginHorizontal();
206+
EditorGUIUtility.labelWidth = 40;
207+
textFormat.outline = EditorGUILayout.FloatField("Outline", textFormat.outline);
208+
textFormat.outlineColor = EditorGUILayout.ColorField("Color", textFormat.outlineColor);
209+
EditorGUIUtility.labelWidth = initLabelWidth;
210+
EditorGUILayout.EndHorizontal();
211+
212+
EditorGUILayout.BeginHorizontal();
213+
EditorGUIUtility.labelWidth = 50;
214+
textFormat.shadowOffset = EditorGUILayout.Vector2Field("Shadow Offset", textFormat.shadowOffset);
215+
textFormat.shadowColor = EditorGUILayout.ColorField("Color", textFormat.shadowColor);
216+
EditorGUIUtility.labelWidth = initLabelWidth;
217+
EditorGUILayout.EndHorizontal();
218+
219+
220+
EditorGUILayout.BeginHorizontal();
221+
textFormat.italic = EditorGUILayout.ToggleLeft("<i>I</i>", textFormat.italic, richStyle,GUILayout.Width(30));
222+
textFormat.bold = EditorGUILayout.ToggleLeft("<b>B</b>", textFormat.bold, richStyle, GUILayout.Width(30));
223+
textFormat.underline = EditorGUILayout.ToggleLeft("U̲", textFormat.underline, richStyle, GUILayout.Width(30));
224+
textFormat.strikethrough = EditorGUILayout.ToggleLeft(" S̶ ̶ ̶", textFormat.strikethrough, richStyle, GUILayout.Width(36));
225+
EditorGUILayout.EndHorizontal();
226+
227+
EditorGUILayout.BeginHorizontal();
228+
EditorGUIUtility.labelWidth = 90;
229+
textFormat.lineSpacing = EditorGUILayout.IntField("Line Spacing", textFormat.lineSpacing);
230+
textFormat.letterSpacing = EditorGUILayout.IntField("Letter Spacing", textFormat.letterSpacing);
231+
EditorGUIUtility.labelWidth = initLabelWidth;
232+
EditorGUILayout.EndHorizontal();
233+
textFormat.specialStyle = (TextFormat.SpecialStyle)EditorGUILayout.EnumPopup("Special Style", textFormat.specialStyle);
234+
235+
}
236+
if (EditorGUI.EndChangeCheck())
237+
gObj.asTextField.textFormat = textFormat;
238+
239+
EditorGUILayout.EndFoldoutHeaderGroup();
240+
}
241+
242+
if (gObj is GComponent gComp)
243+
{
244+
EditorGUI.BeginChangeCheck();
245+
bool opaque = EditorGUILayout.Toggle("Opaque", gComp.opaque);
246+
if (EditorGUI.EndChangeCheck())
247+
gComp.opaque = opaque;
248+
249+
var headerLabelStyle = new GUIStyle(GUI.skin.label);
250+
headerLabelStyle.fontStyle = FontStyle.Bold;
251+
252+
if (gComp.Controllers.Count > 0)
253+
{
254+
_guiControllersFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_guiControllersFoldout, "Controllers");
255+
if (_guiControllersFoldout)
256+
{
257+
foreach (var ctl in gComp.Controllers)
258+
{
259+
EditorGUILayout.BeginHorizontal();
260+
EditorGUILayout.LabelField(ctl.name, headerLabelStyle, GUILayout.MaxWidth(ctl.name.Length * 15));
261+
262+
for (var i = 0; i < ctl.pageCount; i++)
263+
{
264+
var btnName = ctl.GetPageId(i) + ": " + ctl.GetPageName(i);
265+
var btnStyle = new GUIStyle("ButtonMid");
266+
if (ctl.selectedIndex == i)
267+
{
268+
btnStyle.normal.textColor = Color.green;
269+
btnStyle.hover.textColor = Color.yellow;
270+
btnStyle.fontStyle = FontStyle.Bold;
271+
}
272+
if (GUILayout.Button(btnName, btnStyle))
273+
{
274+
ctl.selectedIndex = i;
275+
}
276+
}
277+
EditorGUILayout.EndHorizontal();
278+
}
279+
}
280+
EditorGUILayout.EndFoldoutHeaderGroup();
281+
}
282+
283+
if (gComp.Transitions.Count > 0)
284+
{
285+
_guiTransitionsFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_guiTransitionsFoldout, "Transitions");
286+
if (_guiTransitionsFoldout)
287+
{
288+
foreach (var transition in gComp.Transitions)
289+
{
290+
EditorGUILayout.BeginHorizontal();
291+
var labelStyle = new GUIStyle(headerLabelStyle);
292+
if (transition.playing)
293+
{
294+
labelStyle.normal.textColor = Color.yellow;
295+
}
296+
297+
EditorGUILayout.LabelField($"{transition.name} - {transition.totalDuration}s", labelStyle, GUILayout.MinWidth(150));
298+
EditorGUI.BeginChangeCheck();
299+
var timeScale = transition.timeScale;
300+
301+
302+
if (EditorGUI.EndChangeCheck())
303+
transition.timeScale = timeScale;
304+
305+
306+
if (GUILayout.Button("▶", GUILayout.Width(20)))
307+
{
308+
transition.Play();
309+
}
310+
311+
if (GUILayout.Button("■", GUILayout.Width(20)))
312+
{
313+
transition.Stop();
314+
}
315+
316+
EditorGUILayout.EndHorizontal();
317+
}
318+
}
319+
EditorGUILayout.EndFoldoutHeaderGroup();
320+
}
133321
}
322+
134323
}
135324
}
136325
}

0 commit comments

Comments
 (0)