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); }
/// <summary> /// Draws a custom editor for mesh button datum so they're human-editable /// </summary> protected override void DrawCustomFooter() { ButtonMeshProfile meshProfile = (ButtonMeshProfile)target; CompoundButtonMesh meshButton = null; if (targetComponent is CompoundButtonMesh) { meshButton = targetComponent as CompoundButtonMesh; } // Validate our button states - ensure there's one for each button state enum value ButtonStateEnum[] buttonStates = (ButtonStateEnum[])System.Enum.GetValues(typeof(ButtonStateEnum)); List <CompoundButtonMesh.MeshButtonDatum> missingStates = new List <CompoundButtonMesh.MeshButtonDatum>(); foreach (ButtonStateEnum buttonState in buttonStates) { bool foundState = false; foreach (CompoundButtonMesh.MeshButtonDatum datum in meshProfile.ButtonStates) { if (datum.ActiveState == buttonState) { foundState = true; break; } } if (!foundState) { CompoundButtonMesh.MeshButtonDatum missingState = new CompoundButtonMesh.MeshButtonDatum(buttonState) { Name = buttonState.ToString() }; missingStates.Add(missingState); } } // If any were missing, add them to our button states // They may be out of order but we don't care if (missingStates.Count > 0) { missingStates.AddRange(meshProfile.ButtonStates); meshProfile.ButtonStates = missingStates.ToArray(); } foreach (CompoundButtonMesh.MeshButtonDatum datum in meshProfile.ButtonStates) { UnityEditor.EditorGUILayout.Space(); UnityEditor.EditorGUILayout.LabelField(datum.ActiveState.ToString(), UnityEditor.EditorStyles.boldLabel); UnityEditor.EditorGUI.indentLevel++; if (meshButton != null && meshButton.TargetTransform == null) { UnityEditor.EditorGUILayout.LabelField("(No target transform specified for scale / offset)", UnityEditor.EditorStyles.miniLabel); } else { datum.Offset = UnityEditor.EditorGUILayout.Vector3Field("Offset", datum.Offset); datum.Scale = UnityEditor.EditorGUILayout.Vector3Field("Scale", datum.Scale); if (datum.Scale == Vector3.zero) { GUI.color = warningColor; if (GUILayout.Button("Warning: Button state scale is zero. Click here to fix.", UnityEditor.EditorStyles.miniButton)) { datum.Scale = Vector3.one; } } } GUI.color = defaultColor; if (meshButton != null && meshButton.Renderer == null) { UnityEditor.EditorGUILayout.LabelField("(No target renderer specified for color / value material properties)", UnityEditor.EditorStyles.miniLabel); } else { if (!string.IsNullOrEmpty(meshProfile.ColorPropertyName)) { datum.StateColor = UnityEditor.EditorGUILayout.ColorField(meshProfile.ColorPropertyName + " value", datum.StateColor); } if (!string.IsNullOrEmpty(meshProfile.ValuePropertyName)) { datum.StateValue = UnityEditor.EditorGUILayout.FloatField(meshProfile.ValuePropertyName + " value", datum.StateValue); } } UnityEditor.EditorGUI.indentLevel--; } }
public override void OnInspectorGUI() { ButtonMeshProfile meshProfile = (ButtonMeshProfile)target; CompoundButtonMesh meshButton = (CompoundButtonMesh)targetComponent; HUXEditorUtils.BeginProfileBox(); // Draw an editor for each state datum meshProfile.SmoothStateChanges = EditorGUILayout.Toggle("Smooth state changes", meshProfile.SmoothStateChanges); if (meshProfile.SmoothStateChanges) { meshProfile.AnimationSpeed = EditorGUILayout.Slider("Animation speed", meshProfile.AnimationSpeed, 0.01f, 1f); } meshProfile.StickyPressedEvents = EditorGUILayout.Toggle("'Sticky' pressed events", meshProfile.StickyPressedEvents); if (meshProfile.StickyPressedEvents) { meshProfile.StickyPressedTime = EditorGUILayout.Slider("'Sticky' pressed event time", meshProfile.StickyPressedTime, 0.01f, 1f); } // Validate our button states - ensure there's one for each button state enum value Button.ButtonStateEnum[] buttonStates = (Button.ButtonStateEnum[])System.Enum.GetValues(typeof(Button.ButtonStateEnum)); List <CompoundButtonMesh.MeshButtonDatum> missingStates = new List <CompoundButtonMesh.MeshButtonDatum>(); foreach (Button.ButtonStateEnum buttonState in buttonStates) { bool foundState = false; foreach (CompoundButtonMesh.MeshButtonDatum datum in meshProfile.ButtonStates) { if (datum.ActiveState == buttonState) { foundState = true; break; } } if (!foundState) { CompoundButtonMesh.MeshButtonDatum missingState = new CompoundButtonMesh.MeshButtonDatum(buttonState); missingState.Name = buttonState.ToString(); missingStates.Add(missingState); } } // If any were missing, add them to our button states // They may be out of order but we don't care if (missingStates.Count > 0) { missingStates.AddRange(meshProfile.ButtonStates); meshProfile.ButtonStates = missingStates.ToArray(); } foreach (CompoundButtonMesh.MeshButtonDatum datum in meshProfile.ButtonStates) { HUXEditorUtils.BeginSubSectionBox(datum.ActiveState.ToString()); //datum.Name = EditorGUILayout.TextField("Name", datum.Name); if (meshButton != null && meshButton.TargetTransform == null) { HUXEditorUtils.DrawSubtleMiniLabel("(No target transform specified for scale / offset)"); } else { datum.Offset = EditorGUILayout.Vector3Field("Offset", datum.Offset); datum.Scale = EditorGUILayout.Vector3Field("Scale", datum.Scale); if (datum.Scale == Vector3.zero) { GUI.color = HUXEditorUtils.WarningColor; if (GUILayout.Button("Warning: Button state scale is zero. Click here to fix.", EditorStyles.miniButton)) { datum.Scale = Vector3.one; } } } GUI.color = HUXEditorUtils.DefaultColor; if (meshButton != null && meshButton.Renderer == null) { HUXEditorUtils.DrawSubtleMiniLabel("(No target renderer specified for color / value material properties)"); } else { if (!string.IsNullOrEmpty(meshProfile.ColorPropertyName)) { datum.StateColor = EditorGUILayout.ColorField(meshProfile.ColorPropertyName + " value", datum.StateColor); } if (!string.IsNullOrEmpty(meshProfile.ValuePropertyName)) { datum.StateValue = EditorGUILayout.FloatField(meshProfile.ValuePropertyName + " value", datum.StateValue); } } HUXEditorUtils.EndSubSectionBox(); } HUXEditorUtils.EndProfileBox(); HUXEditorUtils.SaveChanges(this); }