public override void OnInspectorGUI() { CompoundButtonIcon iconButton = (CompoundButtonIcon)target; iconButton.DisableIcon = EditorGUILayout.Toggle("Disable icon", iconButton.DisableIcon); if (iconButton.DisableIcon) { HUXEditorUtils.SaveChanges(target, serializedObject); return; } profileProp.objectReferenceValue = HUXEditorUtils.DrawProfileField <ButtonIconProfile>(profileProp.objectReferenceValue as ButtonIconProfile); //iconButton.Profile = HUXEditorUtils.DrawProfileField<ButtonIconProfile>(iconButton.Profile); if (iconButton.Profile == null) { HUXEditorUtils.SaveChanges(target, serializedObject); return; } HUXEditorUtils.BeginSectionBox("Icon settings"); if (UnityEditor.Selection.gameObjects.Length == 1) { iconButton.IconRenderer = HUXEditorUtils.DropDownComponentField <MeshRenderer>("Icon renderer", iconButton.IconRenderer, iconButton.transform); if (iconButton.IconRenderer == null) { HUXEditorUtils.ErrorMessage("You must specify an icon renderer", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); return; } if (iconButton.Profile.IconMaterial == null) { HUXEditorUtils.ErrorMessage("You must specify an icon material in the profile", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); return; } if (iconButton.Profile.IconMesh == null) { HUXEditorUtils.ErrorMessage("You must specify an icon mesh in the profile", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); return; } // Icon profiles provide their own fields for the icon name iconButton.Alpha = EditorGUILayout.Slider("Icon transparency", iconButton.Alpha, 0f, 1f); iconButton.IconName = iconButton.Profile.DrawIconSelectField(iconButton.IconName); } else { EditorGUILayout.LabelField("(This section not supported for multiple objects)", EditorStyles.miniLabel); } HUXEditorUtils.EndSectionBox(); HUXEditorUtils.DrawProfileInspector(iconButton.Profile, iconButton); // Check to see if the icon is valid - if it's not, show the placeholder /*Texture2D icon = iconButton.IconRenderer.sharedMaterial.mainTexture as Texture2D; * if (icon == null || icon == iconButton.IconProfile._IconNotFound_) * { * HUXEditorUtils.WarningMessage( * "Texture '" + iconButton.IconName + "' was not found in the selected profile. A substitute will be displayed until an icon file has been added to the profile.", * "Click to open profile", * ClickToOpen); * }*/ HUXEditorUtils.SaveChanges(target, serializedObject); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { CompoundButtonText textButton = (CompoundButtonText)target; textAreaLabel = new GUIStyle(EditorStyles.textArea); textAreaLabel.fontSize = 32; GUI.color = Color.white; textButton.DisableText = EditorGUILayout.Toggle("Disable text", textButton.DisableText); if (textButton.DisableText) { HUXEditorUtils.SaveChanges(target, serializedObject); return; } profileProp.objectReferenceValue = HUXEditorUtils.DrawProfileField <ButtonTextProfile>(profileProp.objectReferenceValue as ButtonTextProfile); if (textButton.Profile == null) { HUXEditorUtils.SaveChanges(target, serializedObject); return; } if (UnityEditor.Selection.gameObjects.Length == 1) { textButton.TextMesh = HUXEditorUtils.DropDownComponentField <TextMesh>("Text mesh", textButton.TextMesh, textButton.transform); //textButton.TextMesh = (TextMesh)EditorGUILayout.ObjectField("Text mesh", textButton.TextMesh, typeof(TextMesh), true); if (textButton.TextMesh == null) { GUI.color = HUXEditorUtils.ErrorColor; EditorGUILayout.LabelField("You must select a text mesh object."); HUXEditorUtils.SaveChanges(target, serializedObject); return; } } else { EditorGUILayout.LabelField("(This section not supported for multiple objects)", EditorStyles.miniLabel); } HUXEditorUtils.BeginSectionBox("Overrides"); EditorGUILayout.BeginHorizontal(); textButton.OverrideFontStyle = EditorGUILayout.Toggle("Font style", textButton.OverrideFontStyle); if (textButton.OverrideFontStyle) { textButton.Style = (FontStyle)EditorGUILayout.EnumPopup(textButton.Style); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); textButton.OverrideAnchor = EditorGUILayout.Toggle("Text anchor", textButton.OverrideAnchor); if (textButton.OverrideAnchor) { textButton.Anchor = (TextAnchor)EditorGUILayout.EnumPopup(textButton.Anchor); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); textButton.OverrideSize = EditorGUILayout.Toggle("Text size", textButton.OverrideSize); if (textButton.OverrideSize) { textButton.Size = EditorGUILayout.IntField(textButton.Size); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); textButton.OverrideOffset = EditorGUILayout.Toggle("Offset", textButton.OverrideOffset); if (textButton.OverrideOffset) { EditorGUILayout.LabelField("(You may now manually adjust the offset of the text)", EditorStyles.miniLabel); } EditorGUILayout.EndHorizontal(); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.BeginSectionBox("Button text"); textButton.Text = EditorGUILayout.TextArea(textButton.Text, textAreaLabel); HUXEditorUtils.EndSectionBox(); //textButton.Alpha = EditorGUILayout.Slider("Text transparency", textButton.Alpha, 0f, 1f); HUXEditorUtils.DrawProfileInspector(textButton.Profile, textButton); HUXEditorUtils.SaveChanges(target, serializedObject); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { SimpleMenuCollection menu = (SimpleMenuCollection)target; HUXEditorUtils.BeginSectionBox("Menu settings"); menu.DisplayTitle = EditorGUILayout.Toggle("Display Title", menu.DisplayTitle); if (menu.DisplayTitle) { //menu.TitleText.font = (Font)EditorGUILayout.ObjectField("Title font", menu.TitleText.font, typeof(Font), false); menu.Title = EditorGUILayout.TextField("Title", menu.Title); menu.TitleText = HUXEditorUtils.DropDownComponentField <TextMesh>("Title TextMesh", menu.TitleText, menu.transform); } menu.ButtonPrefab = (GameObject)EditorGUILayout.ObjectField("Button prefab", menu.ButtonPrefab, typeof(GameObject), false); menu.ParentCollection = HUXEditorUtils.DropDownComponentField <ObjectCollection>("Collection parent", menu.ParentCollection, menu.transform); if (menu.ButtonPrefab == null) { HUXEditorUtils.ErrorMessage("You must specify a button prefab"); HUXEditorUtils.EndSectionBox(); return; } if (menu.ParentCollection == null) { HUXEditorUtils.ErrorMessage("This menu needs a collection component to work", AddCollection, "Fix"); HUXEditorUtils.EndSectionBox(); return; } bool showIcon = false; bool showText = false; CompoundButtonIcon icon = menu.ButtonPrefab.GetComponent <CompoundButtonIcon>(); showIcon = icon != null; CompoundButtonText text = menu.ButtonPrefab.GetComponent <CompoundButtonText>(); showText = text != null; ButtonIconProfile profile = null; if (icon != null) { profile = icon.IconProfile; } HUXEditorUtils.BeginSubSectionBox("Buttons"); HUXEditorUtils.DrawSubtleMiniLabel("Up to " + SimpleMenuCollection.MaxButtons + " allowed. Un-named buttons will be ignored."); SimpleMenuCollectionButton[] buttons = menu.Buttons; HashSet <string> buttonNamesSoFar = new HashSet <string>(); int numButtons = 0; for (int i = 0; i < buttons.Length; i++) { if (!buttons[i].IsEmpty) { numButtons++; } DrawButtonEditor(buttons[i], showIcon, showText, profile, "buttons", i, buttonNamesSoFar); } HUXEditorUtils.EndSubSectionBox(); menu.EditorRefreshButtons(); HUXEditorUtils.BeginSubSectionBox("Menu preview"); HUXEditorUtils.DrawSubtleMiniLabel("An approximation of what the menu will look like."); List <SimpleMenuCollectionButton> buttonsList = new List <SimpleMenuCollectionButton>(buttons); buttonsList.Sort(delegate(SimpleMenuCollectionButton b1, SimpleMenuCollectionButton b2) { return(b1.Index.CompareTo(b2.Index)); }); scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.MinHeight(previewButtonSizeY * numButtons + 50f)); EditorGUILayout.BeginVertical(); bool drewOneButton = false; foreach (SimpleMenuCollectionButton button in buttonsList) { drewOneButton = DrawPreviewButton(button, showText); } 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.EndVertical(); EditorGUILayout.EndScrollView(); HUXEditorUtils.EndSubSectionBox(); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(menu); }
private void DrawButtonEditor(SimpleMenuCollectionButton template, bool showIcon, bool showText, ButtonIconProfile profile, string arrayName, int templateIndex, HashSet <string> buttonNamesSoFar) { HUXEditorUtils.BeginSectionBox(template.IsEmpty ? "(Empty)" : template.Name + " (" + template.Index + ")", HUXEditorUtils.ObjectColor); GUI.color = template.IsEmpty ? HUXEditorUtils.DisabledColor : HUXEditorUtils.DefaultColor; EditorGUILayout.BeginHorizontal(); template.Name = EditorGUILayout.TextField("Button Name", template.Name); if (GUILayout.Button("Clear", EditorStyles.miniButton)) { template.Name = string.Empty; } EditorGUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(template.Name) && buttonNamesSoFar.Contains(template.Name)) { HUXEditorUtils.ErrorMessage("Buttons must have unique names."); } else { buttonNamesSoFar.Add(template.Name); } if (!template.IsEmpty) { if (showText) { if (string.IsNullOrEmpty(template.Text)) { GUI.color = HUXEditorUtils.WarningColor; } template.Text = EditorGUILayout.TextField("Label Text", template.Text); } if (showIcon) { GUI.color = HUXEditorUtils.DefaultColor; string[] keys = profile.GetIconKeys().ToArray(); int selectedIndex = 0; for (int i = 0; i < keys.Length; i++) { if (keys[i].Equals(template.Icon)) { selectedIndex = i; break; } } selectedIndex = EditorGUILayout.Popup("Icon", selectedIndex, keys); template.Icon = keys[selectedIndex]; } if (!Application.isPlaying) { template.Target = HUXEditorUtils.SceneObjectField <InteractionReceiver>("Interaction Receiver", template.Target); if (template.Target == null) { HUXEditorUtils.WarningMessage("This button will have no effect until you choose an interaction receiver to register it with."); } } } // Draw the unity message section /*string propertyName = string.Format("{0}.Array.data[{1}].OnTappedEvent", arrayName, templateIndex); * SerializedProperty buttonEvent = serializedObject.FindProperty(propertyName); * EditorGUILayout.PropertyField(buttonEvent); * if (GUI.changed) { * serializedObject.ApplyModifiedProperties(); * }*/ HUXEditorUtils.EndSectionBox(); }
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.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); }
public override void OnInspectorGUI() { CompoundButton cb = (CompoundButton)target; // Don't perform this check at runtime if (!Application.isPlaying) { // First, check our colliders // Get the components we need for the button to be visible Rigidbody parentRigidBody = cb.GetComponent <Rigidbody>(); Collider parentCollider = cb.GetComponent <Collider>(); // Get all child colliders that AREN'T the parent collider HashSet <Collider> childColliders = new HashSet <Collider>(cb.GetComponentsInChildren <Collider>()); childColliders.Remove(parentCollider); bool foundError = false; EditorGUILayout.BeginVertical(EditorStyles.helpBox); if (parentCollider == null) { if (childColliders.Count == 0) { foundError = true; GUI.color = HUXEditorUtils.ErrorColor; EditorGUILayout.LabelField("Error: Button must have at least 1 collider to be visible, preferably on the root transform.", EditorStyles.wordWrappedLabel); if (GUILayout.Button("Fix now")) { cb.gameObject.AddComponent <BoxCollider>(); } } else if (parentRigidBody == null) { foundError = true; GUI.color = HUXEditorUtils.ErrorColor; EditorGUILayout.LabelField("Error: Button requires a rigidbody if colliders are only present on child transforms.", EditorStyles.wordWrappedLabel); if (GUILayout.Button("Fix now")) { Rigidbody rb = cb.gameObject.AddComponent <Rigidbody>(); rb.isKinematic = true; } } else if (!parentRigidBody.isKinematic) { foundError = true; GUI.color = HUXEditorUtils.WarningColor; EditorGUILayout.LabelField("Warning: Button rigid body is not kinematic - this is not recommended.", EditorStyles.wordWrappedLabel); if (GUILayout.Button("Fix now")) { parentRigidBody.isKinematic = true; } } } // If our colliders were fine, next check the interaction manager to make sure the button will be visible if (!foundError) { FocusManager fm = GameObject.FindObjectOfType <FocusManager>(); if (fm != null) { if (fm.RaycastLayerMask != (fm.RaycastLayerMask | (1 << cb.gameObject.layer))) { foundError = true; GUI.color = HUXEditorUtils.WarningColor; EditorGUILayout.LabelField("Warning: Button is not on a layer that the focus manager can see. Button will not receive input until either the button's layer or the FocusManager's RaycastLayerMask is changed. (This may be intentional.)", EditorStyles.wordWrappedLabel); if (fm.RaycastLayerMask.value != 0) { if (GUILayout.Button("Fix now")) { // Put the button on the first layer that the layer mask can see for (int i = 0; i < 32; i++) { if (fm.RaycastLayerMask == (fm.RaycastLayerMask | (1 << i))) { cb.gameObject.layer = i; break; } } } } } } else { EditorGUILayout.LabelField("(Couldn't find a focus manager to perform visibility check)", EditorStyles.wordWrappedLabel); } } if (!foundError) { GUI.color = HUXEditorUtils.SuccessColor; EditorGUILayout.LabelField("Button is good to go!", EditorStyles.wordWrappedLabel); } EditorGUILayout.EndVertical(); } GUI.color = HUXEditorUtils.DefaultColor; HUXEditorUtils.BeginSectionBox("Button properties", HUXEditorUtils.DefaultColor); // Draw the filter tag field HUXEditorUtils.DrawFilterTagField(serializedObject, "FilterTag"); cb.RequireGaze = EditorGUILayout.Toggle("Require Gaze", cb.RequireGaze); cb.ButtonState = (Button.ButtonStateEnum)EditorGUILayout.EnumPopup("Button State", cb.ButtonState); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.BeginSectionBox("Commonly referenced components", HUXEditorUtils.DefaultColor); cb.MainCollider = HUXEditorUtils.DropDownComponentField <Collider>("Main collider", cb.MainCollider, cb.transform); cb.MainRenderer = HUXEditorUtils.DropDownComponentField <MeshRenderer>("Main renderer", cb.MainRenderer, cb.transform); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); }
public override void OnInspectorGUI() { CompoundButtonMesh meshButton = (CompoundButtonMesh)target; GUI.color = HUXEditorUtils.DefaultColor; meshButton.MeshProfile = HUXEditorUtils.DrawProfileField <ButtonMeshProfile>(meshButton.MeshProfile); if (meshButton.MeshProfile == null) { HUXEditorUtils.SaveChanges(target); return; } HUXEditorUtils.BeginSectionBox("Target objects"); meshButton.TargetTransform = HUXEditorUtils.DropDownComponentField <Transform> ("Transform", meshButton.TargetTransform, meshButton.transform); if (meshButton.TargetTransform != null && meshButton.TargetTransform == meshButton.transform) { HUXEditorUtils.WarningMessage("Button may behave strangely if scale & offset is applied to transform root. Consider choosing a child transform."); } else if (meshButton.TargetTransform != null) { // Check to see if offset & scale match any of the button defaults bool foundCloseState = false; foreach (CompoundButtonMesh.MeshButtonDatum datum in meshButton.MeshProfile.ButtonStates) { if (meshButton.TargetTransform.localPosition == datum.Offset && meshButton.TargetTransform.localScale == datum.Scale) { foundCloseState = true; break; } } if (!foundCloseState) { HUXEditorUtils.WarningMessage("Transform doesn't match the scale / offset of any button states. Button may appear different at runtime."); } } GUI.color = HUXEditorUtils.DefaultColor; meshButton.Renderer = HUXEditorUtils.DropDownComponentField <MeshRenderer>("Mesh Renderer", meshButton.Renderer, meshButton.transform); //meshButton.MeshFilter = HUXEditorUtils.DropDownComponentField<MeshFilter>("Mesh Filter", meshButton.MeshFilter, meshButton.transform); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.BeginSectionBox("Target material properties", (meshButton.Renderer == null ? HUXEditorUtils.DisabledColor : HUXEditorUtils.DefaultColor)); if (meshButton.Renderer == null) { HUXEditorUtils.DrawSubtleMiniLabel("(No renderer specified)"); } else { meshButton.MeshProfile.ColorPropertyName = HUXEditorUtils.MaterialPropertyName( meshButton.MeshProfile.ColorPropertyName, meshButton.Renderer.sharedMaterial, ShaderUtil.ShaderPropertyType.Color); meshButton.MeshProfile.ValuePropertyName = HUXEditorUtils.MaterialPropertyName( meshButton.MeshProfile.ValuePropertyName, meshButton.Renderer.sharedMaterial, ShaderUtil.ShaderPropertyType.Float); } HUXEditorUtils.EndSectionBox(); // Draw the profile HUXEditorUtils.DrawProfileInspector(meshButton.MeshProfile, meshButton); HUXEditorUtils.SaveChanges(target, meshButton.MeshProfile); }