Example #1
0
        /// <summary>
        /// Whether the indicated wand button was released during this frame.
        /// </summary>
        /// <param name="button">The wand button to check.</param>
        /// <param name="targetWand">Unless specified, the state of the dominant-hand wand is returned.</param>
        /// <returns>Returns true if the button was released this frame.</returns>
        public static bool GetButtonUp(WandButton button, WandTarget targetWand = WandTarget.Primary)
        {
            var wandState         = currentWandStates[targetWand];
            var previousWandState = previousWandStates[targetWand];

            // Return true if the button is currently released, but was pressed on the previous frame.
            return(!wandState.GetButtonState(button) && previousWandState.GetButtonState(button));
        }
Example #2
0
    public override void OnInspectorGUI()
    {
        //Disconnect the prefab instance from the original prefab
        bool isPrefabOriginal = (PrefabUtility.GetPrefabParent(target) == null) && (PrefabUtility.GetPrefabObject(target) != null);

        if (!isPrefabOriginal)
        {
            PrefabUtility.DisconnectPrefabInstance(target);
        }

        EditorGUI.BeginChangeCheck();

        GUILayout.Space(10);
        EditorGUILayout.LabelField("Grabber Settings", EditorStyles.boldLabel);

        bool enableGrabbing = EditorGUILayout.Toggle(new GUIContent("Enable Grabbing", "Toggles grabbing using the specified wand."), grabTarget.enableGrabbing);

        //Disable grabbing if enable grabbin is false
        EditorGUI.BeginDisabledGroup(!enableGrabbing);

        bool grabWithTrigger = EditorGUILayout.Toggle(new GUIContent("Grab With Trigger", "Toggles navigation with trigger. Overrides Grab Button."), grabTarget.grabWithTrigger);

        //Disable grab button if grab with trigger is true
        EditorGUI.BeginDisabledGroup(grabWithTrigger);

        WandButton validGrabButton = grabTarget.grabButton;
        WandButton grabButton      = (WandButton)EditorGUILayout.EnumPopup(new GUIContent("Grab Button", "Select button to be used to grab."), grabTarget.grabButton);

        //End grab button disabled group
        EditorGUI.EndDisabledGroup();

        //End grabber disabled group
        EditorGUI.EndDisabledGroup();

        GUILayout.Space(20);

        EditorGUI.EndChangeCheck();

        Undo.RecordObject(grabTarget, "Updated Grabber Settings");
        canoe = GameObject.Find("CC_CANOE").GetComponent <CC_CANOE>();

        //GRABBER STARTS
        grabTarget.enableGrabbing  = enableGrabbing;
        grabTarget.grabWithTrigger = grabWithTrigger;

        string location = "CCaux_Grabber on " + grabTarget.gameObject.name + "/\"Grabber Settings\"/\"Grab Button\"";

        //Button logic to keep user from selecting incorrect input for grab button
        if (canoe.isVive() && !CC_INPUT.IsViveInput(grabButton))
        {
            if (!CC_INPUT.IsEnumSeparator(grabButton))
            {
                if (!CC_INPUT.IsViveInput(validGrabButton))
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not Vive input. Defaulting to \"Menu\" button.");
                    grabButton = grabTarget.grabButton = WandButton.Menu;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not Vive input.");
                    grabButton = grabTarget.grabButton = validGrabButton;
                }
            }
            throw new ExitGUIException();
        }
        else if (canoe.isOptiTrack() && !CC_INPUT.IsOptiTrackInput(grabButton))
        {
            if (!CC_INPUT.IsEnumSeparator(grabButton))
            {
                if (!CC_INPUT.IsOptiTrackInput(validGrabButton))
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not OptiTrack input. Defaulting to \"X\" button.");
                    grabButton = grabTarget.grabButton = WandButton.X;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + grabButton + "\" is not OptiTrack input.");
                    grabButton = grabTarget.grabButton = validGrabButton;
                }
            }
            throw new ExitGUIException();
        }
        else
        {
            grabTarget.grabButton = grabButton;
        }
        //Button logic end

        //GRABBER ENDS
    }
    public override void OnInspectorGUI()
    {
        //Get This Target
        navTarget = (CCaux_OmniNavigator)target;
        canoe     = GameObject.Find("CC_CANOE").GetComponent <CC_CANOE>();
        //Disconnect the prefab instance from the original prefab
        bool isPrefabOriginal = (PrefabUtility.GetPrefabParent(target) == null) && (PrefabUtility.GetPrefabObject(target) != null);

        if (!isPrefabOriginal)
        {
            PrefabUtility.DisconnectPrefabInstance(target);
        }

        EditorGUI.BeginChangeCheck();

        //NAVIGATION STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Navigation Settings", EditorStyles.boldLabel);
        bool enableNavigation = EditorGUILayout.Toggle(new GUIContent("Enable Navigation", "Toggle navigation using navigation input (default is trigger)."), navTarget.enableNavigation);

        //Disable navigation if enable navigation is false
        EditorGUI.BeginDisabledGroup(!enableNavigation);

        bool disableNavigationX = EditorGUILayout.Toggle(new GUIContent("Disable X-Axis Movement", "Toggle movement in the X-axis while navigating."), navTarget.disableNavigationX);
        bool disableNavigationY = EditorGUILayout.Toggle(new GUIContent("Disable Y-Axis Movement", "Toggle movement in the Y-axis while navigating."), navTarget.disableNavigationY);
        bool disableNavigationZ = EditorGUILayout.Toggle(new GUIContent("Disable Z-Axis Movement", "Toggle movement in the Z-axis while navigating."), navTarget.disableNavigationZ);

        CCaux_OmniNavigator.rotationLock lockRotation = (CCaux_OmniNavigator.rotationLock)EditorGUILayout.EnumPopup(new GUIContent("Lock Rotation Around Axis", "Select an axis to lock rotation around."), navTarget.lockRotation);
        Wand wandToUse      = (Wand)EditorGUILayout.EnumPopup(new GUIContent("Navigation Wand", "Select wand to use for navigation."), navTarget.wandToUse);
        bool navWithTrigger = EditorGUILayout.Toggle(new GUIContent("Navigate with Trigger", "Toggles navigation with trigger. Overrides Navigation Button."), navTarget.navWithTrigger);

        //Disable navigation button selection if trigger is used for navigation
        EditorGUI.BeginDisabledGroup(navWithTrigger);
        WandButton validNavButton = navTarget.navButton;
        WandButton navButton      = (WandButton)EditorGUILayout.EnumPopup(new GUIContent("Navigation Button", "Select button to use for navigation."), navTarget.navButton);

        //End navigation button disabled group
        EditorGUI.EndDisabledGroup();

        float moveSpeed   = EditorGUILayout.FloatField(new GUIContent("Movement Speed", "Set navigation movement speed."), navTarget.moveSpeed);
        float rotateSpeed = EditorGUILayout.FloatField(new GUIContent("Rotation Speed", "Set navigation rotation speed."), navTarget.rotateSpeed);

        //NAVIGATION ENDS

        //RESET STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Reset Settings", EditorStyles.boldLabel);
        WandButton validResetButton = navTarget.resetButton;
        WandButton resetButton      = (WandButton)EditorGUILayout.EnumPopup(new GUIContent("Reset Button", "Select button to reset CANOE position."), navTarget.resetButton);
        float      resetSpeed       = EditorGUILayout.FloatField(new GUIContent("Reset Speed", "Set the CANOE's speed when returning to its reset position."), navTarget.resetSpeed);
        Vector3    resetPosition    = EditorGUILayout.Vector3Field(new GUIContent("Reset Position", "Set the CANOE's reset position."), navTarget.resetPosition);
        Vector3    resetRotation    = EditorGUILayout.Vector3Field(new GUIContent("Reset Rotation", "Set the CANOE's reset rotation."), navTarget.resetRotation);

        //RESET ENDS

        //MISC STARTS
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Misc Settings", EditorStyles.boldLabel);
        GameObject cursor = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Cursor Object", "Set object to display while navigating."), navTarget.cursor, typeof(Object), true);

        //MISC ENDS

        //End navigation disabled group
        EditorGUI.EndDisabledGroup();

        GUILayout.Space(20);

        EditorGUI.EndChangeCheck();

        Undo.RecordObject(navTarget, "Updated Navigator Settings");
        canoe = GameObject.Find("CC_CANOE").GetComponent <CC_CANOE>();

        //NAVIGATION STARTS
        navTarget.enableNavigation   = enableNavigation;
        navTarget.disableNavigationX = disableNavigationX;
        navTarget.disableNavigationY = disableNavigationY;
        navTarget.disableNavigationZ = disableNavigationZ;

        navTarget.lockRotation   = lockRotation;
        navTarget.wandToUse      = wandToUse;
        navTarget.navWithTrigger = navWithTrigger;

        string location = "CCaux_OmniNavigator/\"Navigation Settings\"/\"Navigation Button\"";

        //Button logic to keep user from selecting incorrect input for navigation button
        if (canoe.isVive() && !CC_INPUT.IsViveInput(navButton))
        {
            if (!CC_INPUT.IsEnumSeparator(navButton))
            {
                if (!CC_INPUT.IsViveInput(validNavButton))
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not Vive input. Defaulting to \"Menu\" button.");
                    navButton = navTarget.navButton = WandButton.Menu;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not Vive input.");
                    navButton = navTarget.navButton = validNavButton;
                }
            }
            throw new ExitGUIException();
        }
        else if (canoe.isOptiTrack() && !CC_INPUT.IsOptiTrackInput(navButton))
        {
            if (!CC_INPUT.IsEnumSeparator(navButton))
            {
                if (!CC_INPUT.IsOptiTrackInput(validNavButton))
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not OptiTrack input. Defaulting to \"X\" button.");
                    navButton = navTarget.navButton = WandButton.X;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + navButton + "\" is not OptiTrack input.");
                    navButton = navTarget.navButton = validNavButton;
                }
            }
            throw new ExitGUIException();
        }
        else
        {
            navTarget.navButton = navButton;
        }
        //Button logic end

        navTarget.moveSpeed   = moveSpeed;
        navTarget.rotateSpeed = rotateSpeed;
        //NAVIGATION ENDS

        //RESET STARTS
        location = "CCaux_OmniNavigator/\"Reset Settings\"/\"Reset Button\"";

        //Button logic to keep user from selecting incorrect input for reset button
        if (canoe.isVive() && !CC_INPUT.IsViveInput(resetButton))
        {
            if (!CC_INPUT.IsEnumSeparator(resetButton))
            {
                if (!CC_INPUT.IsViveInput(validResetButton))
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not Vive input. Defaulting to \"Menu\" button.");
                    resetButton = navTarget.resetButton = WandButton.Menu;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not Vive input.");
                    resetButton = navTarget.resetButton = validResetButton;
                }
            }
            throw new ExitGUIException();
        }
        else if (canoe.isOptiTrack() && !CC_INPUT.IsOptiTrackInput(resetButton))
        {
            if (!CC_INPUT.IsEnumSeparator(resetButton))
            {
                if (!CC_INPUT.IsOptiTrackInput(validResetButton))
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not OptiTrack input. Defaulting to \"X\" button.");
                    resetButton = navTarget.resetButton = WandButton.X;
                }
                else
                {
                    Debug.LogError(location + ": Wand button \"" + resetButton + "\" is not OptiTrack input.");
                    resetButton = navTarget.resetButton = validResetButton;
                }
            }
            throw new ExitGUIException();
        }
        else
        {
            navTarget.resetButton = resetButton;
        }
        //Button logic end

        navTarget.resetSpeed    = resetSpeed;
        navTarget.resetPosition = resetPosition;
        navTarget.resetRotation = resetRotation;
        //RESET ENDS

        //MISC STARTS
        navTarget.cursor = cursor;
        //MISC ENDS
    }
