GUIUtility
How do I use G U I Utility
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonAnimatorViewEditor.cs
Copy
66 private void DrawWeightInspector()
67 {
68 SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowLayerWeightsInspector");
69 foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Layer Weights", foldoutProperty.boolValue);
70
71 if (foldoutProperty.boolValue == false)
72 {
73 return;
74 }
75
76 float lineHeight = 20;
77 Rect containerRect = PhotonGUI.ContainerBody(this.m_Animator.layerCount*lineHeight);
78
79 for (int i = 0; i < this.m_Animator.layerCount; ++i)
80 {
81 if (this.m_Target.DoesLayerSynchronizeTypeExist(i) == false)
82 {
83 this.m_Target.SetLayerSynchronized(i, PhotonAnimatorView.SynchronizeType.Disabled);
84 EditorUtility.SetDirty(this.m_Target);
85 }
86
87 PhotonAnimatorView.SynchronizeType value = this.m_Target.GetLayerSynchronizeType(i);
88
89 Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + i*lineHeight, containerRect.width, lineHeight);
90
91 Rect labelRect = new Rect(elementRect.xMin + 5, elementRect.yMin + 2, EditorGUIUtility.labelWidth - 5, elementRect.height);
92 GUI.Label(labelRect, "Layer " + i);
93
94 Rect popupRect = new Rect(elementRect.xMin + EditorGUIUtility.labelWidth, elementRect.yMin + 2, elementRect.width - EditorGUIUtility.labelWidth - 5, EditorGUIUtility.singleLineHeight);
95 value = (PhotonAnimatorView.SynchronizeType) EditorGUI.EnumPopup(popupRect, value);
96
97 if (i < this.m_Animator.layerCount - 1)
98 {
99 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
100 PhotonGUI.DrawSplitter(splitterRect);
101 }
102
103 if (value != this.m_Target.GetLayerSynchronizeType(i))
104 {
105 Undo.RecordObject(target, "Modify Synchronize Layer Weights");
106 this.m_Target.SetLayerSynchronized(i, value);
107
108 EditorUtility.SetDirty(this.m_Target);
109 }
110 }
111 }
File name: PhotonAnimatorViewEditor.cs
Copy
179 private void DrawParameterInspector()
180 {
181 SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowParameterInspector");
182 foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Parameters", foldoutProperty.boolValue);
183
184 if (foldoutProperty.boolValue == false)
185 {
186 return;
187 }
188
189 float lineHeight = 20;
190 Rect containerRect = PhotonGUI.ContainerBody(GetParameterCount()*lineHeight);
191
192 for (int i = 0; i < GetParameterCount(); i++)
193 {
194 AnimatorControllerParameter parameter = null;
195
196#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
197 parameter = this.m_Controller.GetParameter(i);
198#else
199 parameter = m_Animator.parameters[ i ];
200#endif
201
202 string defaultValue = "";
203
204 if (parameter.type == AnimatorControllerParameterType.Bool)
205 {
206 defaultValue += parameter.defaultBool.ToString();
207 }
208 else if (parameter.type == AnimatorControllerParameterType.Float)
209 {
210 defaultValue += parameter.defaultFloat.ToString();
211 }
212 else if (parameter.type == AnimatorControllerParameterType.Int)
213 {
214 defaultValue += parameter.defaultInt.ToString();
215 }
216
217 if (this.m_Target.DoesParameterSynchronizeTypeExist(parameter.name) == false)
218 {
219 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, PhotonAnimatorView.SynchronizeType.Disabled);
220 EditorUtility.SetDirty(this.m_Target);
221 }
222
223 PhotonAnimatorView.SynchronizeType value = this.m_Target.GetParameterSynchronizeType(parameter.name);
224
225 Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + i*lineHeight, containerRect.width, lineHeight);
226
227 Rect labelRect = new Rect(elementRect.xMin + 5, elementRect.yMin + 2, EditorGUIUtility.labelWidth - 5, elementRect.height);
228 GUI.Label(labelRect, parameter.name + " (" + defaultValue + ")");
229
230 Rect popupRect = new Rect(elementRect.xMin + EditorGUIUtility.labelWidth, elementRect.yMin + 2, elementRect.width - EditorGUIUtility.labelWidth - 5, EditorGUIUtility.singleLineHeight);
231 value = (PhotonAnimatorView.SynchronizeType) EditorGUI.EnumPopup(popupRect, value);
232
233 if (i < GetParameterCount() - 1)
234 {
235 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
236 PhotonGUI.DrawSplitter(splitterRect);
237 }
238
239 if (value != this.m_Target.GetParameterSynchronizeType(parameter.name))
240 {
241 Undo.RecordObject(target, "Modify Synchronize Parameter " + parameter.name);
242 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, value);
243
244 EditorUtility.SetDirty(this.m_Target);
245 }
246 }
247 }
File name: PhotonRigidbody2DViewEditor.cs
Copy
7 public override void OnInspectorGUI()
8 {
9 PhotonGUI.ContainerHeader("Options");
10
11 Rect containerRect = PhotonGUI.ContainerBody(EditorGUIUtility.singleLineHeight*2 + 10);
12
13 Rect propertyRect = new Rect(containerRect.xMin + 5, containerRect.yMin + 5, containerRect.width, EditorGUIUtility.singleLineHeight);
14 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeVelocity"), new GUIContent("Synchronize Velocity"));
15
16 propertyRect.y += EditorGUIUtility.singleLineHeight;
17 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeAngularVelocity"), new GUIContent("Synchronize Angular Velocity"));
18 }
File name: PhotonRigidbodyViewEditor.cs
Copy
7 public override void OnInspectorGUI()
8 {
9 PhotonGUI.ContainerHeader("Options");
10
11 Rect containerRect = PhotonGUI.ContainerBody(EditorGUIUtility.singleLineHeight*2 + 10);
12
13 Rect propertyRect = new Rect(containerRect.xMin + 5, containerRect.yMin + 5, containerRect.width, EditorGUIUtility.singleLineHeight);
14 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeVelocity"), new GUIContent("Synchronize Velocity"));
15
16 propertyRect.y += EditorGUIUtility.singleLineHeight;
17 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeAngularVelocity"), new GUIContent("Synchronize Angular Velocity"));
18 }
File name: PhotonTransformViewEditor.cs
Copy
96 private void DrawSynchronizePositionData()
97 {
98 if (this.m_SynchronizePositionProperty == null || this.m_SynchronizePositionProperty.boolValue == false)
99 {
100 return;
101 }
102
103 SerializedProperty interpolatePositionProperty = serializedObject.FindProperty("m_PositionModel.InterpolateOption");
104 PhotonTransformViewPositionModel.InterpolateOptions interpolateOption = (PhotonTransformViewPositionModel.InterpolateOptions)interpolatePositionProperty.enumValueIndex;
105
106 SerializedProperty extrapolatePositionProperty = serializedObject.FindProperty("m_PositionModel.ExtrapolateOption");
107 PhotonTransformViewPositionModel.ExtrapolateOptions extrapolateOption = (PhotonTransformViewPositionModel.ExtrapolateOptions)extrapolatePositionProperty.enumValueIndex;
108
109 float containerHeight = 155;
110
111 switch (interpolateOption)
112 {
113 case PhotonTransformViewPositionModel.InterpolateOptions.FixedSpeed:
114 case PhotonTransformViewPositionModel.InterpolateOptions.Lerp:
115 containerHeight += EDITOR_LINE_HEIGHT;
116 break;
117 /*case PhotonTransformViewPositionModel.InterpolateOptions.MoveTowardsComplex:
118 containerHeight += EDITOR_LINE_HEIGHT*3;
119 break;*/
120 }
121
122 if (extrapolateOption != PhotonTransformViewPositionModel.ExtrapolateOptions.Disabled)
123 {
124 containerHeight += EDITOR_LINE_HEIGHT;
125 }
126
127 switch (extrapolateOption)
128 {
129 case PhotonTransformViewPositionModel.ExtrapolateOptions.FixedSpeed:
130 containerHeight += EDITOR_LINE_HEIGHT;
131 break;
132 }
133
134 if (this.m_InterpolateHelpOpen == true)
135 {
136 containerHeight += GetInterpolateHelpBoxHeight();
137 }
138
139 if (this.m_ExtrapolateHelpOpen == true)
140 {
141 containerHeight += GetExtrapolateHelpBoxHeight();
142 }
143
144 // removed Gizmo Options. -3 lines, -1 splitter
145 containerHeight -= EDITOR_LINE_HEIGHT * 2;
146
147 Rect rect = PhotonGUI.ContainerBody(containerHeight);
148
149 Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
150
151 DrawTeleport(ref propertyRect);
152 DrawSplitter(ref propertyRect);
153
154 DrawSynchronizePositionDataInterpolation(ref propertyRect, interpolatePositionProperty, interpolateOption);
155 DrawSplitter(ref propertyRect);
156
157 DrawSynchronizePositionDataExtrapolation(ref propertyRect, extrapolatePositionProperty, extrapolateOption);
158 DrawSplitter(ref propertyRect);
159
160 DrawSynchronizePositionDataGizmos(ref propertyRect);
161 }
File name: PhotonTransformViewEditor.cs
Copy
309 private void DrawSynchronizeRotationData()
310 {
311 if (this.m_SynchronizeRotationProperty == null || this.m_SynchronizeRotationProperty.boolValue == false)
312 {
313 return;
314 }
315
316 SerializedProperty interpolateRotationProperty = serializedObject.FindProperty("m_RotationModel.InterpolateOption");
317 PhotonTransformViewRotationModel.InterpolateOptions interpolateOption =
318 (PhotonTransformViewRotationModel.InterpolateOptions) interpolateRotationProperty.enumValueIndex;
319
320 float containerHeight = 20;
321
322 switch (interpolateOption)
323 {
324 case PhotonTransformViewRotationModel.InterpolateOptions.RotateTowards:
325 case PhotonTransformViewRotationModel.InterpolateOptions.Lerp:
326 containerHeight += EDITOR_LINE_HEIGHT;
327 break;
328 }
329
330 if (this.m_InterpolateRotationHelpOpen == true)
331 {
332 containerHeight += GetInterpolateHelpBoxHeight();
333 }
334
335 Rect rect = PhotonGUI.ContainerBody(containerHeight);
336 Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
337
338 DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateRotationHelpOpen, interpolateRotationProperty, INTERPOLATE_TOOLTIP);
339 DrawHelpBox(ref propertyRect, this.m_InterpolateRotationHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
340
341 switch (interpolateOption)
342 {
343 case PhotonTransformViewRotationModel.InterpolateOptions.RotateTowards:
344 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_RotationModel.InterpolateRotateTowardsSpeed"),
345 new GUIContent("RotateTowards Speed"));
346 break;
347 case PhotonTransformViewRotationModel.InterpolateOptions.Lerp:
348 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_RotationModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
349 break;
350 }
351 }
File name: PhotonTransformViewEditor.cs
Copy
358 private void DrawSynchronizeScaleData()
359 {
360 if (this.m_SynchronizeScaleProperty == null || this.m_SynchronizeScaleProperty.boolValue == false)
361 {
362 return;
363 }
364
365 SerializedProperty interpolateScaleProperty = serializedObject.FindProperty("m_ScaleModel.InterpolateOption");
366 PhotonTransformViewScaleModel.InterpolateOptions interpolateOption = (PhotonTransformViewScaleModel.InterpolateOptions) interpolateScaleProperty.enumValueIndex;
367
368 float containerHeight = EDITOR_LINE_HEIGHT;
369
370 switch (interpolateOption)
371 {
372 case PhotonTransformViewScaleModel.InterpolateOptions.MoveTowards:
373 case PhotonTransformViewScaleModel.InterpolateOptions.Lerp:
374 containerHeight += EDITOR_LINE_HEIGHT;
375 break;
376 }
377
378 if (this.m_InterpolateScaleHelpOpen == true)
379 {
380 containerHeight += GetInterpolateHelpBoxHeight();
381 }
382
383 Rect rect = PhotonGUI.ContainerBody(containerHeight);
384 Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
385
386 DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateScaleHelpOpen, interpolateScaleProperty, INTERPOLATE_TOOLTIP);
387 DrawHelpBox(ref propertyRect, this.m_InterpolateScaleHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
388
389 switch (interpolateOption)
390 {
391 case PhotonTransformViewScaleModel.InterpolateOptions.MoveTowards:
392 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_ScaleModel.InterpolateMoveTowardsSpeed"),
393 new GUIContent("MoveTowards Speed"));
394 break;
395 case PhotonTransformViewScaleModel.InterpolateOptions.Lerp:
396 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_ScaleModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
397 break;
398 }
399 }
File name: PhotonEditor.cs
Copy
269 protected static void Inspect()
270 {
271 EditorGUIUtility.PingObject(PhotonNetwork.PhotonServerSettings);
272 Selection.activeObject = PhotonNetwork.PhotonServerSettings;
273 }
File name: PhotonEditor.cs
Copy
420 protected virtual void OnGuiRegisterCloudApp()
421 {
422 GUI.skin.label.wordWrap = true;
423 if (!this.isSetupWizard)
424 {
425 GUILayout.BeginHorizontal();
426 GUILayout.FlexibleSpace();
427 if (GUILayout.Button(CurrentLang.MainMenuButton, GUILayout.ExpandWidth(false)))
428 {
429 this.SwitchMenuState(GUIState.Main);
430 }
431
432 GUILayout.EndHorizontal();
433
434 GUILayout.Space(15);
435 }
436
437 if (this.photonSetupState == PhotonSetupStates.RegisterForPhotonCloud)
438 {
439 GUI.skin.label.fontStyle = FontStyle.Bold;
440 GUILayout.Label(CurrentLang.ConnectButton);
441 EditorGUILayout.Separator();
442 GUI.skin.label.fontStyle = FontStyle.Normal;
443
444 GUILayout.Label(CurrentLang.UsePhotonLabel);
445 EditorGUILayout.Separator();
446 this.emailAddress = EditorGUILayout.TextField(CurrentLang.EmailLabel, this.emailAddress);
447
448 if (GUILayout.Button(CurrentLang.SendButton))
449 {
450 GUIUtility.keyboardControl = 0;
451 this.RegisterWithEmail(this.emailAddress);
452 }
453
454 GUILayout.Space(20);
455
456
457 GUILayout.Label(CurrentLang.SignedUpAlreadyLabel);
458 if (GUILayout.Button(CurrentLang.SetupButton))
459 {
460 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
461 }
462 EditorGUILayout.Separator();
463
464
465 GUILayout.Label(CurrentLang.RegisterByWebsiteLabel);
466 if (GUILayout.Button(CurrentLang.AccountWebsiteButton))
467 {
468 EditorUtility.OpenWithDefaultApp(UrlAccountPage + Uri.EscapeUriString(this.emailAddress));
469 }
470
471 EditorGUILayout.Separator();
472
473 GUILayout.Label(CurrentLang.SelfHostLabel);
474
475 if (GUILayout.Button(CurrentLang.SelfHostSettingsButton))
476 {
477 this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
478 }
479
480 GUILayout.FlexibleSpace();
481
482
483 if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
484 {
485 GUILayout.Label(CurrentLang.MobileExportNoteLabel);
486 }
487 EditorGUILayout.Separator();
488 }
489 else if (this.photonSetupState == PhotonSetupStates.EmailAlreadyRegistered)
490 {
491 GUI.skin.label.fontStyle = FontStyle.Bold;
492 GUILayout.Label(CurrentLang.OopsLabel);
493 GUI.skin.label.fontStyle = FontStyle.Normal;
494
495 GUILayout.Label(CurrentLang.EmailInUseLabel);
496
497 if (GUILayout.Button(CurrentLang.SeeMyAccountPageButton))
498 {
499 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
500 }
501
502 EditorGUILayout.Separator();
503
504 GUILayout.Label(CurrentLang.KnownAppIdLabel);
505 GUILayout.BeginHorizontal();
506 if (GUILayout.Button(CurrentLang.CancelButton))
507 {
508 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
509 }
510
511 if (GUILayout.Button(CurrentLang.SetupButton))
512 {
513 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
514 }
515
516 GUILayout.EndHorizontal();
517 }
518 else if (this.photonSetupState == PhotonSetupStates.SetupPhotonCloud)
519 {
520 // cloud setup
521 GUI.skin.label.fontStyle = FontStyle.Bold;
522 GUILayout.Label(CurrentLang.PhotonCloudConnect);
523 GUI.skin.label.fontStyle = FontStyle.Normal;
524
525 EditorGUILayout.Separator();
526 this.OnGuiSetupCloudAppId();
527 this.OnGuiCompareAndHelpOptions();
528 }
529 else if (this.photonSetupState == PhotonSetupStates.SetupSelfHosted)
530 {
531 // self-hosting setup
532 GUI.skin.label.fontStyle = FontStyle.Bold;
533 GUILayout.Label(CurrentLang.SetupOwnHostLabel);
534 GUI.skin.label.fontStyle = FontStyle.Normal;
535
536 EditorGUILayout.Separator();
537
538 this.OnGuiSetupSelfhosting();
539 this.OnGuiCompareAndHelpOptions();
540 }
541 }
File name: PhotonEditor.cs
Copy
543 protected virtual void OnGuiMainWizard()
544 {
545 GUILayout.BeginHorizontal();
546 GUILayout.FlexibleSpace();
547 GUILayout.Label(WizardIcon);
548 GUILayout.FlexibleSpace();
549 GUILayout.EndHorizontal();
550
551 EditorGUILayout.Separator();
552
553 GUILayout.Label(CurrentLang.PUNWizardLabel, EditorStyles.boldLabel);
554 if (isPunPlus)
555 {
556 GUILayout.Label(CurrentLang.MobilePunPlusExportNoteLabel);
557 }
558 else if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
559 {
560 GUILayout.Label(CurrentLang.MobileExportNoteLabel);
561 }
562 EditorGUILayout.Separator();
563
564
565 // settings button
566 GUILayout.BeginHorizontal();
567 GUILayout.Label(CurrentLang.SettingsButton, EditorStyles.boldLabel, GUILayout.Width(100));
568 if (GUILayout.Button(new GUIContent(CurrentLang.SetupButton, CurrentLang.SetupServerCloudLabel)))
569 {
570 this.InitPhotonSetupWindow();
571 }
572
573 GUILayout.EndHorizontal();
574 EditorGUILayout.Separator();
575
576
577 // find / select settings asset
578 GUILayout.BeginHorizontal();
579 GUILayout.Label(CurrentLang.SettingsFileLabel, EditorStyles.boldLabel, GUILayout.Width(100));
580 if (GUILayout.Button(new GUIContent(CurrentLang.LocateSettingsButton, CurrentLang.SettingsHighlightLabel)))
581 {
582 EditorGUIUtility.PingObject(PhotonEditor.Current);
583 }
584
585 GUILayout.EndHorizontal();
586
587
588 GUILayout.FlexibleSpace();
589
590 // converter
591 GUILayout.BeginHorizontal();
592 GUILayout.Label(CurrentLang.ConverterLabel, EditorStyles.boldLabel, GUILayout.Width(100));
593 if (GUILayout.Button(new GUIContent(CurrentLang.StartButton, CurrentLang.UNtoPUNLabel)))
594 {
595 PhotonConverter.RunConversion();
596 }
597
598 GUILayout.EndHorizontal();
599 EditorGUILayout.Separator();
600
601
602 // documentation
603 GUILayout.BeginHorizontal();
604 GUILayout.Label(CurrentLang.DocumentationLabel, EditorStyles.boldLabel, GUILayout.Width(100));
605 GUILayout.BeginVertical();
606 if (GUILayout.Button(new GUIContent(CurrentLang.OpenPDFText, CurrentLang.OpenPDFTooltip)))
607 {
608 EditorUtility.OpenWithDefaultApp(DocumentationLocation);
609 }
610
611 if (GUILayout.Button(new GUIContent(CurrentLang.OpenDevNetText, CurrentLang.OpenDevNetTooltip)))
612 {
613 EditorUtility.OpenWithDefaultApp(UrlDevNet);
614 }
615
616 if (GUILayout.Button(new GUIContent(CurrentLang.OpenCloudDashboardText, CurrentLang.OpenCloudDashboardTooltip)))
617 {
618 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
619 }
620
621 if (GUILayout.Button(new GUIContent(CurrentLang.OpenForumText, CurrentLang.OpenForumTooltip)))
622 {
623 EditorUtility.OpenWithDefaultApp(UrlForum);
624 }
625
626 GUILayout.EndVertical();
627 GUILayout.EndHorizontal();
628 }
GUIUtility 172 lượt xem
Gõ tìm kiếm nhanh...