ModelK102.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS {
  6. public class ModelK102 : ModelK101 {
  7. bool isAXkeyTouch;
  8. bool isBYkeyTouch;
  9. bool isJSkeyTouch;
  10. bool isHFkeyTouch;
  11. Vector3 initLocaleulerAngle;
  12. public Vector3 DefauleAngleOffset;
  13. public override void OnSCAwake() {
  14. base.OnSCAwake();
  15. if (StartPoint) {
  16. initLocaleulerAngle = StartPoint.localEulerAngles;
  17. DefauleAngleOffset = new Vector3(43,0,0);
  18. }
  19. }
  20. bool isEnableHandAnimation = false;
  21. float timeindex = 0;
  22. [Header("PowerVisual")]
  23. public MeshRenderer powerMeshRender;
  24. [Header("PowerShinVisual")]
  25. public SkinnedMeshRenderer powerShinnedMeshRender;
  26. public MeshRenderer OtherMeshRender;
  27. public override void OnSCStart() {
  28. base.OnSCStart();
  29. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "EnableK102HandAnimation")) {
  30. isEnableHandAnimation = API_Module_SDKConfiguration.GetBool("Module_InputSystem", "EnableK102HandAnimation", 0);
  31. }
  32. if (isEnableHandAnimation == false && handAnimation) {
  33. handAnimation.ModuleStop();
  34. }
  35. if (StartPoint) {
  36. InitStartPointRotation();
  37. }
  38. if (powerMeshRender) {
  39. powerMeshRender.sharedMaterial = releaseMaterial;
  40. }
  41. if (powerShinnedMeshRender) {
  42. powerShinnedMeshRender.sharedMaterial = releaseMaterial;
  43. }
  44. if (OtherMeshRender) {
  45. OtherMeshRender.sharedMaterial = releaseMaterial;
  46. }
  47. }
  48. public override void OnSCDestroy() {
  49. base.OnSCDestroy();
  50. StartPoint.localEulerAngles = initLocaleulerAngle;
  51. }
  52. protected void InitStartPointRotation() {
  53. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "K102PointerAngleOffsetX")) {
  54. DefauleAngleOffset.x = Mathf.Clamp(API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "K102PointerAngleOffsetX", 0), -60, 60);
  55. }
  56. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "K102PointerAngleOffsetY")) {
  57. DefauleAngleOffset.y = Mathf.Clamp(API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "K102PointerAngleOffsetY", 0), -60, 60);
  58. }
  59. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "K102PointerAngleOffsetZ")) {
  60. DefauleAngleOffset.z = Mathf.Clamp(API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "K102PointerAngleOffsetZ", 0), -60, 60);
  61. }
  62. DebugMy.Log("StartPoint initLocaleulerAngle:" + initLocaleulerAngle + " DefauleAngleOffset:" + DefauleAngleOffset, this, true);
  63. if (Application.isEditor) {
  64. DefauleAngleOffset = new Vector3(0, 0, 0);
  65. DebugMy.Log("isEditor Set DefauleAngleOffset:" + DefauleAngleOffset, this, true);
  66. }
  67. StartPoint.localEulerAngles = initLocaleulerAngle + DefauleAngleOffset;
  68. }
  69. public override void UpdatePowerUI() {
  70. base.UpdatePowerUI();
  71. timeindex += Time.deltaTime;
  72. if (timeindex < 1f) {
  73. return;
  74. }
  75. timeindex = 0;
  76. if (inputDeviceGCPartUI && pressMaterial && releaseMaterial) {
  77. if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 1) {
  78. precentLed(0.25f);
  79. } else if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 3) {
  80. precentLed(0.5f);
  81. } else if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 5) {
  82. precentLed(0.75f);
  83. } else if (inputDeviceGCPartUI.inputDeviceGCPart.inputDataGC.BatteryPower <= 7) {
  84. precentLed(1);
  85. }
  86. }
  87. }
  88. protected virtual void precentLed(float percent) {
  89. if (powerShinnedMeshRender) {
  90. if (percent <= 0.25f) {
  91. powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.35f, 1));
  92. } else if (percent <= 0.5f) {
  93. powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.25f, 1));
  94. } else if (percent <= 0.75f) {
  95. powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.15f, 1));
  96. } else if (percent <= 1f) {
  97. powerShinnedMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.1f, 1));
  98. }
  99. } else if (powerMeshRender) {
  100. if (percent <= 0.25f) {
  101. powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.35f, 1));
  102. } else if (percent <= 0.5f) {
  103. powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.25f, 1));
  104. } else if (percent <= 0.75f) {
  105. powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.15f, 1));
  106. } else if (percent <= 1f) {
  107. powerMeshRender.sharedMaterial.SetTextureScale("_TextureSample1", new Vector2(0.1f, 1));
  108. }
  109. }
  110. }
  111. public override void UpdateHallVisual() {
  112. if (HallForward) {
  113. HallForward.localEulerAngles = (HallForwardPresslocalEulerAngles - HallForwardReleaselocalEulerAngles) / (HallForwardPressValue - HallForwardReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallFoward + HallForwardPresslocalEulerAngles;
  114. }
  115. if (HallInside) {
  116. HallInside.localPosition = (HallInsidePressLocalPosition - HallInsideReleaseLocalPosition) / (HallInsidePressValue - HallInsideReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallInside + HallInsidePressLocalPosition;
  117. }
  118. }
  119. public override void SetHandleKeysColor()
  120. {
  121. if (releaseMaterial == null || pressMaterial == null)
  122. {
  123. return;
  124. }
  125. foreach (var item in inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.inputKeys.inputKeyPressDic)
  126. {
  127. if (item.Key == InputKeyCode.Trigger)
  128. {
  129. //triggerKey.material = releaseMaterial;
  130. //if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  131. // triggerKey.material = pressMaterial;
  132. //}
  133. }
  134. else if (functionKey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction))
  135. {
  136. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
  137. {
  138. functionKey.material = pressMaterial;
  139. }
  140. else if (item.Value == InputKeyState.UP)
  141. {
  142. functionKey.material = releaseMaterial;
  143. }
  144. else if (item.Value == InputKeyState.TouchEnter) {
  145. functionKey.material = touchEnterMaterial;
  146. }
  147. else if (item.Value == InputKeyState.TouchExit)
  148. {
  149. functionKey.material = releaseMaterial;
  150. }
  151. }
  152. else if (axkey && (item.Key == InputKeyCode.X || item.Key == InputKeyCode.A))
  153. {
  154. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
  155. {
  156. axkey.material = pressMaterial;
  157. }
  158. else if (item.Value == InputKeyState.TouchEnter)
  159. {
  160. isAXkeyTouch=true;
  161. if (axkey.material != pressMaterial)
  162. {
  163. axkey.material = touchEnterMaterial;
  164. }
  165. }
  166. else if (item.Value == InputKeyState.TouchExit)
  167. {
  168. isAXkeyTouch = false;
  169. axkey.material = releaseMaterial;
  170. }
  171. else if (item.Value == InputKeyState.UP)
  172. {
  173. axkey.material = isAXkeyTouch ? touchEnterMaterial : releaseMaterial;
  174. }
  175. }
  176. else if (bykey && (item.Key == InputKeyCode.Y || item.Key == InputKeyCode.B))
  177. {
  178. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
  179. {
  180. bykey.material = pressMaterial;
  181. }
  182. else if (item.Value == InputKeyState.TouchEnter)
  183. {
  184. isBYkeyTouch = true;
  185. if (bykey.material != pressMaterial)
  186. {
  187. bykey.material = touchEnterMaterial;
  188. }
  189. }
  190. else if (item.Value == InputKeyState.TouchExit)
  191. {
  192. isBYkeyTouch = false;
  193. bykey.material = releaseMaterial;
  194. }
  195. else if (item.Value == InputKeyState.UP)
  196. {
  197. bykey.material = isBYkeyTouch ? touchEnterMaterial : releaseMaterial;
  198. }
  199. }
  200. else if (hallFoward && (item.Key == InputKeyCode.LHallForward || item.Key == InputKeyCode.RHallForward))
  201. {
  202. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
  203. {
  204. hallFoward.material = pressMaterial;
  205. }
  206. else if (item.Value == InputKeyState.TouchEnter)
  207. {
  208. isHFkeyTouch = true;
  209. hallFoward.material = touchEnterMaterial;
  210. }
  211. else if (item.Value == InputKeyState.TouchExit)
  212. {
  213. isHFkeyTouch = false;
  214. hallFoward.material = releaseMaterial;
  215. }
  216. else if (item.Value == InputKeyState.UP)
  217. {
  218. hallFoward.material = isHFkeyTouch ? touchEnterMaterial : releaseMaterial;
  219. }
  220. }
  221. else if (hallInside && (item.Key == InputKeyCode.LHallInside || item.Key == InputKeyCode.RHallInside))
  222. {
  223. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
  224. {
  225. hallInside.material = pressMaterial;
  226. }
  227. else if (item.Value == InputKeyState.UP)
  228. {
  229. hallInside.material = releaseMaterial;
  230. }
  231. else if (item.Value == InputKeyState.TouchEnter)
  232. {
  233. hallInside.material = touchEnterMaterial;
  234. }
  235. else if (item.Value == InputKeyState.TouchExit)
  236. {
  237. hallInside.material = releaseMaterial;
  238. }
  239. }
  240. else if (joystickKey && (item.Key == InputKeyCode.LjoystickKey || item.Key == InputKeyCode.RjoystickKey))
  241. {
  242. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG)
  243. {
  244. joystickKey.material = pressMaterial;
  245. }
  246. else if (item.Value == InputKeyState.TouchEnter)
  247. {
  248. isJSkeyTouch = true;
  249. joystickKey.material = touchEnterMaterial;
  250. }
  251. else if (item.Value == InputKeyState.TouchExit)
  252. {
  253. isJSkeyTouch = false;
  254. joystickKey.material = releaseMaterial;
  255. }
  256. else if (item.Value == InputKeyState.UP)
  257. {
  258. joystickKey.material = releaseMaterial;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }