private void Update() { Vector2 buttonPosition = TBInput.GetAxis2D(_button, _controller); Vector3 newPosition = new Vector3(buttonPosition.x * 8f, buttonPosition.y * 8f, 0f); transform.localPosition = newPosition; }
protected virtual void Initialize() { trackingOffsets = GetDefaultTrackingOffsets(); loadedButtonDefs = TBInput.LoadButtonDefs <T>(GetDefaultDefs(), fileName); lookupTable = TBInput.NewLookupTableFromDefs <T>(loadedButtonDefs); loaded = true; }
private void Start() { if (TBInput.GetControllerModel(controller) == VRController.None) { gameObject.SetActive(false); Debug.LogWarning("Finger chart was disabled because no controller was found for " + controller + ". Is that input type enabled in Input Settings?"); return; } if (!TBInput.SupportsFinger(TBInput.Finger.Thumb, controller)) { _thumb.enabled = false; _thumb.transform.parent.gameObject.SetActive(false); } if (!TBInput.SupportsFinger(TBInput.Finger.Index, controller)) { _index.transform.parent.gameObject.SetActive(false); _index.enabled = false; } if (!TBInput.SupportsFinger(TBInput.Finger.Grip, controller)) { _grip.transform.parent.gameObject.SetActive(false); _grip.enabled = false; } if (controller == TBInput.Controller.RHandController) { ToggleHandedness(); } }
/// <summary> /// Loads controller data into memory for a given SDK. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="controllers"></param> /// <param name="controllerName"></param> /// <param name="defaultButtonDefs"></param> /// <param name="fileName"></param> public static string LoadController <T>(ref Dictionary <string, ButtonMapGroup <TBInput.ButtonDef <T> > > controllers, string controllerName, List <TBInput.ButtonDef <T> > defaultButtonDefs, string fileName) { ButtonMapGroup <TBInput.ButtonDef <T> > newController; if (controllers.TryGetValue(controllerName, out newController)) { return(controllerName); } else { newController = new ButtonMapGroup <TBInput.ButtonDef <T> >(); newController.fileName = fileName; newController.controllerName = controllerName; newController.defs = defaultButtonDefs; // If a custom mapping exits, try to use it. if (File.Exists(settingsPath + TBSettings.settingsFolder + newController.fileName + ".json")) { newController.defs = TBInput.LoadButtonDefs(defaultButtonDefs, fileName); TBLogging.LogMessage("Found and loaded button maps for " + controllerName + ".", null, messageEnd); } else { // If no custom mapping, we use the default one. A custom one will be saved if you make any changes. TBLogging.LogMessage("Could not find custom button maps for " + controllerName + " in " + settingsPath + TBSettings.settingsFolder + newController.fileName + ".json. Created new maps from default.", null, messageEnd); } controllers.Add(controllerName, newController); return(controllerName); } }
/// <summary> /// Override to set up inputs for the left and right controllers in a single def on 3DOF. /// </summary> protected override void Initialize() { loadedButtonDefs = TBInput.LoadButtonDefs(GetDefaultDefs(), fileName); if (TBCore.GetActiveHeadset() == VRHeadset.GearVR) { _instance.model = VRController.GearVRController; } loadedButtonDefs.Add(new TBInput.ButtonDef <OVRInput.RawButton>() { rawButton = OVRInput.RawButton.LTouchpad, virtualButtons = loadedButtonDefs[0].virtualButtons, name = "Touchpad Left", supportsTouch = true, supportsAxis2D = true }); loadedButtonDefs.Add(new TBInput.ButtonDef <OVRInput.RawButton>() { rawButton = OVRInput.RawButton.LIndexTrigger, virtualButtons = loadedButtonDefs[1].virtualButtons, name = "Trigger Left", supportsTouch = false, supportsAxis2D = false }); lookupTable = TBInput.NewLookupTableFromDefs(loadedButtonDefs); loaded = true; }
private void DetectInputs(out bool actionTeleportation, out bool shiftLeft, out bool shiftRight, out bool actionInteract, out bool actionRelease) { actionTeleportation = false; shiftLeft = false; shiftRight = false; actionInteract = false; actionRelease = false; /* check whether we prefer to use a touchpad or joystick with current controller configuration */ if (useTouchpadInsteadOfJoystick) { DetectTouchpadInputs(out actionTeleportation, out shiftLeft, out shiftRight); } else { DetectJoystickInputs(out actionTeleportation, out shiftLeft, out shiftRight); } /* trigger is pressed -> interact with object */ //if(TBInput.GetButtonDown(TBInput.Button.PrimaryTrigger, controller)) { if (TBInput.GetAxis1D(TBInput.Button.PrimaryTrigger, controller) > triggerThreshold && !triggerPushed) { triggerPushed = true; actionInteract = true; } /* trigger is released -> release object */ //if(TBInput.GetButtonUp(TBInput.Button.PrimaryTrigger, controller)) { if (TBInput.GetAxis1D(TBInput.Button.PrimaryTrigger, controller) < triggerThreshold && triggerPushed) { triggerPushed = false; actionRelease = true; } }
private void ButtonStart_Click(object sender, EventArgs e) { if (!int.TryParse(TBInput.Text, out n)) { MessageBox.Show("Введено неверное значение", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); TBInput.Clear(); return; } DG1.ColumnCount = n; DG1.RowCount = 1; DG1.Rows[0].Height = 43; MergeSort.CountComps = 0; MergeSort.CountMoves = 0; FormHelper.MatrToGRid(DG1, FormHelper.OutputResultMergeSort(arr.ToArray()), n); TBCompsMerge.Text = MergeSort.CountComps.ToString(); TBMovesMerge.Text = MergeSort.CountMoves.ToString(); DG2.ColumnCount = n; DG2.RowCount = 1; DG2.Rows[0].Height = 43; NaturalMergeSort.CountComps = 0; NaturalMergeSort.CountMoves = 0; FormHelper.MatrToGRid(DG2, FormHelper.OutputResultNaturalMergeSort(arr.ToArray()), n); TBCompsNatMerge.Text = NaturalMergeSort.CountComps.ToString(); TBMovesNatMerge.Text = NaturalMergeSort.CountMoves.ToString(); }
private IEnumerator Start() { if (TBInput.GetControllerModel(controller) == VRController.None) { Debug.Log("Input chart was disabled because no controller was found for " + controller + ". This means that the associated ControlType is disabled in TButt's Input Settings, or no compatible controller exists for the current platform."); gameObject.SetActive(false); yield break; } controllerLabel.text = controller.ToString() + " | " + TBInput.GetControllerModel(controller).ToString(); _rect = GetComponent <RectTransform>(); for (int i = 0; i < buttons.Count; i++) { if (TBInput.SupportsVirtualButton(buttons[i], controller)) { CreateDisplayRow(buttons[i]); } } ConformHeights(); TBInput.ControlType assocaitedControlType = TBInput.ControlType.None; switch (controller) { case TBInput.Controller.LHandController: case TBInput.Controller.RHandController: assocaitedControlType = TBInput.ControlType.HandControllers; break; case TBInput.Controller.Mobile3DOFController: assocaitedControlType = TBInput.ControlType.Mobile3DOFController; break; case TBInput.Controller.Gamepad: assocaitedControlType = TBInput.ControlType.Gamepad; break; case TBInput.Controller.ClickRemote: assocaitedControlType = TBInput.ControlType.ClickRemote; break; } if (assocaitedControlType != TBInput.GetActiveControlType()) { gameObject.GetComponent <Canvas>().enabled = false; while (TBInput.GetActiveControlType() == TBInput.ControlType.None) { yield return(null); } if (assocaitedControlType == TBInput.GetActiveControlType()) { gameObject.GetComponent <Canvas>().enabled = true; } } }
protected virtual T[] GetButtonArray(TBInput.Button button, ref TBInput.Controller controller) { if (controller == TBInput.Controller.Active) { controller = TBInput.GetActiveController(); } return(TBInput.GetRawButtons <T>(button, GetButtonLookupTableForController(controller))); }
/// <summary> /// Needed for generating a controller type compatible with Oculus SDK calls. /// </summary> /// <param name="controller"></param> /// <returns></returns> public static OVRInput.Controller GetOculusControllerID(TBInput.Controller controller) { if (controller == TBInput.Controller.Active) { controller = TBInput.GetActiveController(); } switch (controller) { case TBInput.Controller.LHandController: return(OVRInput.Controller.LTouch); case TBInput.Controller.RHandController: return(OVRInput.Controller.RTouch); case TBInput.Controller.Mobile3DOFController: if (TBCore.UsingEditorMode() || TBCore.GetActivePlatform() == VRPlatform.OculusPC) { if (TBSettings.GetControlSettings().handedness3DOF == TBSettings.TBHardwareHandedness.Left) { return(OVRInput.Controller.LTouch); } else { return(OVRInput.Controller.RTouch); } } else { if (OVRInput.IsControllerConnected(OVRInput.Controller.LTrackedRemote)) { return(OVRInput.Controller.LTrackedRemote); } else { return(OVRInput.Controller.RTrackedRemote); } } case TBInput.Controller.ClickRemote: if (TBCore.GetActivePlatform() == VRPlatform.OculusMobile) { return(OVRInput.Controller.Touchpad); } else { return(OVRInput.Controller.Remote); } case TBInput.Controller.Gamepad: return(OVRInput.Controller.Gamepad); } TBLogging.LogError("Controller type " + controller + " has no match for Oculus."); return(OVRInput.Controller.None); }
public void SetButton(TBInput.Button button, TBInput.Controller controller) { _button = button; _controller = controller; if (!TBInput.SupportsAxis1D(button, controller)) { transform.parent.gameObject.SetActive(false); } }
public void SetButton(TBInput.Button button, TBInput.Controller controller) { _button = button; _controller = controller; if (!TBInput.SupportsButton(button, controller)) { gameObject.SetActive(false); } }
private void Update() { if (TBInput.GetButton(_button, _controller)) { _image.color = Color.green; } else { _image.color = Color.white; } }
void Start() { if (TBInput.GetActiveControlType() != TBInput.ControlType.None) { gameObject.SetActive(false); } else { StartCoroutine(ChooseController()); } }
private void AnimateInput(ref float time, TBInput.Controller controller) { if (TBInput.GetButton(TBInput.Button.Any, controller)) { AddTime(ref time); } else { ResolveTime(ref time); } }
private void OnEnable() { if (TBInput.GetActiveControlType() == TBInput.ControlType.None) { TBInput.Events.OnControlTypeChanged += OnControlTypeChanged; _subscribed = true; } else { gameObject.SetActive(false); } }
protected virtual IEnumerator RefreshInputRoutine() { switch (TBInput.GetActiveControlType()) { case TBInput.ControlType.Mobile3DOFController: while (Get3DOFHandedness() == TBInput.Mobile3DOFHandedness.Center) { yield return(null); } TBInput.Events.Internal.UpdateHandedness(Get3DOFHandedness()); break; } }
private void Button_Click(object sender, EventArgs e) { if (!int.TryParse(TBInput.Text, out n)) { MessageBox.Show("Введено неверное значение", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); TBInput.Clear(); return; } DGSource.ColumnCount = n; DGSource.RowCount = 1; DGSource.Rows[0].Height = 43; arr = FormHelper.InputData(n); FormHelper.MatrToGRid(DGSource, arr, n); }
private void AnimateControllerModel() { if (TBInput.GetAxis1D(TBInput.Button.PrimaryTrigger, controller) > triggerThreshold) { triggerRepresentation.transform.localRotation = Quaternion.Euler(-10.0f, -180.0f, 0.0f); } else { triggerRepresentation.transform.localRotation = Quaternion.Euler(10.0f, -180.0f, 0.0f); } Vector2 joyPos = TBInput.GetAxis2D(TBInput.Button.Joystick, controller); analogRepresentation.transform.localRotation = Quaternion.Euler(-joyPos.y * 30.0f, 180.0f, joyPos.x * 30.0f); }
public override TBInput.Controller GetActiveController() { if (TBInput.GetActiveControlType() == TBInput.ControlType.HandControllers) { if (GvrControllerInput.GetDevice(GvrControllerHand.Dominant).SupportsPositionalTracking) { return(TBInput.Controller.RHandController); } else { return(TBInput.Controller.Mobile3DOFController); } } else { return(TBInput.Controller.Mobile3DOFController); } }
private IEnumerator Start() { while (TBInput.GetActiveControlType() == TBInput.ControlType.None) { yield return(null); } switch (TBInput.GetActiveControlType()) { case TBInput.ControlType.Mobile3DOFController: Instantiate(mobile3DOFController).name = "3DOF Controller"; break; case TBInput.ControlType.HandControllers: Instantiate(leftHandController).name = "Left Hand Controller"; Instantiate(rightHandController).name = "Right Hand Controller"; break; } }
public virtual TBInput.Controller GetActiveController() { switch (TBInput.GetActiveControlType()) { case TBInput.ControlType.ClickRemote: return(TBInput.Controller.ClickRemote); case TBInput.ControlType.Gamepad: return(TBInput.Controller.Gamepad); case TBInput.ControlType.HandControllers: return(TBInput.Controller.RHandController); case TBInput.ControlType.Mobile3DOFController: return(TBInput.Controller.Mobile3DOFController); default: return(TBInput.Controller.None); } }
private void Start() { if (TBInput.GetControllerModel(controller) == VRController.None) { Debug.LogWarning("Input chart was disabled because no controller was found for " + controller + ". Is that input type enabled in Input Settings?"); gameObject.SetActive(false); return; } controllerLabel.text = controller.ToString() + " | " + TBInput.GetControllerModel(controller).ToString(); _rect = GetComponent <RectTransform>(); for (int i = 0; i < buttons.Count; i++) { if (TBInput.SupportsVirtualButton(buttons[i], controller)) { CreateDisplayRow(buttons[i]); } } ConformHeights(); }
public override void Update() { #if ENABLE_WINMD_SUPPORT if (Gamepad.Gamepads == null) { return; } if (Gamepad.Gamepads.Count > 0) { gamepad = Gamepad.Gamepads[0]; _prevReading = _reading; _reading = gamepad.GetCurrentReading(); } #else if (!_playerIndexSet || !_prevState.IsConnected) { for (int i = 0; i < 4; ++i) { PlayerIndex testPlayerIndex = (PlayerIndex)i; GamePadState testState = GamePad.GetState(testPlayerIndex); if (testState.IsConnected) { Debug.Log(string.Format("GamePad found {0}", testPlayerIndex)); playerIndex = testPlayerIndex; _playerIndexSet = true; } } } if (TBInput.GetActiveControlType() == TBInput.ControlType.Gamepad) { GamePad.SetVibration(0, 0, 0); } _prevState = _state; _state = GamePad.GetState(playerIndex); #endif }
protected GvrControllerInputDevice GetGoogleControllerID(TBInput.Controller controller) { if (controller == TBInput.Controller.Active) { controller = TBInput.GetActiveController(); } switch (controller) { case TBInput.Controller.LHandController: return(GvrControllerInput.GetDevice(GvrControllerHand.Left)); case TBInput.Controller.RHandController: return(GvrControllerInput.GetDevice(GvrControllerHand.Right)); case TBInput.Controller.Mobile3DOFController: return(GvrControllerInput.GetDevice(GvrControllerHand.Dominant)); default: TBLogging.LogError("No controller for " + controller + " exists in TButt's Google VR implementation. Falling back to dominant hand controller."); return(GvrControllerInput.GetDevice(GvrControllerHand.Dominant)); } }
private void DetectTouchpadInputs(out bool actionTeleportation, out bool shiftLeft, out bool shiftRight) { actionTeleportation = false; shiftLeft = false; shiftRight = false; /* on touch start, note current touch position and prepare for shift */ Vector2 touchpadPosition = TBInput.GetAxis2D(TBInput.Button.Touchpad, controller); if (TBInput.GetTouchDown(TBInput.Button.Action1, controller)) { touchpadPrepareForShift = true; touchpadPositionOnTouchStart = touchpadPosition; } /* on touchpad release, check whether shift flag is still up and whether minimum threshold is met */ else if (TBInput.GetTouchUp(TBInput.Button.Action1, controller) && touchpadPrepareForShift) { touchpadPrepareForShift = false; if (Mathf.Abs(touchpadPosition.x - touchpadPositionOnTouchStart.x) > touchpadSwipeThreshold) { if (touchpadPosition.x < touchpadPositionOnTouchStart.x) { shiftLeft = true; } else { shiftRight = true; } } } /* when button is clicked, initiate teleport and cancel shift */ if (TBInput.GetButton(TBInput.Button.Action1, controller)) { touchpadPrepareForShift = false; actionTeleportation = true; } }
private IEnumerator ChooseController() { if (!TBInput.SupportsControlType(controlType)) { disabledImage.gameObject.SetActive(true); yield break; } while (TBInput.GetActiveControlType() == TBInput.ControlType.None) { switch (controlType) { case TBInput.ControlType.HandControllers: AnimateHandControllers(); break; case TBInput.ControlType.ClickRemote: AnimateInput(ref _selectionVal, TBInput.Controller.ClickRemote); break; case TBInput.ControlType.Gamepad: AnimateInput(ref _selectionVal, TBInput.Controller.Gamepad); break; case TBInput.ControlType.Mobile3DOFController: AnimateInput(ref _selectionVal, TBInput.Controller.Mobile3DOFController); break; } if (_selectionVal >= 1) { TBInput.SetActiveControlType(controlType); } yield return(null); } }
private void DetectJoystickInputs(out bool actionTeleportation, out bool shiftLeft, out bool shiftRight) { actionTeleportation = false; shiftLeft = false; shiftRight = false; /* joystick is pulled toward or away from player -> teleport */ Vector2 joystickPosition = TBInput.GetAxis2D(TBInput.Button.Joystick, controller); if (Mathf.Abs(joystickPosition.y) > joystickThreshold) { actionTeleportation = true; } /* joystick is pulled to the right -> blink shift to right */ else if (joystickPosition.x > joystickThreshold) { if (!shiftInitiated) { shiftRight = true; shiftInitiated = true; } } /* joystick is pulled to the left -> blink shift to left */ else if (joystickPosition.x < -joystickThreshold) { if (!shiftInitiated) { shiftLeft = true; shiftInitiated = true; } } else { shiftInitiated = false; } }
private void AnimateHandControllers() { bool leftController = false; bool rightController = false; if (TBInput.GetButton(TBInput.Button.Any, TBInput.Controller.RHandController)) { rightController = true; } if (TBInput.GetButton(TBInput.Button.Any, TBInput.Controller.LHandController)) { leftController = true; } if (rightController || leftController) { AddTime(ref _selectionVal); } else { ResolveTime(ref _selectionVal); } }
private void Update() { if (_thumb.enabled) { _thumbWeight = TBInput.GetFinger(TBInput.Finger.Thumb, controller); _thumb.fillAmount = _thumbWeight; } if (_index.enabled) { _indexWeight = TBInput.GetFinger(TBInput.Finger.Index, controller); _index.fillAmount = _indexWeight; } if (_grip.enabled) { _gripWeight = TBInput.GetFinger(TBInput.Finger.Grip, controller); _grip.fillAmount = _gripWeight; } else { _gripWeight = _indexWeight; } ResolveIcon(); }