public SteamVRController(string name, int index, InputTransform inputTransform) : base(name) { m_Index = (uint)index; m_InputTransform = inputTransform; // Write the controller's properties XDevicePlugin.SetBool(handle, XDevicePlugin.kField_IsAbsRotation, true); }
public override void Move(InputTransform inp, Transform transform) { base.Move(inp, transform); parent.velocity = new Vector3((float)(start_velocity.x + float_speed * Mathf.Cos((float)inp.direction) * inp.magnitude), parent.player_rb.velocity.y, (float)(start_velocity.z + float_speed * Mathf.Sin((float)inp.direction) * inp.magnitude)); Debug.Log($"Move()->float: {parent.velocity}"); }
public override void Move(InputTransform inp, Transform transform) { base.Move(inp, transform); if (doubleTapDetector.DetectDirectional(inp)) { sprintState = true; } if (Math.Abs(inp.magnitude) < doubleTapDetector.doubleTapCloseness) { sprintState = false; } if (sprintState) { parent.velocity = new Vector3((float)(sprintSpeed * Math.Cos(inp.direction) * inp.magnitude), 0, (float)(sprintSpeed * Math.Sin(inp.direction) * inp.magnitude)); Debug.Log($"Move()->sprint: {parent.velocity}"); } else { parent.velocity = new Vector3((float)(runSpeed * Math.Cos(inp.direction) * inp.magnitude), 0, (float)(runSpeed * Math.Sin(inp.direction) * inp.magnitude)); Debug.Log($"Move()->run: {parent.velocity}"); } anim_speed = parent.velocity.magnitude / 3.0f; }
public static uint TransformButton(InputTransform transform, ulong ulButtonPressed, ulong ulButtonTouched) { uint ret = 0; for (int i = 0; i < transform.maxButtons; ++i) { switch ((EVRButtonId)transform.buttonMasksFrom[i]) { case EVRButtonId.k_EButton_SteamVR_Touchpad: case EVRButtonId.k_EButton_SteamVR_Trigger: if ((ulButtonTouched & (1u << transform.buttonMasksFrom[i])) != 0) { ret |= (uint)transform.buttonMasksTo[i]; } break; default: if ((ulButtonPressed & (1u << transform.buttonMasksFrom[i])) != 0) { ret |= (uint)transform.buttonMasksTo[i]; } break; } } return(ret); }
public override void OnInputUpdated(uint prev_buttons, uint buttons, bool isShift = false) { if (m_CurrentStateId == -1) { return; } // InputTransform inputMapping = isShift?m_ShiftInputMappings[m_CurrentStateId]:m_InputMappings[m_CurrentStateId]; if (inputMapping != null) { int buttonMask; for (int i = 0, imax = inputMapping.buttonMasksFrom.Length; i < imax; ++i) { buttonMask = inputMapping.buttonMasksFrom[i]; // if ((prev_buttons & buttonMask) == 0 && (buttons & buttonMask) != 0) // Down // { ImeApiPlugin.ime_simulate_key(inputMapping.buttonMasksTo[i]); } else if ((prev_buttons & buttonMask) != 0 && (buttons & buttonMask) == 0) // Up // { } } } }
public bool DetectDirectional(InputTransform inp) { if (doubleTapHold) { //Debug.Log($"Double tap hold:"); if (Math.Abs(inp.magnitude) < doubleTapCloseness) // back to 0 { if (Time.time - timeDiff > doubleTapTimeEnd) // allow user to switch directions { //Debug.Log($"Double tap hold: end"); doubleTapHold = false; return(false); } } else { timeDiff = Time.time; } //Debug.Log($"Double tap hold: yay"); return(true); } else { if (Math.Abs(prevMagnitude2) < doubleTapCloseness && Math.Abs(prevMagnitude) < doubleTapCloseness && Math.Abs(inp.magnitude - 1.0) < doubleTapCloseness) // 0 to 100 { direction = inp.direction; prevMagnitude = 1.0; timeDiff = Time.time; //Debug.Log($"Double tap 1: {prevMagnitude}, {timeDiff}"); } else if (Math.Abs(prevMagnitude - 1) < doubleTapCloseness && Math.Abs(inp.magnitude) < doubleTapCloseness && Time.time - timeDiff < doubleTapTime) // 100 to 0 { prevMagnitude2 = prevMagnitude; prevMagnitude = 0; //Debug.Log($"Double tap 2: {prevMagnitude2}, {prevMagnitude}"); } else if (Math.Abs(prevMagnitude2 - 1) < doubleTapCloseness && Math.Abs(prevMagnitude) < doubleTapCloseness && Math.Abs(inp.magnitude - 1.0) < doubleTapCloseness && Time.time - timeDiff < doubleTapTime && Math.Abs(inp.direction - direction) < doubleTapCloseness) // 0 to 100 again { prevMagnitude = 0; prevMagnitude2 = 0; direction = -999f; timeDiff = Time.time; //Debug.Log($"Double tap 3: {prevMagnitude}, {prevMagnitude}, {timeDiff}"); doubleTapHold = true; return(true); } else if (Time.time - timeDiff > doubleTapTime) { prevMagnitude = 0; prevMagnitude2 = 0; direction = -999f; timeDiff = Time.time; //Debug.Log($"Double tap 4: {prevMagnitude}, {prevMagnitude}, {timeDiff}"); } } return(false); }
/// <summary> /// /// </summary> public SixenseController(SixenseControllerManager manager, string name, int index) : base(name) { this.manager = manager; this.index = index; this.inputTransform = this.manager.inputTransforms.Length == 1?this.manager.inputTransforms[0]:this.manager.inputTransforms[index]; this.rawData = new SixensePluginLite.sixenseControllerData(); // Write the controller's properties XDevicePlugin.SetBool(handle, XDevicePlugin.kField_IsAbsRotation, true); }
public override void Move(InputTransform inp, Transform transform) { if (inp.magnitude > 0.2) { parent.anim.SetBool(parent.animation_is_idle_id, false); parent.move_state = new RunningMovementState(parent); parent.move_state.Move(inp, transform); } base.Move(inp, transform); }
public XboxController(XboxControllerManager manager, string name, int dwUserIndex) : base(name) { this.manager = manager; this.dwUserIndex = dwUserIndex; xinputState = new XInputPlugin.XINPUT_STATE(); xinputVibration = new XInputPlugin.XINPUT_VIBRATION(); xinputBatteryInformation = new XInputPlugin.XINPUT_BATTERY_INFORMATION(); // if (this.manager.inputTransforms != null && this.manager.inputTransforms.Length > 1) { inputTransform = this.manager.inputTransforms[0]; } }
/// <summary> /// /// </summary> public override bool InitAllControllers() { // if (m_IsInited) { return(false); } m_IsInited = true; // int ret; ret = XDevicePlugin.Init(); if (ret != 0) { return(false); } ret = SixensePluginLite.sixenseInit(); if (ret != 0) { return(false); } // if (maxControllers <= 0) { maxControllers = SixensePluginLite.sixenseGetMaxControllers(); } if (controllers == null) { if (inputTransforms.Length == 0) { inputTransforms = new InputTransform[1] { null }; } controllers = new SixenseController[maxControllers]; for (int i = 0; i < maxControllers; ++i) { controllers[i] = new SixenseController( this, string.Format(controllerFormat, i), i ); } } // m_Result = 0; return(true); }
public override bool InitAllControllers() { // SteamVR only works in windows. if (Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.WindowsPlayer ) { return(false); } #if STEAM_VR_SDK // bool ret = base.InitAllControllers(); if (ret) { if (!OpenVRInterop.IsRuntimeInstalled() || !OpenVRInterop.IsHmdPresent()) { ret = false; } if (ret) { if (inputTransforms.Length == 0) { inputTransforms = new InputTransform[1] { null }; } controllers = new SteamVRController[maxControllers]; for (int i = 0; i < maxControllers; ++i) { controllers[i] = new SteamVRController( string.Format(controllerFormat, i), i, inputTransforms.Length == 1?inputTransforms[0]:inputTransforms[i] ); } } } return(ret); #else Log.d("SteamVRControllerManager", "Not Support!!!If you want to enable this feature,please follow these steps:\n" + " 1) You need HTC Vive or other devices which can be developed by OpenVR,and remember SteamVR only works in pc.\n" + " 2) Import \"SteamVR Plugin.unitypackage\"(you can download it from \"https://www.assetstore.unity3d.com/en/#!/content/32647\").\n" + " 3) Add \"STEAM_VR_SDK\" to [Scripting Define Symbols] in [Player Settings](menu:Edit>Project Settings>Player).\n"); return(false); #endif }
virtual public void Move(InputTransform inp, Transform transform) { if (inp.h > 0.2) { anim_direction = 1.0f; } else if (inp.h < -0.2) { anim_direction = -1.0f; } else { anim_direction = 0.0f; } parent.transform.Rotate(0, (float)(inp.r * rotateSpeed), 0); }
// Update is called once per frame void FixedUpdate() { if (!ready) { return; } //DontGoThroughThings(player_collider, player_rb); //DontGoThroughThings(left_toe_collider, player_rb, delegate { right_foot_caught = true;}); //DontGoThroughThings(right_toe_collider, player_rb, delegate { left_foot_caught = true; }); InputTransform inp = new InputTransform(); move_state.Move(inp, transform); anim.SetFloat(animation_speed_id, (float)move_state.anim_speed); anim.SetFloat(animation_direction_id, (float)move_state.anim_direction); anim.speed = (float)move_state.anim_speed; player_rb.useGravity = true; if (Input.GetButtonDown(jump_button) && move_state.is_grounded) { move_state = new JumpingMovementState(this); //GetComponent<Rigidbody>().AddForce(Vector3.up * 1.0f); right_foot_caught = false; left_foot_caught = false; } else if (right_foot_caught || left_foot_caught) { move_state.FootGrounded(); } else { move_state.FootUngrounded(); } move_state.FixedUpdate(); velocity = transform.TransformDirection(velocity); //Debug.Log($"velocity: {velocity}"); player_rb.velocity = new Vector3(velocity.x, player_rb.velocity.y, velocity.z); //Debug.Log($"pos: {transform.localPosition}"); Debug.Log(move_state.GetType().ToString()); }
public virtual void SetSubKeyboardActive(int id, bool value, bool isShift = false) { if (id == -1) { } else { InputTransform inputMapping = isShift?m_ShiftInputMappings[id]:m_InputMappings[id]; if (inputMapping != null) { string text = null; for (int i = 0, imax = m_UIKeys.Length; i < imax; ++i) { if (m_UIKeys[i] != null) { if (m_KeyNames.TryGetValue(inputMapping.buttonMasksTo[i], out text)) { m_UIKeys[i].Display(text); } else { m_UIKeys[i].Display(((Keys)inputMapping.buttonMasksTo[i]).ToString()); } } } return; } } // Deactivate... for (int i = 0, imax = m_UIKeys.Length; i < imax; ++i) { if (m_UIKeys[i] != null) { m_UIKeys[i].Display(null); } } }
internal override bool ParseNodeBodyElement(string id, VRMLParser parser) { int line = parser.Line; if (id == "children") { List <X3DNode> nodes = parser.ParseSFNodeOrMFNodeValue(); foreach (X3DNode node in nodes) { X3DChildNode child = node as X3DShapeNode; if (child == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } else { Children.Add(child); } } } else if (id == "controlPoint") { object token = parser.PeekNextToken(); if (token is VRMLTokenIdKeywordOrFieldType) { X3DNode node = parser.ParseSFNodeValue(); if (node != null) { ControlPoint = node as X3DCoordinateNode; if (ControlPoint == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } } } else { x3dCoordinate coords = new x3dCoordinate(); coords.Point = parser.ParseSFVec3fOrMFVec3fValue(); ControlPoint = coords; } } else if (id == "inputCoord") { List <X3DNode> nodes = parser.ParseSFNodeOrMFNodeValue(); foreach (X3DNode node in nodes) { X3DCoordinateNode coord = node as X3DCoordinateNode; if (coord == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } else { InputCoord.Add(coord); } } } else if (id == "inputTransform") { List <X3DNode> nodes = parser.ParseSFNodeOrMFNodeValue(); foreach (X3DNode node in nodes) { IX3DCoordinateDeformerInputTransform transf = node as IX3DCoordinateDeformerInputTransform; if (transf == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } else { InputTransform.Add(transf); } } } else if (id == "outputCoord") { List <X3DNode> nodes = parser.ParseSFNodeOrMFNodeValue(); foreach (X3DNode node in nodes) { X3DCoordinateNode coord = node as X3DCoordinateNode; if (coord == null) { parser.ErrorParsingNode(VRMLReaderError.UnexpectedNodeType, this, id, node, line); } else { OutputCoord.Add(coord); } } } else if (id == "weight") { Weight.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "bboxCenter") { BBoxCenter = parser.ParseSFVec3fValue(); } else if (id == "bboxSize") { BBoxSize = parser.ParseSFVec3fValue(); } else if (id == "uDimension") { UDimension = parser.ParseIntValue(); } else if (id == "uKnot") { UKnot.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "uOrder") { UOrder = parser.ParseIntValue(); } else if (id == "vDimension") { VDimension = parser.ParseIntValue(); } else if (id == "vKnot") { VKnot.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "vOrder") { VOrder = parser.ParseIntValue(); } else if (id == "wDimension") { WDimension = parser.ParseIntValue(); } else if (id == "wKnot") { WKnot.AddRange(parser.ParseSFFloatOrMFFloatValue()); } else if (id == "wOrder") { WOrder = parser.ParseIntValue(); } else { return(false); } return(true); }