123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS {
- public class ModelK102 : ModelK101 {
- bool isAXkeyTouch;
- bool isBYkeyTouch;
- bool isJSkeyTouch;
- bool isHFkeyTouch;
- Vector3 initLocaleulerAngle;
- public Vector3 DefauleAngleOffset;
- public override void OnSCAwake() {
- base.OnSCAwake();
- if (StartPoint) {
- initLocaleulerAngle = StartPoint.localEulerAngles;
- DefauleAngleOffset = new Vector3(43,0,0);
- }
- }
- bool isEnableHandAnimation = false;
- float timeindex = 0;
- [Header("PowerVisual")]
- public MeshRenderer powerMeshRender;
- [Header("PowerShinVisual")]
- public SkinnedMeshRenderer powerShinnedMeshRender;
- public MeshRenderer OtherMeshRender;
- public override void OnSCStart() {
- base.OnSCStart();
- if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "EnableK102HandAnimation")) {
- isEnableHandAnimation = API_Module_SDKConfiguration.GetBool("Module_InputSystem", "EnableK102HandAnimation", 0);
- }
- if (isEnableHandAnimation == false && handAnimation) {
- handAnimation.ModuleStop();
- }
- if (StartPoint) {
- InitStartPointRotation();
- }
- if (powerMeshRender) {
- powerMeshRender.sharedMaterial = releaseMaterial;
- }
- if (powerShinnedMeshRender) {
- powerShinnedMeshRender.sharedMaterial = releaseMaterial;
- }
- if (OtherMeshRender) {
- OtherMeshRender.sharedMaterial = releaseMaterial;
- }
- }
- public override void OnSCDestroy() {
- base.OnSCDestroy();
- StartPoint.localEulerAngles = initLocaleulerAngle;
- }
- protected void InitStartPointRotation() {
- if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "K102PointerAngleOffsetX")) {
- DefauleAngleOffset.x = Mathf.Clamp(API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "K102PointerAngleOffsetX", 0), -60, 60);
- }
- if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "K102PointerAngleOffsetY")) {
- DefauleAngleOffset.y = Mathf.Clamp(API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "K102PointerAngleOffsetY", 0), -60, 60);
- }
- if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "K102PointerAngleOffsetZ")) {
- DefauleAngleOffset.z = Mathf.Clamp(API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "K102PointerAngleOffsetZ", 0), -60, 60);
- }
- DebugMy.Log("StartPoint initLocaleulerAngle:" + initLocaleulerAngle + " DefauleAngleOffset:" + DefauleAngleOffset, this, true);
- if (Application.isEditor) {
- DefauleAngleOffset = new Vector3(0, 0, 0);
- DebugMy.Log("isEditor Set DefauleAngleOffset:" + DefauleAngleOffset, this, true);
- }
- StartPoint.localEulerAngles = initLocaleulerAngle + DefauleAngleOffset;
- }
- public override void UpdatePowerUI() {
- base.UpdatePowerUI();
- timeindex += Time.deltaTime;
- if (timeindex < 1f) {
- return;
- }
- timeindex = 0;
- if (inputDeviceGCPartUI && pressMaterial && releaseMaterial) {
- if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 1) {
- precentLed(0.25f);
- } else if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 3) {
- precentLed(0.5f);
- } else if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 5) {
- precentLed(0.75f);
- } else if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 7) {
- precentLed(1);
- }
- }
- }
- protected virtual void precentLed(float percent) {
- if (powerShinnedMeshRender) {
- if (percent <= 0.25f) {
- powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.35f, 1));
- } else if (percent <= 0.5f) {
- powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.25f, 1));
- } else if (percent <= 0.75f) {
- powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.15f, 1));
- } else if (percent <= 1f) {
- powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.1f, 1));
- }
- } else if (powerMeshRender) {
- if (percent <= 0.25f) {
- powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.35f, 1));
- } else if (percent <= 0.5f) {
- powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.25f, 1));
- } else if (percent <= 0.75f) {
- powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.15f, 1));
- } else if (percent <= 1f) {
- powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.1f, 1));
- }
- }
- }
- public override void UpdateHallVisual() {
- if (HallForward) {
- HallForward.localEulerAngles = (HallForwardPresslocalEulerAngles - HallForwardReleaselocalEulerAngles) / (HallForwardPressValue - HallForwardReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallFoward + HallForwardPresslocalEulerAngles;
- }
- if (HallInside) {
- HallInside.localPosition = (HallInsidePressLocalPosition - HallInsideReleaseLocalPosition) / (HallInsidePressValue - HallInsideReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallInside + HallInsidePressLocalPosition;
- }
- }
- public override void SetHandleKeysColor()
- {
- if (releaseMaterial == null || pressMaterial == null)
- {
- return;
- }
- foreach (var item in inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.inputKeys.inputKeyPressDic)
- {
- if (item.Key == InputKeyCode.Trigger)
- {
- //triggerKey.material = releaseMaterial;
- //if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
- // triggerKey.material = pressMaterial;
- //}
- }
- else if (functionKey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction))
- {
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
- {
- functionKey.material = pressMaterial;
- }
- else if (item.Value == InputKeyState.UP)
- {
- functionKey.material = releaseMaterial;
- }
- else if (item.Value == InputKeyState.TouchEnter) {
- functionKey.material = touchEnterMaterial;
- }
- else if (item.Value == InputKeyState.TouchExit)
- {
- functionKey.material = releaseMaterial;
- }
- }
- else if (axkey && (item.Key == InputKeyCode.X || item.Key == InputKeyCode.A))
- {
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
- {
- axkey.material = pressMaterial;
- }
- else if (item.Value == InputKeyState.TouchEnter)
- {
- isAXkeyTouch=true;
- if (axkey.material != pressMaterial)
- {
- axkey.material = touchEnterMaterial;
- }
- }
- else if (item.Value == InputKeyState.TouchExit)
- {
- isAXkeyTouch = false;
- axkey.material = releaseMaterial;
- }
- else if (item.Value == InputKeyState.UP)
- {
- axkey.material = isAXkeyTouch ? touchEnterMaterial : releaseMaterial;
- }
- }
- else if (bykey && (item.Key == InputKeyCode.Y || item.Key == InputKeyCode.B))
- {
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
- {
- bykey.material = pressMaterial;
- }
- else if (item.Value == InputKeyState.TouchEnter)
- {
- isBYkeyTouch = true;
- if (bykey.material != pressMaterial)
- {
- bykey.material = touchEnterMaterial;
- }
- }
- else if (item.Value == InputKeyState.TouchExit)
- {
- isBYkeyTouch = false;
- bykey.material = releaseMaterial;
- }
- else if (item.Value == InputKeyState.UP)
- {
- bykey.material = isBYkeyTouch ? touchEnterMaterial : releaseMaterial;
- }
- }
- else if (hallFoward && (item.Key == InputKeyCode.LHallForward || item.Key == InputKeyCode.RHallForward))
- {
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
- {
- hallFoward.material = pressMaterial;
- }
- else if (item.Value == InputKeyState.TouchEnter)
- {
- isHFkeyTouch = true;
- hallFoward.material = touchEnterMaterial;
- }
- else if (item.Value == InputKeyState.TouchExit)
- {
- isHFkeyTouch = false;
- hallFoward.material = releaseMaterial;
- }
- else if (item.Value == InputKeyState.UP)
- {
- hallFoward.material = isHFkeyTouch ? touchEnterMaterial : releaseMaterial;
- }
- }
- else if (hallInside && (item.Key == InputKeyCode.LHallInside || item.Key == InputKeyCode.RHallInside))
- {
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
- {
- hallInside.material = pressMaterial;
- }
- else if (item.Value == InputKeyState.UP)
- {
- hallInside.material = releaseMaterial;
- }
- else if (item.Value == InputKeyState.TouchEnter)
- {
- hallInside.material = touchEnterMaterial;
- }
- else if (item.Value == InputKeyState.TouchExit)
- {
- hallInside.material = releaseMaterial;
- }
- }
- else if (joystickKey && (item.Key == InputKeyCode.LjoystickKey || item.Key == InputKeyCode.RjoystickKey))
- {
- if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
- {
- joystickKey.material = pressMaterial;
- }
- else if (item.Value == InputKeyState.TouchEnter)
- {
- isJSkeyTouch = true;
- joystickKey.material = touchEnterMaterial;
- }
- else if (item.Value == InputKeyState.TouchExit)
- {
- isJSkeyTouch = false;
- joystickKey.material = releaseMaterial;
- }
- else if (item.Value == InputKeyState.UP)
- {
- joystickKey.material = releaseMaterial;
- }
- }
- }
- }
- }
- }
|