123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS {
- public class ModelK11 : ModelGCBase {
- public InputDeviceKSPartUI inputDeviceKSPartUI {
- get {
- return inputDevicePartUIBase as InputDeviceKSPartUI;
- }
- }
- [Header("3DofBias")]
- public Vector3 modelPositionDeltaWithDevice = new Vector3(0, 0, 0f);
- [Header("Keys")]
- public MeshRenderer Upkey;
- public MeshRenderer Downkey;
- public MeshRenderer LeftKey;
- public MeshRenderer RightKey;
- public MeshRenderer TriggerKey;
- [Header("Joystick")]
- public Transform joystick;
- [Range(0,4)]
- public float rotationfactor = 2;
- public Vector2 joystickInitalValue = new Vector2(8, 8);
- public Vector3 joystickInitallocalEulerAngles;
- [Header("MaterialVisual")]
- public Material pressMaterial;
- public Material releaseMaterial;
- void UpdateTransform() {
- transform.localPosition = modelPositionDeltaWithDevice;
- }
- public override void OnSCStart() {
- base.OnSCStart();
- }
- public override void OnSCLateUpdate() {
- base.OnSCLateUpdate();
- UpdateTransform();
- UpdateJoystickTransform();
- }
- //[Range(0, 16)]
- //public int xx = 8;
- //[Range(0, 16)]
- //public int yy = 8;
- Vector3 biasJoystick = new Vector3(0,0,0);
- public virtual void UpdateJoystickTransform() {
- if (joystick) {
- if(inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX != joystickInitalValue.x || inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY != joystickInitalValue.y) {
- biasJoystick.z = rotationfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX - joystickInitalValue.x);
- biasJoystick.x = rotationfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY - joystickInitalValue.y);
- joystick.localEulerAngles = joystickInitallocalEulerAngles + biasJoystick;
- }
- }
- }
- public override void SetHandleKeysColor() {
- if (releaseMaterial == null || pressMaterial == null) {
- return;
- }
- foreach (var item in inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.inputKeys.inputKeyDic) {
- if(TriggerKey && (item.Key == InputKeyCode.LTrigger || item.Key == InputKeyCode.RTrigger)) {
- TriggerKey.material = releaseMaterial;
- if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
- TriggerKey.material = pressMaterial;
- }
- } else if (Upkey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction)) {
- Upkey.material = releaseMaterial;
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
- Upkey.material = pressMaterial;
- }
- } else if(RightKey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction)) {
- RightKey.material = releaseMaterial;
- if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
- RightKey.material = pressMaterial;
- }
- } else if (Downkey && (item.Key == InputKeyCode.X || item.Key == InputKeyCode.A)) {
- Downkey.material = releaseMaterial;
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
- Downkey.material = pressMaterial;
- }
- } else if(LeftKey && (item.Key == InputKeyCode.Y || item.Key == InputKeyCode.B)) {
- LeftKey.material = releaseMaterial;
- if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
- LeftKey.material = pressMaterial;
- }
- }
- }
- }
- }
- }
|