Пример #1
0
    /* -----< DECLARATIONS - END >----- */



    void Start()
    {
        //Find Objects
        nc           = GameObject.FindObjectOfType <NumberCruncher>();
        myJoystick   = GameObject.FindObjectOfType <UltimateJoystick>();
        myFire       = GameObject.FindObjectOfType <UltimateButton>();
        levelManager = GameObject.FindObjectOfType <LevelManager>();



        //TODO: Add comments to whole section
        float   distance  = transform.position.z - Camera.main.transform.position.z;
        Vector3 leftmost  = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, distance));
        Vector3 rightmost = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, distance));

        xmin = leftmost.x + padding;
        xmax = rightmost.x - padding;



        //Get the size of the player controls from the PPM
        //Also applies changes made to the controls in the setting menu
        myJoystick.joystickSize = PlayerPrefsManager.ControlsSize_Get();
        myFire.buttonSize       = PlayerPrefsManager.ControlsSize_Get();
        myFire.UpdatePositioning();     // ask UB to update our changes
        myJoystick.UpdatePositioning(); // ask UJ to update our changes
    }                                   //Start() -end
Пример #2
0
 void Update()
 {
     // If the button has been pressed down on this frame, and the truck is not moving faster than -250, then set the motor speed to -250.
     if (UltimateButton.GetButtonDown("Gas") && wheelMotor.motorSpeed > -250)
     {
         wheelMotor.motorSpeed = -250;
     }
 }
Пример #3
0
        private void DisableButton(string name)
        {
            UltimateButton b = UltimateButton.GetUltimateButton(name);

            if (b != null)
            {
                CanvasGroup cg = b.GetComponent <CanvasGroup>();
                cg.alpha = 0.0f;
            }
        }
Пример #4
0
    void OnEnable()
    {
        // Store the Ultimate Button references as soon as this script is being viewed.
        StoreReferences();

        // Register the Undo function to be called for undo's.
        Undo.undoRedoPerformed += UndoRedoCallback;

        // Store the parent canvas.
        parentCanvas = GetParentCanvas();

        UltimateButton targ = ( UltimateButton )target;

        TransmitInputEnabled = new AnimBool(targ.transmitInput);

        TensionAccentError = new AnimBool(targ.tensionAccent == null);
    }
Пример #5
0
    void SetHighlight(UltimateButton ub)
    {
        if (ub.showHighlight == true)
        {
            if (ub.buttonHighlight != null && ub.buttonHighlight.gameObject.activeInHierarchy == false)
            {
                ub.buttonHighlight.gameObject.SetActive(true);
            }

            ub.UpdateHighlightColor(ub.highlightColor);
        }
        else
        {
            if (ub.buttonHighlight != null && ub.buttonHighlight.gameObject.activeInHierarchy == true)
            {
                ub.buttonHighlight.gameObject.SetActive(false);
            }
        }
    }
Пример #6
0
        void Update()
        {
            Vector3 angles = this.transform.localRotation.eulerAngles;

            angles.x = this.ForceAngle;
            this.transform.localRotation = Quaternion.Euler(angles);

            if (this.LastLaunched != null)
            {
                this.EnableButton("BoostButton");

                this.DisableButton("LaunchButton");
                this.DisableStick("LaunchStick");

                if (UltimateButton.GetButtonDown("BoostButton"))
                {
                    this.Boost(this.LastLaunched);
                    this.LastLaunched = null;
                }
            }
            else
            {
                this.EnableButton("LaunchButton");
                this.EnableStick("LaunchStick");

                this.DisableButton("BoostButton");

                if (UltimateButton.GetButtonDown("LaunchButton"))
                {
                    this.LaunchNext();
                }
            }

            if (this.PathRenderer != null)
            {
                this.PathRenderer.ForceAmount   = this.ForceAmount;
                this.PathRenderer.LineStart     = (this.LaunchPoint != null) ? this.LaunchPoint.transform.position : this.transform.position;
                this.PathRenderer.LineDirection = this.transform.forward;
            }
        }
Пример #7
0
 void SetAnimation(UltimateButton ub)
 {
     if (ub.useAnimation == true)
     {
         if (ub.buttonAnimator != null)
         {
             if (ub.buttonAnimator.enabled == false)
             {
                 ub.buttonAnimator.enabled = true;
             }
         }
     }
     else
     {
         if (ub.buttonAnimator != null)
         {
             if (ub.buttonAnimator.enabled == true)
             {
                 ub.buttonAnimator.enabled = false;
             }
         }
     }
 }
