private void DisableStick(string name) { UltimateJoystick s = UltimateJoystick.GetJoystick(name); if (s != null) { CanvasGroup cg = s.GetComponent <CanvasGroup>(); cg.alpha = 0.0f; } }
void StoreReferences() { targ = ( UltimateJoystick )target; joystick = serializedObject.FindProperty("joystick"); joystickSizeFolder = serializedObject.FindProperty("joystickSizeFolder"); joystickBase = serializedObject.FindProperty("joystickBase"); highlightBase = serializedObject.FindProperty("highlightBase"); highlightJoystick = serializedObject.FindProperty("highlightJoystick"); tensionAccentUp = serializedObject.FindProperty("tensionAccentUp"); tensionAccentDown = serializedObject.FindProperty("tensionAccentDown"); tensionAccentLeft = serializedObject.FindProperty("tensionAccentLeft"); tensionAccentRight = serializedObject.FindProperty("tensionAccentRight"); scalingAxis = serializedObject.FindProperty("scalingAxis"); anchor = serializedObject.FindProperty("anchor"); joystickTouchSize = serializedObject.FindProperty("joystickTouchSize"); customTouchSize_X = serializedObject.FindProperty("customTouchSize_X"); customTouchSize_Y = serializedObject.FindProperty("customTouchSize_Y"); customTouchSizePos_X = serializedObject.FindProperty("customTouchSizePos_X"); customTouchSizePos_Y = serializedObject.FindProperty("customTouchSizePos_Y"); dynamicPositioning = serializedObject.FindProperty("dynamicPositioning"); joystickSize = serializedObject.FindProperty("joystickSize"); radiusModifier = serializedObject.FindProperty("radiusModifier"); customSpacing_X = serializedObject.FindProperty("customSpacing_X"); customSpacing_Y = serializedObject.FindProperty("customSpacing_Y"); gravity = serializedObject.FindProperty("gravity"); extendRadius = serializedObject.FindProperty("extendRadius"); axis = serializedObject.FindProperty("axis"); boundary = serializedObject.FindProperty("boundary"); deadZone = serializedObject.FindProperty("deadZone"); tapCountOption = serializedObject.FindProperty("tapCountOption"); tapCountDuration = serializedObject.FindProperty("tapCountDuration"); targetTapCount = serializedObject.FindProperty("targetTapCount"); disableVisuals = serializedObject.FindProperty("disableVisuals"); showHighlight = serializedObject.FindProperty("showHighlight"); highlightColor = serializedObject.FindProperty("highlightColor"); showTension = serializedObject.FindProperty("showTension"); tensionColorNone = serializedObject.FindProperty("tensionColorNone"); tensionColorFull = serializedObject.FindProperty("tensionColorFull"); useAnimation = serializedObject.FindProperty("useAnimation"); useFade = serializedObject.FindProperty("useFade"); fadeUntouched = serializedObject.FindProperty("fadeUntouched"); fadeTouched = serializedObject.FindProperty("fadeTouched"); fadeInDuration = serializedObject.FindProperty("fadeInDuration"); fadeOutDuration = serializedObject.FindProperty("fadeOutDuration"); joystickName = serializedObject.FindProperty("joystickName"); exampleCodeOptions = new List <string>(); for (int i = 0; i < exampleCodes.Length; i++) { exampleCodeOptions.Add(exampleCodes[i].optionName); } SetDisableVisuals(targ); SetHighlight(targ); SetAnimation(targ); SetTensionAccent(targ); if (targ.useFade == true) { if (!targ.GetComponent <CanvasGroup>()) { targ.gameObject.AddComponent <CanvasGroup>(); } targ.gameObject.GetComponent <CanvasGroup>().alpha = targ.fadeUntouched; } else { if (!targ.GetComponent <CanvasGroup>()) { targ.gameObject.AddComponent <CanvasGroup>(); } targ.gameObject.GetComponent <CanvasGroup>().alpha = 1.0f; } }
public override void OnInspectorGUI() { serializedObject.Update(); showDefaultInspector = EditorGUILayout.ToggleLeft("Default Inspector", showDefaultInspector); if (showDefaultInspector) { base.OnInspectorGUI(); return; } EditorGUILayout.Space(); #region ERROR CHECK if (CanvasErrors() == true) { if (parentCanvas.renderMode != RenderMode.ScreenSpaceOverlay) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.HelpBox("The parent Canvas needs to be set to 'Screen Space - Overlay' in order for the Ultimate Joystick to function correctly.", MessageType.Error); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Update Canvas", EditorStyles.miniButtonLeft)) { parentCanvas.renderMode = RenderMode.ScreenSpaceOverlay; parentCanvas = GetParentCanvas(); } if (GUILayout.Button("Update Joystick", EditorStyles.miniButtonRight)) { UltimateJoystickCreator.RequestCanvas(Selection.activeGameObject); parentCanvas = GetParentCanvas(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } if (parentCanvas.GetComponent <CanvasScaler>()) { if (parentCanvas.GetComponent <CanvasScaler>().uiScaleMode != CanvasScaler.ScaleMode.ConstantPixelSize) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.HelpBox("The Canvas Scaler component located on the parent Canvas needs to be set to 'Constant Pixel Size' in order for the Ultimate Joystick to function correctly.", MessageType.Error); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Update Canvas", EditorStyles.miniButtonLeft)) { parentCanvas.GetComponent <CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize; parentCanvas = GetParentCanvas(); UltimateJoystick joystick = ( UltimateJoystick )target; joystick.UpdatePositioning(); } if (GUILayout.Button("Update Joystick", EditorStyles.miniButtonRight)) { UltimateJoystickCreator.RequestCanvas(Selection.activeGameObject); parentCanvas = GetParentCanvas(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } } return; } #endregion #region SIZE AND PLACEMENT DisplayHeader("Size and Placement", "UUI_SizeAndPlacement"); if (EditorPrefs.GetBool("UUI_SizeAndPlacement")) { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(joystick, new GUIContent("Joystick")); EditorGUILayout.PropertyField(joystickSizeFolder, new GUIContent("Size Folder")); EditorGUILayout.PropertyField(joystickBase, new GUIContent("Joystick Base")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } EditorGUILayout.PropertyField(scalingAxis, new GUIContent("Scaling Axis", "The axis to scale the Ultimate Joystick from.")); EditorGUILayout.PropertyField(anchor, new GUIContent("Anchor", "The side of the screen that the\njoystick will be anchored to.")); EditorGUILayout.PropertyField(joystickTouchSize, new GUIContent("Touch Size", "The size of the area in which\nthe touch can be initiated.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (targ.joystickTouchSize == UltimateJoystick.JoystickTouchSize.Custom) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Touch Size Customization"); EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); { EditorGUILayout.Slider(customTouchSize_X, 0.0f, 100.0f, new GUIContent("Width", "The width of the Joystick Touch Area.")); EditorGUILayout.Slider(customTouchSize_Y, 0.0f, 100.0f, new GUIContent("Height", "The height of the Joystick Touch Area.")); EditorGUILayout.Slider(customTouchSizePos_X, 0.0f, 100.0f, new GUIContent("X Position", "The x position of the Joystick Touch Area.")); EditorGUILayout.Slider(customTouchSizePos_Y, 0.0f, 100.0f, new GUIContent("Y Position", "The y position of the Joystick Touch Area.")); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } EditorGUILayout.EndVertical(); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(dynamicPositioning, new GUIContent("Dynamic Positioning", "Moves the joystick to the position of the initial touch.")); EditorGUILayout.Slider(joystickSize, 1.0f, 4.0f, new GUIContent("Joystick Size", "The overall size of the joystick.")); EditorGUILayout.Slider(radiusModifier, 2.0f, 7.0f, new GUIContent("Radius", "Determines how far the joystick can\nmove visually from the center.")); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Joystick Position"); EditorGUI.indentLevel = 1; EditorGUILayout.Slider(customSpacing_X, 0.0f, 50.0f, new GUIContent("X Position:", "The horizontal position of the joystick on the screen.")); EditorGUILayout.Slider(customSpacing_Y, 0.0f, 100.0f, new GUIContent("Y Position:", "The vertical position of the joystick on the screen.")); EditorGUI.indentLevel = 0; GUILayout.Space(1); EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } } #endregion EditorGUILayout.Space(); #region JOYSTICK FUNCTIONALITY DisplayHeader("Joystick Functionality", "UUI_Functionality"); if (EditorPrefs.GetBool("UUI_Functionality")) { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(gravity, new GUIContent("Gravity", "The speed to apply to the joystick when returning to center.")); if (EditorGUI.EndChangeCheck()) { gravity.floatValue = Mathf.Clamp(gravity.floatValue, 0.0f, 60.0f); serializedObject.ApplyModifiedProperties(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(extendRadius, new GUIContent("Extend Radius", "Drags the joystick to follow the touch if it is farther than the radius.")); EditorGUILayout.PropertyField(axis, new GUIContent("Axis", "Constrains the joystick to a certain axis.")); EditorGUILayout.PropertyField(boundary, new GUIContent("Boundary", "Determines how the joystick's position is clamped.")); EditorGUILayout.Slider(deadZone, 0.0f, 1.0f, new GUIContent("Dead Zone", "Size of the dead zone. All values within this range map to neutral.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (targ.extendRadius == true && targ.boundary == UltimateJoystick.Boundary.Square) { EditorGUILayout.HelpBox("Extend Radius option will force the boundary to being circular. Please use a circular boundary when using the Extend Radius option.", MessageType.Warning); } // TAP COUNT // EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(tapCountOption, new GUIContent("Tap Count", "Allows the joystick to calculate double taps and a touch and release within a certain time window.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (targ.tapCountOption != UltimateJoystick.TapCountOption.NoCount) { EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.Slider(tapCountDuration, 0.0f, 1.0f, new GUIContent("Tap Time Window", "Time in seconds that the joystick can receive taps.")); if (targ.tapCountOption == UltimateJoystick.TapCountOption.Accumulate) { EditorGUILayout.IntSlider(targetTapCount, 1, 5, new GUIContent("Target Tap Count", "How many taps to activate the Tap Count Event?")); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } EditorGUI.indentLevel = 0; } } #endregion EditorGUILayout.Space(); #region VISUAL OPTIONS DisplayHeader("Visual Options", "UUI_VisualOptions"); if (EditorPrefs.GetBool("UUI_VisualOptions")) { EditorGUILayout.Space(); // -----------------------< DISABLE VISUALS >---------------------- // EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(disableVisuals, new GUIContent("Disable Visuals", "Disables the visuals of the joystick.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); if (targ.disableVisuals == true) { showHighlight.boolValue = false; showTension.boolValue = false; useFade.boolValue = false; useAnimation.boolValue = false; serializedObject.ApplyModifiedProperties(); } SetDisableVisuals(targ); SetHighlight(targ); SetTensionAccent(targ); SetAnimation(targ); } if (targ.disableVisuals == true && targ.joystickBase == null) { EditorGUILayout.HelpBox("Joystick Base needs to be assigned in the Assigned Variables section.", MessageType.Error); } EditorGUI.BeginDisabledGroup(targ.disableVisuals == true); // This is the start of the disabled fields if the user is using the disableVisuals option. EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(useFade, new GUIContent("Use Fade", "Fades the joystick visuals when interacted with.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); if (targ.useFade == true) { targ.gameObject.GetComponent <CanvasGroup>().alpha = targ.fadeUntouched; } else { targ.gameObject.GetComponent <CanvasGroup>().alpha = 1.0f; } } if (targ.useFade) { EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.Slider(fadeUntouched, 0.0f, 1.0f, new GUIContent("Fade Untouched", "The alpha of the joystick when it is NOT receiving input.")); EditorGUILayout.Slider(fadeTouched, 0.0f, 1.0f, new GUIContent("Fade Touched", "The alpha of the joystick when receiving input.")); EditorGUILayout.PropertyField(fadeInDuration); EditorGUILayout.PropertyField(fadeOutDuration); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); targ.gameObject.GetComponent <CanvasGroup>().alpha = targ.fadeUntouched; } EditorGUI.indentLevel = 0; EditorGUILayout.Space(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(useAnimation, new GUIContent("Use Animation", "Plays animations in reaction to input.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); SetAnimation(targ); } if (targ.useAnimation && !targ.GetComponent <Animator>()) { EditorGUILayout.HelpBox("There is no Animator component attached to this GameObject.", MessageType.Error); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(showHighlight, new GUIContent("Show Highlight", "Displays the highlight images with the Highlight Color variable.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); SetHighlight(targ); } if (targ.showHighlight) { EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(highlightBase, new GUIContent("Base Highlight")); EditorGUILayout.PropertyField(highlightJoystick, new GUIContent("Joystick Highlight")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(highlightColor); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); targ.UpdateHighlightColor(targ.highlightColor); // For every highlight image that is assigned, set the object to dirty so the properties will be applied. This is needed for prefab instances. if (targ.highlightBase != null) { EditorUtility.SetDirty(targ.highlightBase); } if (targ.highlightJoystick != null) { EditorUtility.SetDirty(targ.highlightJoystick); } } if (targ.highlightBase == null && targ.highlightJoystick == null) { EditorGUILayout.HelpBox("No highlight images have been assigned. Please assign some highlight images before continuing.", MessageType.Error); } EditorGUI.indentLevel = 0; EditorGUILayout.Space(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(showTension, new GUIContent("Show Tension", "Displays the visual direction of the joystick using the tension color options.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); SetTensionAccent(targ); } if (targ.showTension) { EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(tensionAccentUp, new GUIContent("Tension Up")); EditorGUILayout.PropertyField(tensionAccentDown, new GUIContent("Tension Down")); EditorGUILayout.PropertyField(tensionAccentLeft, new GUIContent("Tension Left")); EditorGUILayout.PropertyField(tensionAccentRight, new GUIContent("Tension Right")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(tensionColorNone, new GUIContent("Tension None", "The color displayed when the joystick\nis closest to center.")); EditorGUILayout.PropertyField(tensionColorFull, new GUIContent("Tension Full", "The color displayed when the joystick\nis at the furthest distance.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); TensionAccentReset(targ); // For every tension accent that is assigned, set it dirty to apply the color properties. This is needed for applying properties to prefab instances. if (targ.tensionAccentUp != null) { EditorUtility.SetDirty(targ.tensionAccentUp); } if (targ.tensionAccentDown != null) { EditorUtility.SetDirty(targ.tensionAccentDown); } if (targ.tensionAccentLeft != null) { EditorUtility.SetDirty(targ.tensionAccentLeft); } if (targ.tensionAccentRight != null) { EditorUtility.SetDirty(targ.tensionAccentRight); } } if (targ.tensionAccentUp == null && targ.tensionAccentDown == null && targ.tensionAccentLeft == null && targ.tensionAccentRight == null) { EditorGUILayout.HelpBox("No tension accent images have been assigned. Please assign some images before continuing.", MessageType.Error); } EditorGUI.indentLevel = 0; } EditorGUI.EndDisabledGroup(); // This is the end for the Touch Pad option. } #endregion EditorGUILayout.Space(); #region SCRIPT REFERENCE DisplayHeader("Script Reference", "UUI_ScriptReference"); if (EditorPrefs.GetBool("UUI_ScriptReference")) { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(joystickName, new GUIContent("Joystick Name", "The name of the targeted joystick used for static referencing.")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } if (targ.joystickName == string.Empty) { EditorGUILayout.HelpBox("Please assign a Joystick Name in order to be able to get this joystick's position dynamically.", MessageType.Warning); } else { EditorGUILayout.BeginVertical("Box"); GUILayout.Space(1); EditorGUILayout.LabelField("Example Code Generator", EditorStyles.boldLabel); exampleCodeIndex = EditorGUILayout.Popup("Function", exampleCodeIndex, exampleCodeOptions.ToArray()); EditorGUILayout.LabelField("Function Description", EditorStyles.boldLabel); GUIStyle wordWrappedLabel = new GUIStyle(GUI.skin.label) { wordWrap = true }; EditorGUILayout.LabelField(exampleCodes[exampleCodeIndex].optionDescription, wordWrappedLabel); EditorGUILayout.LabelField("Example Code", EditorStyles.boldLabel); GUIStyle wordWrappedTextArea = new GUIStyle(GUI.skin.textArea) { wordWrap = true }; EditorGUILayout.TextArea(string.Format(exampleCodes[exampleCodeIndex].basicCode, joystickName.stringValue), wordWrappedTextArea); GUILayout.Space(1); EditorGUILayout.EndVertical(); } if (GUILayout.Button("Open Documentation")) { //UltimateJoystickReadmeEditor.OpenReadmeDocumentation(); if (Selection.activeGameObject != null && !AssetDatabase.Contains(Selection.activeGameObject) && Application.isPlaying) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Current Position:", EditorStyles.boldLabel); EditorGUILayout.LabelField("Horizontal Axis: " + targ.HorizontalAxis.ToString("F2")); EditorGUILayout.LabelField("Vertical Axis: " + targ.VerticalAxis.ToString("F2")); EditorGUILayout.EndVertical(); } } } #endregion EditorGUILayout.Space(); Repaint(); }