void Start() { wandPosition = new Vector3[2]; wandRotation = new Quaternion[2]; setDefaultPositions(); canoe = GameObject.Find("CC_CANOE").GetComponent <CC_CANOE>(); if (canoe.isVive()) { yaw_pitchKey = KeyCode.T; rollKey = KeyCode.O; left_right_up_downKey = KeyCode.V; left_right_in_outKey = KeyCode.Comma; if (CC_CONFIG.IsDestiny()) { addViveClusterInputs(); } } else if (canoe.isOptiTrack() && CC_CONFIG.IsDestiny()) { addOptiTrackClusterInputs(); } }
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 }
/// <summary> /// Obtain tracker information. /// </summary> private void getTrackerInformation() { if (CC_CONFIG.IsDestiny()) { Vector3 position = new Vector3(0, 0, 0); Quaternion rotation = Quaternion.identity; if (canoe.isVive()) { //Update head ClusterInput entry position = ClusterInput.GetTrackerPosition("head"); rotation = ClusterInput.GetTrackerRotation("head"); //Angle puck so flat section is bottom //Change "Camera Forward Tilt" in editor to change tilt if hat/helmet is angled rotation *= Quaternion.AngleAxis(90 - canoe.cameraForwardTilt, Vector3.left); rotation *= Quaternion.AngleAxis(180, Vector3.up); convertHeadTracking(position, rotation); //Update left controller ClusterInput entries position = ClusterInput.GetTrackerPosition("leftWand"); rotation = ClusterInput.GetTrackerRotation("leftWand"); convertWandTracking(Wand.Left, position, rotation); //Update right controller ClusterInput entries position = ClusterInput.GetTrackerPosition("rightWand"); rotation = ClusterInput.GetTrackerRotation("rightWand"); convertWandTracking(Wand.Right, position, rotation); //Moving the Character Controller with the head movement float same = CC_CANOE.CanoeCharacterController().center.y; CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z); } else if (canoe.isOptiTrack()) { //Head position and rotation position = ClusterInput.GetTrackerPosition("head"); //position = new Vector3(position.x, position.y, -position.z); rotation = ClusterInput.GetTrackerRotation("head"); convertHeadTracking(position, rotation); //Left wand position and rotation position = ClusterInput.GetTrackerPosition("leftWand"); rotation = ClusterInput.GetTrackerRotation("leftWand"); convertWandTracking(Wand.Left, position, rotation); //Right wand position and rotation position = ClusterInput.GetTrackerPosition("rightWand"); rotation = ClusterInput.GetTrackerRotation("rightWand"); convertWandTracking(Wand.Right, position, rotation); //Moving the Character Controller with the head movement float same = CC_CANOE.CanoeCharacterController().center.y; CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z); } } else { if (CC_CONFIG.IsInnovator()) { //if (checkInnovatorTracking()) { headPosition = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_HEAD@" + CC_CONFIG.innovatorIP, 0)); headRotation = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_HEAD@" + CC_CONFIG.innovatorIP, 0) * Quaternion.AngleAxis(90 - canoe.cameraForwardTilt, Vector3.left) * Quaternion.AngleAxis(180, Vector3.up)); //Moving the Character Controller with the head movement float same = CC_CANOE.CanoeCharacterController().center.y; CC_CANOE.CanoeCharacterController().center = new Vector3(headPosition.x, same, headPosition.z); //Wands rotation and position. wandPosition[0] = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_WAND0@" + CC_CONFIG.innovatorIP, 0)); wandPosition[1] = convertToLeftHandPosition(VRPN.vrpnTrackerPos("CC_FLAT_WAND1@" + CC_CONFIG.innovatorIP, 0)); wandRotation[0] = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_WAND0@" + CC_CONFIG.innovatorIP, 0)); wandRotation[1] = convertToLeftHandRotation(VRPN.vrpnTrackerQuat("CC_FLAT_WAND1@" + CC_CONFIG.innovatorIP, 0)); } else { setDefaultPositions(); } } }
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 }