Пример #8
0
    void SetTensionAccent(UltimateButton ub)
    {
        if (ub.showTension == true)
        {
            if (ub.tensionAccent == null)
            {
                return;
            }

            if (ub.tensionAccent != null && ub.tensionAccent.gameObject.activeInHierarchy == false)
            {
                ub.tensionAccent.gameObject.SetActive(true);
            }

            ub.tensionAccent.color = ub.tensionColorNone;
        }
        else
        {
            if (ub.tensionAccent != null && ub.tensionAccent.gameObject.activeInHierarchy == true)
            {
                ub.tensionAccent.gameObject.SetActive(false);
            }
        }
    }
	void SetAnimation ( UltimateButton ult )
	{
		if( ult.useAnimation == true )
		{
			if( ult.buttonAnimator != null )
				if( ult.buttonAnimator.enabled == false )
					ult.buttonAnimator.enabled = true;
		}
		else
		{
			if( ult.buttonAnimator != null )
				if( ult.buttonAnimator.enabled == true )
					ult.buttonAnimator.enabled = false;
		}
	}
	void SetTensionAccent ( UltimateButton ult )
	{
		if( ult.showTension == true )
		{
			if( ult.tensionAccent == null )
				return;
			
			if( ult.tensionAccent != null && ult.tensionAccent.gameObject.activeInHierarchy == false )
				ult.tensionAccent.gameObject.SetActive( true );

			ult.tensionAccent.color = ult.tensionColorNone;
		}
		else
		{
			if( ult.tensionAccent != null && ult.tensionAccent.gameObject.activeInHierarchy == true )
				ult.tensionAccent.gameObject.SetActive( false );
		}
	}
	void SetHighlight ( UltimateButton ult )
	{
		if( ult.showHighlight == true )
		{
			if( ult.buttonHighlight != null && ult.buttonHighlight.gameObject.activeInHierarchy == false )
				ult.buttonHighlight.gameObject.SetActive( true );
			
			ult.UpdateHighlight();
		}
		else
		{
			if( ult.buttonHighlight != null && ult.buttonHighlight.gameObject.activeInHierarchy == true )
				ult.buttonHighlight.gameObject.SetActive( false );
		}
	}
Пример #12
0
    void StoreReferences()
    {
        UltimateButton targ = ( UltimateButton )target;

        /* -----< ASSIGNED VARIABLES >----- */
        sizeFolder      = serializedObject.FindProperty("sizeFolder");
        buttonBase      = serializedObject.FindProperty("buttonBase");
        buttonHighlight = serializedObject.FindProperty("buttonHighlight");
        tensionAccent   = serializedObject.FindProperty("tensionAccent");
        buttonAnimator  = serializedObject.FindProperty("buttonAnimator");
        /* ---< END ASSIGNED VARIABLES >--- */

        /* -----< SIZE AND PLACEMENT >----- */
        positioning = serializedObject.FindProperty("positioning");

        scalingAxis     = serializedObject.FindProperty("scalingAxis");
        anchor          = serializedObject.FindProperty("anchor");
        touchSize       = serializedObject.FindProperty("touchSize");
        buttonSize      = serializedObject.FindProperty("buttonSize");
        customSpacing_X = serializedObject.FindProperty("customSpacing_X");
        customSpacing_Y = serializedObject.FindProperty("customSpacing_Y");

        joystick         = serializedObject.FindProperty("joystick");
        rectTrans        = serializedObject.FindProperty("rectTrans");
        targetButtonBase = serializedObject.FindProperty("targetButtonBase");
        anchorSide       = serializedObject.FindProperty("anchorSide");
        /* ---< END SIZE AND PLACEMENT >--- */

        /* -----< STYLES AND OPTIONS >----- */
        imageStyle       = serializedObject.FindProperty("imageStyle");
        inputRange       = serializedObject.FindProperty("inputRange");
        trackInput       = serializedObject.FindProperty("trackInput");
        transmitInput    = serializedObject.FindProperty("transmitInput");
        receiver         = serializedObject.FindProperty("receiver");
        tapCountOption   = serializedObject.FindProperty("tapCountOption");
        tapCountDuration = serializedObject.FindProperty("tapCountDuration");
        targetTapCount   = serializedObject.FindProperty("targetTapCount");

        baseColor              = serializedObject.FindProperty("baseColor");
        showHighlight          = serializedObject.FindProperty("showHighlight");
        highlightColor         = serializedObject.FindProperty("highlightColor");
        showTension            = serializedObject.FindProperty("showTension");
        tensionColorNone       = serializedObject.FindProperty("tensionColorNone");
        tensionColorFull       = serializedObject.FindProperty("tensionColorFull");
        tensionFadeInDuration  = serializedObject.FindProperty("tensionFadeInDuration");
        tensionFadeOutDuration = serializedObject.FindProperty("tensionFadeOutDuration");
        useAnimation           = serializedObject.FindProperty("useAnimation");
        useFade         = serializedObject.FindProperty("useFade");
        fadeUntouched   = serializedObject.FindProperty("fadeUntouched");
        fadeTouched     = serializedObject.FindProperty("fadeTouched");
        fadeInDuration  = serializedObject.FindProperty("fadeInDuration");
        fadeOutDuration = serializedObject.FindProperty("fadeOutDuration");
        /* ---< END STYLES AND OPTIONS >--- */

        /* ------< SCRIPT REFERENCE >------ */
        buttonName = serializedObject.FindProperty("buttonName");
        /* ----< END SCRIPT REFERENCE >---- */

        /* ------< BUTTON EVENTS >------ */
        onButtonDown  = serializedObject.FindProperty("onButtonDown");
        onButtonUp    = serializedObject.FindProperty("onButtonUp");
        tapCountEvent = serializedObject.FindProperty("tapCountEvent");
        /* ----< END BUTTON EVENTS >---- */

        /* // ---< ANIMATED BOOLEANS >--- \\ */
        SizeAndPlacement        = new AnimBool(EditorPrefs.GetBool("UUI_SizeAndPlacement"));
        StyleAndOptions         = new AnimBool(EditorPrefs.GetBool("UUI_StyleAndOptions"));
        ScriptReference         = new AnimBool(EditorPrefs.GetBool("UUI_ScriptReference"));
        highlightOption         = new AnimBool(targ.showHighlight);
        tensionOption           = new AnimBool(targ.showTension);
        animationOption         = new AnimBool(targ.useAnimation);
        fadeOption              = new AnimBool(targ.useFade);
        tapOption               = new AnimBool(targ.tapCountOption != UltimateButton.TapCountOption.NoCount ? true : false);
        buttonNameAssigned      = new AnimBool(targ.buttonName == string.Empty ? false : true);
        buttonNameUnassigned    = new AnimBool(targ.buttonName != string.Empty ? false : true);
        ButtonEvents            = new AnimBool(EditorPrefs.GetBool("UUI_ExtraOption_01"));
        TouchSizeDefaultOptions = new AnimBool(targ.touchSize == UltimateButton.TouchSize.Default ? true : false);
        /* // ---< END ANIMATED BOOLEANS >--- \\ */

        SetHighlight(targ);
        SetAnimation(targ);
        SetTensionAccent(targ);

        if (!targ.GetComponent <CanvasGroup>())
        {
            targ.gameObject.AddComponent <CanvasGroup>();
        }
        if (targ.useFade == true)
        {
            targ.gameObject.GetComponent <CanvasGroup>().alpha = targ.fadeUntouched;
        }
        else
        {
            targ.gameObject.GetComponent <CanvasGroup>().alpha = 1.0f;
        }
    }
Пример #13
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.Space();

        #region CANVAS ERRORS
        /* ///// ---------------------------------------- < CANVAS ERRORS > ---------------------------------------- \\\\\ */
        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 Button to function correctly.", MessageType.Error);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Update Canvas", EditorStyles.miniButtonLeft))
                {
                    parentCanvas.renderMode = RenderMode.ScreenSpaceOverlay;
                    parentCanvas            = GetParentCanvas();
                }
                if (GUILayout.Button("Update Button", EditorStyles.miniButtonRight))
                {
                    UltimateButtonCreator.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 Button to function correctly.", MessageType.Error);
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Update Canvas", EditorStyles.miniButtonLeft))
                    {
                        parentCanvas.GetComponent <CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize;
                        parentCanvas = GetParentCanvas();
                        UltimateButton button = ( UltimateButton )target;
                        button.UpdatePositioning();
                    }
                    if (GUILayout.Button("Update Button", EditorStyles.miniButtonRight))
                    {
                        UltimateButtonCreator.RequestCanvas(Selection.activeGameObject);
                        parentCanvas = GetParentCanvas();
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();
                }
            }
            return;
        }
        /* \\\\\ -------------------------------------- < END CANVAS ERRORS > -------------------------------------- ///// */
        #endregion

        UltimateButton targ = ( UltimateButton )target;

        #region SIZE AND PLACEMENT
        /* ///// ---------------------------------------- < SIZE AND PLACEMENT > ---------------------------------------- \\\\\ */
        DisplayHeader("Size and Placement", "UUI_SizeAndPlacement", SizeAndPlacement);

        if (EditorGUILayout.BeginFadeGroup(SizeAndPlacement.faded))
        {
            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(positioning);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }

            if (targ.positioning == UltimateButton.Positioning.ScreenSpace)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(sizeFolder, new GUIContent("Button Size Folder"));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.BeginChangeCheck();
                {
                    EditorGUILayout.PropertyField(scalingAxis);
                    EditorGUILayout.PropertyField(anchor);
                    EditorGUILayout.PropertyField(touchSize, new GUIContent("Touch Size", "The size of the area in which the touch can start"));
                    EditorGUILayout.Slider(buttonSize, 0.0f, 5.0f, new GUIContent("Button Size"));
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                    TouchSizeDefaultOptions.target = targ.touchSize == UltimateButton.TouchSize.Default ? true : false;
                }

                EditorGUILayout.BeginVertical("Box");
                {
                    EditorGUILayout.LabelField("Button Position");
                    EditorGUI.indentLevel = 1;
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUILayout.Slider(customSpacing_X, 0.0f, 50.0f, new GUIContent("X Position:"));
                            EditorGUILayout.Slider(customSpacing_Y, 0.0f, 100.0f, new GUIContent("Y Position:"));
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            serializedObject.ApplyModifiedProperties();
                        }
                    }
                    EditorGUI.indentLevel = 0;
                }
                EditorGUILayout.EndVertical();
            }
            else if (targ.positioning == UltimateButton.Positioning.RelativeToJoystick)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(joystick);
                EditorGUILayout.PropertyField(sizeFolder, new GUIContent("Button Size Folder"));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.BeginChangeCheck();
                {
                    EditorGUILayout.PropertyField(anchorSide);
                    EditorGUILayout.PropertyField(touchSize, new GUIContent("Touch Size", "The size of the area in which the touch can start"));
                    EditorGUILayout.Slider(buttonSize, 0.0f, 5.0f, new GUIContent("Button Size"));
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                    TouchSizeDefaultOptions.target = targ.touchSize == UltimateButton.TouchSize.Default ? true : false;
                }

                EditorGUILayout.BeginVertical("Box");
                {
                    EditorGUILayout.LabelField("Button Position");
                    EditorGUI.indentLevel = 1;
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUILayout.Slider(customSpacing_X, 0.0f, 100.0f, new GUIContent("X Position:"));
                            EditorGUILayout.Slider(customSpacing_Y, 0.0f, 100.0f, new GUIContent("Y Position:"));
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            serializedObject.ApplyModifiedProperties();
                        }
                    }
                    EditorGUI.indentLevel = 0;
                }
                EditorGUILayout.EndVertical();
            }
            else if (targ.positioning == UltimateButton.Positioning.RelativeToButton)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(rectTrans, new GUIContent("Target Size Folder"));
                EditorGUILayout.PropertyField(targetButtonBase, new GUIContent("Target Button Base Image"));
                EditorGUILayout.PropertyField(sizeFolder, new GUIContent("This Button Size Folder"));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.BeginChangeCheck();
                {
                    EditorGUILayout.PropertyField(anchorSide);
                    EditorGUILayout.PropertyField(touchSize, new GUIContent("Touch Size", "The size of the area in which the touch can start"));
                    EditorGUILayout.Slider(buttonSize, 0.0f, 5.0f, new GUIContent("Button Size"));
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                    TouchSizeDefaultOptions.target = targ.touchSize == UltimateButton.TouchSize.Default ? true : false;
                }

                EditorGUILayout.BeginVertical("Box");
                {
                    EditorGUILayout.LabelField("Button Position");
                    EditorGUI.indentLevel = 1;
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUILayout.Slider(customSpacing_X, -200.0f, 200.0f, new GUIContent("X Position:"));
                            EditorGUILayout.Slider(customSpacing_Y, -200.0f, 200.0f, new GUIContent("Y Position:"));
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            serializedObject.ApplyModifiedProperties();
                        }
                    }
                    EditorGUI.indentLevel = 0;
                }
                EditorGUILayout.EndVertical();
            }
        }
        EditorGUILayout.EndFadeGroup();
        /* \\\\\ -------------------------------------- < END SIZE AND PLACEMENT > -------------------------------------- ///// */
        #endregion

        EditorGUILayout.Space();

        #region STYLE AND OPTIONS
        /* ///// ---------------------------------------- < STYLES AND OPTIONS > ---------------------------------------- \\\\\ */
        DisplayHeader("Style and Options", "UUI_StyleAndOptions", StyleAndOptions);
        if (EditorGUILayout.BeginFadeGroup(StyleAndOptions.faded))
        {
            EditorGUILayout.Space();

            if (EditorGUILayout.BeginFadeGroup(TouchSizeDefaultOptions.faded))
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(imageStyle, new GUIContent("Image Style", "Determines whether the input range should be circular or square. This option affects how the Input Range and Track Input options function."));
                EditorGUILayout.Slider(inputRange, 0.0f, 1.0f, new GUIContent("Input Range", "The range that the Ultimate Button will react to when initiating and dragging the input."));
                EditorGUILayout.PropertyField(trackInput, new GUIContent("Track Input", "Enabling this option will allow the Ultimate Button to track the users input to ensure that button events and states are only called when the input is within the Input Range."));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            }
            if (StyleAndOptions.faded == 1.0f)
            {
                EditorGUILayout.EndFadeGroup();
            }

            // TRANSMIT INPUT //
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(transmitInput, new GUIContent("Transmit Input", "Should the Ultimate Button transmit input events to another UI game object?"));
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                TransmitInputEnabled.target = targ.transmitInput;
            }

            if (EditorGUILayout.BeginFadeGroup(TransmitInputEnabled.faded))
            {
                EditorGUI.indentLevel = 1;

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(receiver, new GUIContent("Input Receiver"));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.indentLevel = 0;
                EditorGUILayout.Space();
            }
            if (StyleAndOptions.faded == 1.0f)
            {
                EditorGUILayout.EndFadeGroup();
            }

            // TAP COUNT OPTIONS //
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(tapCountOption);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                tapOption.target = targ.tapCountOption != UltimateButton.TapCountOption.NoCount ? true : false;
            }
            if (EditorGUILayout.BeginFadeGroup(tapOption.faded))
            {
                EditorGUI.indentLevel = 1;
                EditorGUI.BeginChangeCheck();
                {
                    EditorGUILayout.Slider(tapCountDuration, 0.0f, 1.0f, new GUIContent("Tap Time Window"));
                    EditorGUI.BeginDisabledGroup(targ.tapCountOption != UltimateButton.TapCountOption.Accumulate);
                    EditorGUILayout.IntSlider(targetTapCount, 1, 5, new GUIContent("Target Tap Count"));
                    EditorGUI.EndDisabledGroup();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.indentLevel = 0;

                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Example Code"))
                {
                    ScriptReference.target = true;
                    EditorPrefs.SetBool("UUI_ScriptReference", true);
                    scriptCast = ScriptCast.GetTapCount;
                }
                if (GUILayout.Button("Button Events"))
                {
                    ButtonEvents.target = true;
                    EditorPrefs.SetBool("UUI_ExtraOption_01", true);
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }
            if (StyleAndOptions.faded == 1)
            {
                EditorGUILayout.EndFadeGroup();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(8);
            EditorGUILayout.LabelField("───────");
            EditorGUILayout.EndHorizontal();

            // BASE COLOR //
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(buttonBase);
            EditorGUILayout.PropertyField(baseColor);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                targ.UpdateBaseColor(targ.baseColor);
                if (targ.buttonBase != null)
                {
                    EditorUtility.SetDirty(targ.buttonBase);
                }
            }
            if (targ.buttonBase == null)
            {
                EditorGUI.indentLevel = 1;
                EditorGUILayout.HelpBox("The Button Base image has not been assigned. Please make sure to assign this variable within the Assigned Variables section.", MessageType.Warning);
                EditorGUI.indentLevel = 0;
                EditorGUILayout.Space();
            }

            // --------------------------< HIGHLIGHT >-------------------------- //
            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);
                highlightOption.target = targ.showHighlight;
                if (targ.buttonHighlight != null)
                {
                    EditorUtility.SetDirty(targ.buttonHighlight);
                }
            }
            EditorGUI.indentLevel = 1;
            if (EditorGUILayout.BeginFadeGroup(highlightOption.faded))
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(buttonHighlight, new GUIContent("Button Highlight"));
                EditorGUILayout.PropertyField(highlightColor);
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                    targ.UpdateHighlightColor(targ.highlightColor);
                    if (targ.buttonHighlight != null)
                    {
                        EditorUtility.SetDirty(targ.buttonHighlight);
                    }
                }
                EditorGUILayout.Space();
            }
            if (StyleAndOptions.faded == 1)
            {
                EditorGUILayout.EndFadeGroup();
            }

            EditorGUI.indentLevel = 0;
            // ------------------------< END HIGHLIGHT >------------------------ //

            // ---------------------------< TENSION >--------------------------- //
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(showTension, new GUIContent("Show Tension", "Displays the visual state of the button using the tension color options."));
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                SetTensionAccent(targ);
                tensionOption.target = targ.showTension;
                if (targ.tensionAccent != null)
                {
                    EditorUtility.SetDirty(targ.tensionAccent);
                }
            }

            EditorGUI.indentLevel = 1;

            if (EditorGUILayout.BeginFadeGroup(tensionOption.faded))
            {
                EditorGUI.BeginChangeCheck();
                {
                    EditorGUILayout.PropertyField(tensionAccent);
                    EditorGUILayout.PropertyField(tensionColorNone, new GUIContent("Tension None", "The Color of the Tension with no input."));
                    EditorGUILayout.PropertyField(tensionColorFull, new GUIContent("Tension Full", "The Color of the Tension when there is input."));
                    EditorGUILayout.PropertyField(tensionFadeInDuration, new GUIContent("Fade In Duration", "Time is seconds for the tension to fade in, with 0 being instant."));
                    EditorGUILayout.PropertyField(tensionFadeOutDuration, new GUIContent("Fade Out Duration", "Time is seconds for the tension to fade out, with 0 being instant."));
                }
                if (EditorGUI.EndChangeCheck())
                {
                    if (tensionFadeInDuration.floatValue < 0)
                    {
                        tensionFadeInDuration.floatValue = 0;
                    }
                    if (tensionFadeOutDuration.floatValue < 0)
                    {
                        tensionFadeOutDuration.floatValue = 0;
                    }

                    serializedObject.ApplyModifiedProperties();
                    if (targ.tensionAccent != null)
                    {
                        targ.tensionAccent.color = targ.tensionColorNone;
                        EditorUtility.SetDirty(targ.tensionAccent);
                    }
                }
                if (EditorGUILayout.BeginFadeGroup(TensionAccentError.faded))
                {
                    EditorGUILayout.HelpBox("The Tension Accent image has not been assigned. Please make sure to assign this immediately.", MessageType.Error);
                }
                if (StyleAndOptions.faded == 1.0f && tensionOption.faded == 1.0f)
                {
                    EditorGUILayout.EndFadeGroup();
                }

                EditorGUILayout.Space();
            }
            if (StyleAndOptions.faded == 1)
            {
                EditorGUILayout.EndFadeGroup();
            }

            EditorGUI.indentLevel = 0;
            // -------------------------< END TENSION >------------------------- //

            // USE ANIMATION OPTIONS //
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(useAnimation);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                SetAnimation(targ);
                animationOption.target = targ.useAnimation;
            }
            if (EditorGUILayout.BeginFadeGroup(animationOption.faded))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(buttonAnimator, new GUIContent("Animator"));
                EditorGUI.indentLevel--;
            }
            if (StyleAndOptions.faded == 1)
            {
                EditorGUILayout.EndFadeGroup();
            }

            // USE FADE OPTIONS //
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(useFade);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                fadeOption.target = targ.useFade;

                if (!targ.GetComponent <CanvasGroup>())
                {
                    targ.gameObject.AddComponent <CanvasGroup>();
                }

                if (targ.useFade == true)
                {
                    targ.gameObject.GetComponent <CanvasGroup>().alpha = targ.fadeUntouched;
                }
                else
                {
                    targ.gameObject.GetComponent <CanvasGroup>().alpha = 1.0f;
                }
            }
            if (EditorGUILayout.BeginFadeGroup(fadeOption.faded))
            {
                EditorGUI.indentLevel = 1;
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUILayout.Slider(fadeUntouched, 0.0f, 1.0f, new GUIContent("Fade Untouched", "This controls the alpha of the button when it is NOT receiving any input."));
                        EditorGUILayout.Slider(fadeTouched, 0.0f, 1.0f, new GUIContent("Fade Touched", "This controls the alpha of the button when it is receiving input."));
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedObject.ApplyModifiedProperties();

                        if (!targ.GetComponent <CanvasGroup>())
                        {
                            targ.gameObject.AddComponent <CanvasGroup>();
                        }

                        if (targ.useFade == true)
                        {
                            targ.gameObject.GetComponent <CanvasGroup>().alpha = targ.fadeUntouched;
                        }
                        else
                        {
                            targ.gameObject.GetComponent <CanvasGroup>().alpha = 1.0f;
                        }
                    }
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUILayout.PropertyField(fadeInDuration, new GUIContent("Fade In Duration", "Time is seconds for the button to fade in, with 0 being instant."));
                        EditorGUILayout.PropertyField(fadeOutDuration, new GUIContent("Fade Out Duration", "Time is seconds for the button to fade out, with 0 being instant."));
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (fadeInDuration.floatValue < 0)
                        {
                            fadeInDuration.floatValue = 0;
                        }
                        if (fadeOutDuration.floatValue < 0)
                        {
                            fadeOutDuration.floatValue = 0;
                        }

                        serializedObject.ApplyModifiedProperties();
                    }
                }
                EditorGUI.indentLevel = 0;
                EditorGUILayout.Space();
            }
            if (StyleAndOptions.faded == 1)
            {
                EditorGUILayout.EndFadeGroup();
            }
        }
        EditorGUILayout.EndFadeGroup();
        /* \\\\\ -------------------------------------- < END STYLES AND OPTIONS > -------------------------------------- ///// */
        #endregion

        EditorGUILayout.Space();

        #region SCRIPT REFERENCE
        /* \\\\\ ----------------------------------------- < SCRIPT REFERENCE > ----------------------------------------- ///// */
        DisplayHeader("Script Reference", "UUI_ScriptReference", ScriptReference);
        if (EditorGUILayout.BeginFadeGroup(ScriptReference.faded))
        {
            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(buttonName);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                buttonNameAssigned.target   = targ.buttonName == string.Empty ? false : true;
                buttonNameUnassigned.target = targ.buttonName != string.Empty ? false : true;
            }

            if (EditorGUILayout.BeginFadeGroup(buttonNameUnassigned.faded))
            {
                EditorGUILayout.HelpBox("Please assign a Button Name in order to be able to get this button's states dynamically.", MessageType.Warning);
            }
            if (ScriptReference.faded == 1.0f)
            {
                EditorGUILayout.EndFadeGroup();
            }

            if (EditorGUILayout.BeginFadeGroup(buttonNameAssigned.faded))
            {
                EditorGUILayout.BeginVertical("Box");
                EditorGUILayout.LabelField("Example Code:", EditorStyles.boldLabel);
                EditorGUILayout.LabelField("Please select the function you would like to copy and paste into your script.", EditorStyles.wordWrappedLabel);
                scriptCast = ( ScriptCast )EditorGUILayout.EnumPopup(scriptCast);
                GUILayout.Space(5);
                switch (scriptCast)
                {
                case ScriptCast.GetButtonDown:
                {
                    EditorGUILayout.TextField("if( UltimateButton.GetButtonDown( \"" + targ.buttonName + "\" ) )");
                }
                break;

                case ScriptCast.GetButtonUp:
                {
                    EditorGUILayout.TextField("if( UltimateButton.GetButtonUp( \"" + targ.buttonName + "\" ) )");
                }
                break;

                case ScriptCast.GetButton:
                default:
                {
                    EditorGUILayout.TextField("if( UltimateButton.GetButton( \"" + targ.buttonName + "\" ) )");
                }
                break;

                case ScriptCast.GetTapCount:
                {
                    EditorGUILayout.TextField("if( UltimateButton.GetTapCount( \"" + targ.buttonName + "\" ) )");

                    if (targ.tapCountOption == UltimateButton.TapCountOption.NoCount)
                    {
                        EditorGUILayout.HelpBox("Tap Count is not being used. Please set the Tap Count Option in order to use this option.", MessageType.Warning);
                    }
                }
                break;

                case ScriptCast.GetUltimateButton:
                {
                    EditorGUILayout.TextField("UltimateButton.GetUltimateButton( \"" + targ.buttonName + "\" )");
                }
                break;

                case ScriptCast.DisableButton:
                {
                    EditorGUILayout.TextField("UltimateButton.DisableButton( \"" + targ.buttonName + "\" );");
                }
                break;

                case ScriptCast.EnableButton:
                {
                    EditorGUILayout.TextField("UltimateButton.EnableButton( \"" + targ.buttonName + "\" );");
                }
                break;
                }
                GUILayout.Space(1);
                EditorGUILayout.EndVertical();

                if (GUILayout.Button("Open Documentation"))
                {
                    UltimateButtonWindow.OpenDocumentation();
                }
            }
            if (ScriptReference.faded == 1.0f)
            {
                EditorGUILayout.EndFadeGroup();
            }
        }
        EditorGUILayout.EndFadeGroup();
        /* ///// --------------------------------------- < END SCRIPT REFERENCE > --------------------------------------- \\\\\ */
        #endregion

        EditorGUILayout.Space();

        #region BUTTON EVENTS
        /* \\\\\ ----------------------------------------- < SCRIPT REFERENCE > ----------------------------------------- ///// */
        DisplayHeader("Button Events", "UUI_ExtraOption_01", ButtonEvents);
        if (EditorGUILayout.BeginFadeGroup(ButtonEvents.faded))
        {
            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(onButtonDown);
            EditorGUILayout.PropertyField(onButtonUp);

            if (EditorGUILayout.BeginFadeGroup(tapOption.faded))
            {
                EditorGUILayout.PropertyField(tapCountEvent);
            }
            if (ButtonEvents.faded == 1.0f)
            {
                EditorGUILayout.EndFadeGroup();
            }

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
        EditorGUILayout.EndFadeGroup();
        /* ///// --------------------------------------- < END SCRIPT REFERENCE > --------------------------------------- \\\\\ */
        #endregion

        EditorGUILayout.Space();

        if (PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.Prefab)
        {
            GUISkin defaultSkin     = GUI.skin;
            int     defaultFontSize = defaultSkin.FindStyle("Button").fontSize;
            defaultSkin.FindStyle("Button").fontSize = 12;
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Add to Scene", GUILayout.Height(25), GUILayout.Width(200)))
            {
                UltimateButtonCreator.CreateNewUltimateButton(targ.gameObject);
            }
            GUILayout.FlexibleSpace();
            GUILayout.Space(10);
            EditorGUILayout.EndHorizontal();
            defaultSkin.FindStyle("Button").fontSize = defaultFontSize;
        }

        Repaint();
    }
Пример #14
0
    void FixedUpdate()
    {
        // Determine if the truck is grounded or not by using a Line cast.
        isGrounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Default"));

        // If the gas button is down...
        if (UltimateButton.GetButton("Gas"))
        {
            // If the motor speed is less than the max speed, then accelerate.
            if (wheelMotor.motorSpeed > -maxSpeed)
            {
                wheelMotor.motorSpeed -= Time.deltaTime * accelerationSpeed;
            }

            // If the truck is grounded, then add force to help the truck have more power.
            if (isGrounded == true)
            {
                myRigidbody.AddForceAtPosition(new Vector2(20, 0), new Vector2(transform.position.x, transform.position.y - 1));
            }
        }
        else
        {
            // If the reverse button is down and the motor is not going at all...
            if (UltimateButton.GetButton("Reverse") && wheelMotor.motorSpeed >= 0)
            {
                // Then set the motor speed.
                if (wheelMotor.motorSpeed != reverseSpeed)
                {
                    wheelMotor.motorSpeed = reverseSpeed;
                }

                // If the truck is grounded, then add force to help give more power.
                if (isGrounded == true)
                {
                    myRigidbody.AddForceAtPosition(new Vector2(-10, 0), new Vector2(transform.position.x, transform.position.y - 1));
                }
            }
            else
            {
                // If the motor is running, then decelerate the truck.
                if (wheelMotor.motorSpeed < 0)
                {
                    wheelMotor.motorSpeed += Time.deltaTime * decelerationSpeed;
                }
                // Else if the motor speed is not stopped correctly and the truck is not in reverse, then set the motor speed to 0.
                else if (wheelMotor.motorSpeed > 0 && !UltimateButton.GetButton("Reverse"))
                {
                    wheelMotor.motorSpeed = 0;
                }

                // If the truck is grounded, the wheel speed is nearly stopped, and the truck is still moving, then add force to slow the truck down.
                if (isGrounded == true && wheelMotor.motorSpeed > -100 && myRigidbody.velocity.x > 2)
                {
                    myRigidbody.AddForceAtPosition(new Vector2(-30, 0), new Vector2(transform.position.x, transform.position.y - 1));
                }
            }
        }

        // Apply the motor force.
        rearWheel.motor  = wheelMotor;
        frontWheel.motor = wheelMotor;

        // Make the camera follow the truck.
        cameraTransform.position = transform.position + cameraDefaultPosition;

        // If the truck is not grouned and the truck is not moving, and the truck is not in the middle of resetting...
        if (isGrounded == false && myRigidbody.velocity.magnitude <= 0.5f && isResetting == false)
        {
            // Reduce the reset timer.
            resetTimer -= Time.deltaTime;

            // If the timer is less than zero, then reset the timer and start the ResetTruck coroutine.
            if (resetTimer <= 0)
            {
                resetTimer = resetTimerMax;
                StartCoroutine("ResetTruck");
            }
        }
        // Else if the truck is grounded and the timer isn't at max, then reset the timer to max.
        else if (isGrounded == true && resetTimer != resetTimerMax)
        {
            resetTimer = resetTimerMax;
        }
    }
