public override void OnInspectorGUI() { AppBar appBar = (AppBar)target; appBar.DisplayType = (AppBar.AppBarDisplayTypeEnum)EditorGUILayout.EnumPopup("Display Type", appBar.DisplayType); if (appBar.DisplayType == AppBar.AppBarDisplayTypeEnum.Manipulation) { HUXEditorUtils.BeginSectionBox("Bounding box"); appBar.BoundingBox = HUXEditorUtils.SceneObjectField <BoundingBoxManipulate>(null, appBar.BoundingBox); if (appBar.BoundingBox == null) { HUXEditorUtils.WarningMessage("Manipulation state will not function correctly at runtime without a bounding box. (If you're using BoundingBoxTarget this is not a problem.)"); } HUXEditorUtils.EndSectionBox(); } HUXEditorUtils.BeginSectionBox("App bar options"); appBar.HoverOffsetYScale = EditorGUILayout.Slider("Hover Offset (Y)", appBar.HoverOffsetYScale, -1f, 2f); appBar.HoverOffsetZ = EditorGUILayout.Slider("Hover Offset (Z)", appBar.HoverOffsetZ, 0f, 2f); appBar.SquareButtonPrefab = (GameObject)EditorGUILayout.ObjectField("Button Prefab", appBar.SquareButtonPrefab, typeof(GameObject)); GUI.color = (appBar.CustomButtonIconProfile == null) ? HUXEditorUtils.DisabledColor : HUXEditorUtils.DefaultColor; appBar.CustomButtonIconProfile = (ButtonIconProfile)EditorGUILayout.ObjectField("Custom Icon Profile", appBar.CustomButtonIconProfile, typeof(ButtonIconProfile)); HUXEditorUtils.DrawSubtleMiniLabel("(Leave blank to use the button's default profile)"); GUI.color = HUXEditorUtils.DefaultColor; if (appBar.SquareButtonPrefab == null) { HUXEditorUtils.ErrorMessage("You must specify a button prefab"); HUXEditorUtils.EndSectionBox(); return; } CompoundButtonIcon icon = appBar.SquareButtonPrefab.GetComponent <CompoundButtonIcon>(); if (icon == null) { HUXEditorUtils.ErrorMessage("You must use a button prefab that has a CompoundButtonIcon component"); HUXEditorUtils.EndSectionBox(); return; } HUXEditorUtils.BeginSubSectionBox("Default buttons"); GUI.color = appBar.UseHide ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor; appBar.UseHide = EditorGUILayout.Toggle("Show / Hide Buttons", appBar.UseHide); GUI.color = appBar.UseAdjust ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor; appBar.UseAdjust = EditorGUILayout.Toggle("Adjust / Done Buttons", appBar.UseAdjust); GUI.color = appBar.UseRemove ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor; appBar.UseRemove = EditorGUILayout.Toggle("Remove Button", appBar.UseRemove); GUI.color = HUXEditorUtils.DefaultColor; HUXEditorUtils.EndSubSectionBox(); HUXEditorUtils.BeginSubSectionBox("Custom buttons"); HUXEditorUtils.DrawSubtleMiniLabel("Up to " + AppBar.MaxCustomButtons + " allowed. Un-named buttons will be ignored."); //HUXEditorUtils.DrawProfileField <ButtonIconProfile> (appBar.CustomButtonIconProfile) // Get the profile we'll be using for our icons ButtonIconProfile profile = appBar.CustomButtonIconProfile; if (profile == null) { profile = icon.Profile; if (profile == null) { HUXEditorUtils.ErrorMessage("The button prefab does not specify an icon profile. Can't continue."); HUXEditorUtils.EndSectionBox(); return; } } AppBar.ButtonTemplate[] buttons = appBar.Buttons; if (buttons.Length != AppBar.MaxCustomButtons) { System.Array.Resize <AppBar.ButtonTemplate>(ref buttons, AppBar.MaxCustomButtons); } int numCustomButtons = appBar.UseHide ? 0 : -1; for (int i = 0; i < buttons.Length; i++) { buttons[i] = DrawButtonEditor(buttons[i], profile, ref numCustomButtons, "buttons", i); } appBar.Buttons = buttons; HUXEditorUtils.EndSubSectionBox(); // Force the buttons to refresh based on the options we've specified appBar.EditorRefreshTemplates(); HUXEditorUtils.BeginSubSectionBox("App bar preview"); HUXEditorUtils.DrawSubtleMiniLabel("An approximation of what the final bar will look like. 'Hidden' and 'Manipulation' states depend on default button settings and may not be available."); previewState = (AppBar.AppBarStateEnum)EditorGUILayout.EnumPopup(previewState); List <AppBar.ButtonTemplate> buttonList = new List <AppBar.ButtonTemplate>(); buttonList.AddRange(appBar.DefaultButtons); buttonList.AddRange(buttons); if (previewState == AppBar.AppBarStateEnum.Default) { buttonList.Sort(delegate(AppBar.ButtonTemplate b1, AppBar.ButtonTemplate b2) { return(b1.DefaultPosition.CompareTo(b2.DefaultPosition)); }); } else { buttonList.Sort(delegate(AppBar.ButtonTemplate b1, AppBar.ButtonTemplate b2) { return(b1.ManipulationPosition.CompareTo(b2.ManipulationPosition)); }); } scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.MaxHeight(previewButtonSize + 15f)); EditorGUILayout.BeginHorizontal(); bool drewOneButton = false; for (int i = 0; i < buttonList.Count; i++) { drewOneButton |= DrawPreviewButton(buttonList[i], previewState, appBar.UseHide, appBar.UseAdjust, appBar.UseRemove); } if (!drewOneButton) { HUXEditorUtils.WarningMessage("This state has no buttons due to the options you've chosen. It won't be permitted during play mode."); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); HUXEditorUtils.EndSubSectionBox(); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(appBar); }
private bool DrawPreviewButton(AppBar.ButtonTemplate template, AppBar.AppBarStateEnum state, bool useHide, bool useAdjust, bool useRemove) { bool drewButton = false; if (template.IsEmpty) { return(drewButton); } if (buttonPreviewStyle == null) { buttonPreviewStyle = new GUIStyle(EditorStyles.toolbarButton); buttonPreviewStyle.fontSize = 8; buttonPreviewStyle.fixedHeight = previewButtonSize; buttonPreviewStyle.fixedWidth = previewButtonSize; } GUI.color = Color.Lerp(Color.gray, HUXEditorUtils.DefaultColor, 0.5f); switch (state) { case AppBar.AppBarStateEnum.Default: switch (template.Type) { case AppBar.ButtonTypeEnum.Custom: GUILayout.Button(template.Text, buttonPreviewStyle); drewButton = true; break; case AppBar.ButtonTypeEnum.Adjust: if (useAdjust) { GUILayout.Button(template.Text, buttonPreviewStyle); drewButton = true; } break; case AppBar.ButtonTypeEnum.Hide: if (useHide) { GUILayout.Button(template.Text, buttonPreviewStyle); drewButton = true; } break; case AppBar.ButtonTypeEnum.Remove: if (useRemove) { GUILayout.Button(template.Text, buttonPreviewStyle); drewButton = true; } break; default: break; } break; case AppBar.AppBarStateEnum.Hidden: switch (template.Type) { case AppBar.ButtonTypeEnum.Show: if (useHide) { GUILayout.Button(template.Text, buttonPreviewStyle); drewButton = true; } break; default: break; } break; case AppBar.AppBarStateEnum.Manipulation: switch (template.Type) { default: break; case AppBar.ButtonTypeEnum.Done: GUILayout.Button(template.Text, buttonPreviewStyle); drewButton = true; break; case AppBar.ButtonTypeEnum.Remove: if (useRemove) { GUILayout.Button(template.Text, buttonPreviewStyle); drewButton = true; } break; } break; } GUI.color = HUXEditorUtils.DefaultColor; return(drewButton); }