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.TextArea(menu.Title); menu.TitleText = HUXEditorUtils.DropDownComponentField <TextMesh>("Title TextMesh", menu.TitleText, menu.transform); } menu.DisplaySubtitle = EditorGUILayout.Toggle("Display Subtitle", menu.DisplaySubtitle); if (menu.DisplaySubtitle) { //menu.TitleText.font = (Font)EditorGUILayout.ObjectField("Title font", menu.TitleText.font, typeof(Font), false); menu.Subtitle = EditorGUILayout.TextArea(menu.Subtitle); menu.SubtitleText = HUXEditorUtils.DropDownComponentField <TextMesh>("Subtitle TextMesh", menu.SubtitleText, 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); }
public override void OnInspectorGUI() { CompoundButtonIcon iconButton = (CompoundButtonIcon)target; iconButton.DisableIcon = EditorGUILayout.Toggle("Disable icon", iconButton.DisableIcon); if (iconButton.DisableIcon) { HUXEditorUtils.SaveChanges(target); return; } profileProp.objectReferenceValue = HUXEditorUtils.DrawProfileField <ButtonIconProfile>(profileProp.objectReferenceValue as ButtonIconProfile); //iconButton.Profile = HUXEditorUtils.DrawProfileField<ButtonIconProfile>(iconButton.Profile); if (iconButton.Profile == null) { HUXEditorUtils.SaveChanges(target); 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); return; } if (iconButton.Profile.IconMaterial == null) { HUXEditorUtils.ErrorMessage("You must specify an icon material in the profile", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target); return; } if (iconButton.Profile.IconMesh == null) { HUXEditorUtils.ErrorMessage("You must specify an icon mesh in the profile", null); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target); 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(iconButton, iconButton.Profile); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { CompoundButtonToggle toggle = (CompoundButtonToggle)target; HUXEditorUtils.BeginSectionBox("Target"); toggle.Target = HUXEditorUtils.DropDownComponentField <MonoBehaviour>("Component", toggle.Target, toggle.transform, true); FieldInfo fieldInfo = null; Type profileType = null; if (toggle.Target == null) { HUXEditorUtils.ErrorMessage("Target must be set."); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); return; } else { fieldInfo = toggle.Target.GetType().GetField("Profile"); if (fieldInfo == null) { HUXEditorUtils.ErrorMessage("Target component has no 'Profile' field - are you use this class inherits from ProfileButtonBase?"); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); return; } GUIStyle labelStyle = new GUIStyle(EditorStyles.label); labelStyle.fontSize = 18; labelStyle.fontStyle = FontStyle.Bold; profileType = fieldInfo.FieldType; EditorGUILayout.LabelField("Type: " + toggle.Target.GetType().Name + " / " + fieldInfo.FieldType.Name, labelStyle, GUILayout.MinHeight(24)); } HUXEditorUtils.EndSectionBox(); HUXEditorUtils.BeginSectionBox("Toggling"); HUXEditorUtils.DrawSubtleMiniLabel("Select on/off profiles of the type " + profileType.Name); if (toggle.OnProfile == null) { toggle.OnProfile = (ButtonProfile)fieldInfo.GetValue(toggle.Target); } if (toggle.OffProfile == null) { toggle.OffProfile = toggle.OnProfile; } ButtonProfile onProfile = (ButtonProfile)EditorGUILayout.ObjectField("On Profile", toggle.OnProfile, typeof(ButtonProfile), false); ButtonProfile offProfile = (ButtonProfile)EditorGUILayout.ObjectField("Off Profile", toggle.OffProfile, typeof(ButtonProfile), false); if (onProfile.GetType() == profileType) { toggle.OnProfile = onProfile; } if (offProfile.GetType() == profileType) { toggle.OffProfile = offProfile; } if (toggle.OnProfile.GetType() != profileType) { HUXEditorUtils.ErrorMessage("On profile object does not match type " + profileType.Name); } if (toggle.OffProfile.GetType() != profileType) { HUXEditorUtils.ErrorMessage("Off profile object does not match type " + profileType.Name); } if (onProfile == offProfile) { HUXEditorUtils.WarningMessage("Profiles are the same - toggle will have no effect"); } toggle.Behavior = (CompoundButtonToggle.ToggleBehaviorEnum)EditorGUILayout.EnumPopup("Toggle behavior", toggle.Behavior); HUXEditorUtils.EndSectionBox(); HUXEditorUtils.BeginSectionBox("State"); if (!Application.isPlaying) { toggle.State = EditorGUILayout.Toggle(toggle.State); } else { EditorGUILayout.Toggle(toggle.State); } HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); }
public override void OnInspectorGUI() { CompoundButtonMesh meshButton = (CompoundButtonMesh)target; GUI.color = HUXEditorUtils.DefaultColor; meshButton.Profile = HUXEditorUtils.DrawProfileField <ButtonMeshProfile>(meshButton.Profile); if (meshButton.Profile == 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.Profile.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.Profile.ColorPropertyName = HUXEditorUtils.MaterialPropertyName( meshButton.Profile.ColorPropertyName, meshButton.Renderer.sharedMaterial, ShaderUtil.ShaderPropertyType.Color); meshButton.Profile.ValuePropertyName = HUXEditorUtils.MaterialPropertyName( meshButton.Profile.ValuePropertyName, meshButton.Renderer.sharedMaterial, ShaderUtil.ShaderPropertyType.Float); } HUXEditorUtils.EndSectionBox(); // Draw the profile HUXEditorUtils.DrawProfileInspector(meshButton.Profile, meshButton); HUXEditorUtils.SaveChanges(target, meshButton.Profile); }
public override void OnInspectorGUI() { DrawDefaultInspector(); CompoundButtonAnim acb = (CompoundButtonAnim)target; if (UnityEditor.Selection.gameObjects.Length == 1) { acb.TargetAnimator = HUXEditorUtils.DropDownComponentField <Animator>("Target animator", acb.TargetAnimator, acb.transform); if (acb.TargetAnimator == null) { GUI.color = HUXEditorUtils.ErrorColor; EditorGUILayout.LabelField("You must chooes a target animator."); HUXEditorUtils.SaveChanges(target, serializedObject); return; } } else { EditorGUILayout.LabelField("(This section not supported for multiple objects)", EditorStyles.miniLabel); } Animator animator = acb.TargetAnimator; AnimatorControllerParameter[] animParams = null; if (!animator.isInitialized) { HUXEditorUtils.SaveChanges(target, serializedObject); return; } // Validate the AnimButton controls - make sure there's one control for each button state Button.ButtonStateEnum[] buttonStates = (Button.ButtonStateEnum[])System.Enum.GetValues(typeof(Button.ButtonStateEnum)); if (acb.AnimActions == null || acb.AnimActions.Length != buttonStates.Length) { acb.AnimActions = new CompoundButtonAnim.AnimatorControllerAction[buttonStates.Length]; } // Don't allow user to change setup during play mode if (!Application.isPlaying) { // Get the available animation parameters animParams = animator.parameters; for (int i = 0; i < buttonStates.Length; i++) { acb.AnimActions[i].ButtonState = buttonStates[i]; } // Now make sure all animation parameters are found for (int i = 0; i < acb.AnimActions.Length; i++) { if (!string.IsNullOrEmpty(acb.AnimActions[i].ParamName)) { bool invalidParam = true; foreach (AnimatorControllerParameter animParam in animParams) { if (acb.AnimActions[i].ParamName == animParam.name) { // Update the type while we're here invalidParam = false; acb.AnimActions[i].ParamType = animParam.type; break; } } // If we didn't find it, mark it as invalid acb.AnimActions[i].InvalidParam = invalidParam; } } } if (!acb.gameObject.activeInHierarchy) { //GUI.color = HUX.Editor.EditorStyles.ColorWarning; EditorGUILayout.LabelField("(Gameobject must be active to view animation actions)"); HUXEditorUtils.SaveChanges(target, serializedObject); return; } // Draw the editor for all the anim actions HUXEditorUtils.BeginSectionBox("Animation actions"); for (int i = 0; i < acb.AnimActions.Length; i++) { acb.AnimActions[i] = DrawAnimActionEditor(acb.AnimActions[i], animParams); } HUXEditorUtils.EndSectionBox(); HUXEditorUtils.SaveChanges(target, serializedObject); }
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); return; } textButton.TextProfile = HUXEditorUtils.DrawProfileField <ButtonTextProfile>(textButton.TextProfile); if (textButton.TextProfile == null) { HUXEditorUtils.SaveChanges(target); return; } 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); return; } 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.TextProfile, textButton); HUXEditorUtils.SaveChanges(target); }
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(cb); }