Example #4
0
        /// <summary>
        /// Whether the indicated wand button is currently being pressed.
        /// </summary>
        /// <param name="button">The wand button to check.</param>
        /// <param name="targetWand">Unless specified, the state of the dominant-hand wand is returned.</param>
        /// <returns>Returns true if the button is being pressed.</returns>
        public static bool GetButton(WandButton button, WandTarget targetWand = WandTarget.Primary)
        {
            var wandState = currentWandStates[targetWand];

            return(wandState.GetButtonState(button));
        }
    // Update is called once per frame
    void Update()
    {
        Transform wandTransform = CC_CANOE.WandTransform(wand);
        Vector3   offset        = new Vector3(wandTransform.position.x,
                                              wandTransform.position.y + verticalOffset,
                                              wandTransform.position.z);

        float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis));

        if (angle < 0f)
        {
            angle += 2 * Mathf.PI;
        }

        angle = angle * (180f / Mathf.PI);

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            if ((angle >= 45f) && (angle <= 135f))
            {
                Debug.Log("Up object selected");
                lanternObj   = upObject;
                chosenButton = WandButton.Up;
            }
            else if ((angle >= 225f) && (angle <= 315f))
            {
                Debug.Log("Down object selected");
                lanternObj   = downObject;
                chosenButton = WandButton.Down;
            }
            else if ((angle > 135f) && (angle < 225f))
            {
                Debug.Log("Left object selected");
                lanternObj   = leftObject;
                chosenButton = WandButton.Left;
            }
            else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f)))
            {
                Debug.Log("Right object selected");
                lanternObj   = rightObject;
                chosenButton = WandButton.Right;
            }
        }

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            lanternObj.transform.localScale = Vector3.zero;
            Vector3    rotation = lanternObj.transform.eulerAngles;
            Quaternion quat     = Quaternion.identity;
            lantern = Instantiate(lanternObj, offset, quat);
            lantern.gameObject.SetActive(true);
            lantern.transform.position = offset;
        }
        else if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick))
        {
            lantern.transform.position = offset;
        }
        else if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick))
        {
            lantern.GetComponent <Rigidbody>().isKinematic = false;
            lantern.GetComponent <Rigidbody>().AddForce(new Vector3(0, releaseForce, 0));
            lantern.GetComponent <Lantern>().startExpiring = true;
        }
    }