/// <summary> /// Verify if all controllers are registered if not register the controller. /// </summary> /// <param name="plat"></param> private bool RegisterControllers() { // Registering controllers.. GenericControllerPlatform plat = (GenericControllerPlatform)(coreSettings.CurrentPlatform); if (plat != null) { GameObject[] controls; controls = plat.GetControllerObject(); if (registeredControllers.Count != controls.Length) { registeredControllers.Clear(); for (int i = 0; i < controls.Length; i++) { if (RegisterControllerGameObject(controls[i])) { registeredControllers.Add(true); } } } if (registeredControllers.Count != controls.Length) { return(false); } else { return(true); } } else { Debug.Log("Not a controller platform."); return(false); } }
/// <summary> /// Returns the attach point on the specified controller. /// </summary> /// <param name="isRight">True if the controller is on the right hand.</param> /// <returns></returns> public GameObject GetControllerAttachPosition(bool isRight) { // Registering controllers.. GenericControllerPlatform platform = (GenericControllerPlatform)(coreSettings.CurrentPlatform); if (platform != null) { return(platform.GetControllerAttachPoint(isRight)); } else { Debug.LogError("This platform doesn't support controllers."); return(null); } }
/// <summary> /// This happens when the user realeases the button. /// </summary> public void Teleport() { #region Initialization Stuff maybe shouldn't be here SetUpFadePlane(); if (platform == null) { platform = (GenericControllerPlatform)coreSettings.CurrentPlatform; } #endregion // If the user has decided to teleport (ie lets go of touchpad) then remove all visual indicators // related to selecting things and actually teleport // If the user has decided to cancel (ie squeezes grip button) then remove visual indicators and do nothing if (Pointer.PointOnNavMesh) { // Begin teleport sequence teleporting = true; teleportTimeMarker = Time.time; // Starts the fade! CameraManager.Instance.StartFadingCamera(); } // Reset active controller, disable pointer, disable visual indicators activeController = null; Pointer.enabled = false; if (navmeshAnimator != null) { navmeshAnimator.SetBool(enabledAnimatorID, false); } Pointer.transform.parent = null; Pointer.transform.position = Vector3.zero; Pointer.transform.rotation = Quaternion.identity; Pointer.transform.localScale = Vector3.one; /* Activate laser */ Debug.Log("Teleport Requesting Laser: ON"); ControllerManager.Instance.RequestDisplayLaser(this.gameObject.GetInstanceID()); }
/// <summary> /// Register the buttons on the platform and on this feature serializeble registries. /// </summary> /// <param name="userSelectedButtons">The name of the selected buttons.</param> /// <param name="userSelectedActions">The actions of each button.</param> /// <param name="userSelectionIsRight">If each button is on the right hand side.</param> /// <param name="overrideInteraction">If each button should override interaction.</param> public void RegisterActionButtons(Button.ButtonName[] userSelectedButtons, Button.ButtonActions[] userSelectedActions, bool[] userSelectionIsRight, bool[] overrideInteraction) { // For the case of the Arc teleport we must, add a fixed HoldDown for the same button. // Adding an extra button to be used as a HoldDown Button.ButtonName[] buttonName = new Button.ButtonName[userSelectedButtons.Length * 2]; int j = 0; for (int i = 0; i < userSelectedButtons.Length; i++) { buttonName[j] = userSelectedButtons[i]; buttonName[j + 1] = userSelectedButtons[i]; j += 2; } // Making the extra button have the holddown action. Button.ButtonActions[] buttonActions = new Button.ButtonActions[userSelectedActions.Length * 2]; j = 0; for (int i = 0; i < userSelectedActions.Length; i++) { buttonActions[j] = userSelectedActions[i]; buttonActions[j + 1] = Button.ButtonActions.HoldDown; j += 2; } bool[] position = new bool[userSelectionIsRight.Length * 2]; j = 0; for (int i = 0; i < userSelectionIsRight.Length; i++) { position[j] = userSelectionIsRight[i]; position[j + 1] = userSelectionIsRight[i]; j += 2; } // Retrieve the Actions(methods) from the ArcTeleportManager. Action teleportMethod = GetTeleportMethod(); Action holdingMethod = GetHoldingButtonAction(); // Attempt to register them on the current selected platform. // Retrieve the platform. GenericControllerPlatform platform; if (coreSettings.CurrentPlatform.GetType().IsSubclassOf(typeof(GenericControllerPlatform))) { platform = (GenericControllerPlatform)coreSettings.CurrentPlatform; } else { Debug.LogError("Platform doesn't support controllers. ArcTeleport require controls to work."); return; } // Foreach button register it on the platform. for (int i = 0; i < buttonName.Length; i++) { // Register feature method. Register the teleport method to PushUp events and the selection method to HoldDown events. if (buttonActions[i] == Button.ButtonActions.HoldDown) { /* Registering the method (On the Platform Controller). */ platform.GetPlatformControls().AddButton(buttonName[i], buttonActions[i], position[i], holdingMethod, false, GetFeatureType()); // Saving a reference to the button on the settings to be serialized. SaveButtonChoice(buttonName[i], buttonActions[i], false, position[i]); } else if (buttonActions[i] == Button.ButtonActions.PressUp) { /* Registering the method (On the Platform Controller). */ platform.GetPlatformControls().AddButton(buttonName[i], buttonActions[i], position[i], teleportMethod, false, GetFeatureType()); // Saving a reference to the button on the settings to be serialized. SaveButtonChoice(buttonName[i], buttonActions[i], false, position[i]); } else { Debug.LogError("Something is of Arc Teleport is not set to either HoldDown or PressUp"); } } }
/// <summary> /// This happens while the user is holding down the teleport button. /// </summary> public void WhileHoldingButtonDown() { Debug.Log("Chosing where to teleport!"); Controller newController; List <ButtonRegistry> regs = TeleportSettings.ButtonsSelected; // Figuring which controller just pressed the button. for (int i = 0; i < regs.Count; i++) { // If true, we found which controller to get (the one that owns TeleportButtons[i] button). if (ControllerManager.Instance.CheckButtonInteracting(regs[i].Name, Button.ButtonActions.HoldDown, regs[i].IsRightControllerButton)) { if (regs[i].IsRightControllerButton) { newController = ControllerManager.Instance.GetRightController().GetComponent <Controller>(); } else { newController = ControllerManager.Instance.GetLeftController().GetComponent <Controller>(); } lastActiveController = activeController == newController ? lastActiveController : activeController; activeController = newController; } } // Set active controller to this controller, and enable the parabolic pointer and visual indicators // that the user can use to determine where they are able to teleport. Pointer.transform.parent = activeController.transform; Pointer.transform.localPosition = Vector3.zero; Pointer.transform.localRotation = Quaternion.identity; Pointer.transform.localScale = Vector3.one; Pointer.enabled = true; if (navmeshAnimator != null) { navmeshAnimator.SetBool(enabledAnimatorID, true); } Pointer.ForceUpdateCurrentAngle(); lastClickAngle = Pointer.CurrentParabolaAngle; if (platform == null) { platform = (GenericControllerPlatform)coreSettings.CurrentPlatform; } if (headTransform == null) { headTransform = platform.GetHeadTransform(); } // The user is still deciding where to teleport and has the touchpad held down. // Note: rendering of the parabolic pointer / marker is done in ParabolicPointer Vector3 offset = headTransform.position - centerOfPlayArea.position; offset.y = 0; // Haptic feedback click every [HaptickClickAngleStep] degrees float angleClickDiff = Pointer.CurrentParabolaAngle - lastClickAngle; if (platform.UseHapticPulse()) { if (Mathf.Abs(angleClickDiff) > TeleportSettings.HapticClickAngleStep) { lastClickAngle = Pointer.CurrentParabolaAngle; platform.TriggerHapticPulse(.5f, activeController); } } /* Deactivate Laser */ ControllerManager.Instance.RequestHideLaser(this.gameObject.GetInstanceID()); }