Пример #15
0
    }                                   //Start() -end

    void Update()
    {
#if UNITY_STANDALONE     // Build for all Windows, Mac or Linux Standalone platforms (Input controls)
        // TODO: Add comments to whole section

        // Player movement
        if (Input.GetKey(KeyCode.LeftArrow))         //Move Left?
        {
            transform.position += Vector3.left * speed * Time.deltaTime;
        }
        else if (Input.GetKey(KeyCode.RightArrow))     //Move RIght?
        {
            transform.position += Vector3.right * speed * Time.deltaTime;
        }

        // Restrict the player to the gamespace
        float newX = Mathf.Clamp(transform.position.x, xmin, xmax);
        transform.position = new Vector3(newX, transform.position.y, transform.position.z);

        // Player movement -end



        // Projectile
        if (Input.GetKeyDown(KeyCode.Space))
        {
            InvokeRepeating("Fire", 0.0001f, firingRate);
        }

        // Projectile -end
#else   // Build for all touch platforms (Input controls)
        //Player movement
        float shipMovement = UltimateJoystick.GetHorizontalAxis("PlayerJoystick");
        transform.position += Vector3.left * speed * Time.deltaTime * -shipMovement;

        // Restrict the player to the gamespace
        float newX = Mathf.Clamp(transform.position.x, xmin, xmax);
        transform.position = new Vector3(newX, transform.position.y, transform.position.z);

        //Player movement -end


        //Projectile
        if (UltimateButton.GetButtonDown("PlayerFire"))
        {
            InvokeRepeating("Fire", 0.000001f, firingRate);
            Debug.Log("Fire Pressed");
        }

        if (UltimateButton.GetButtonUp("PlayerFire"))
        {
            Debug.Log("Fire Released");
            CancelInvoke("Fire");
        }//Projectile -end
#endif
        /* -----< GENERAL Update() >----- */

        Orbit(); // Show shield satellites


        /* -----< GENERAL Update -END() >----- */
    }     // void Update -end