HandleControllerEffect.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace EZXR.Glass.Inputs
  5. {
  6. public class HandleControllerEffect : MonoBehaviour
  7. {
  8. public HandType handType;
  9. public Texture defaultTexture;
  10. public Texture[] activeTextures;
  11. public UnityEngine.Renderer[] activeRenderers;
  12. private HandleKeyCode[] allKeyCode = new HandleKeyCode[]
  13. {
  14. HandleKeyCode.Primary,
  15. HandleKeyCode.Secondary,
  16. HandleKeyCode.Return,
  17. HandleKeyCode.Grid,
  18. HandleKeyCode.Home,
  19. HandleKeyCode.Rocker,
  20. HandleKeyCode.Trigger
  21. };
  22. private void Update()
  23. {
  24. for (int i = 0; i < allKeyCode.Length; i++)
  25. {
  26. //按键Down/Up可能会受应用切后台影响而丢失状态监听,不能闭环
  27. //if (HandleControllerManager.Instance.GetButtonDown(handType, allKeyCode[i]))
  28. //{
  29. // if (i < activeTextures.Length && i < activeRenderers.Length)
  30. // activeRenderers[i].material.SetTexture("_MainTex", activeTextures[i]);
  31. //}
  32. //else if (HandleControllerManager.Instance.GetButtonUp(handType, allKeyCode[i]))
  33. //{
  34. // if (i < activeRenderers.Length)
  35. // activeRenderers[i].material.SetTexture("_MainTex", defaultTexture);
  36. //}
  37. if (HandleControllerManager.Instance.GetButton(handType, allKeyCode[i]))
  38. {
  39. if (i < activeTextures.Length && i < activeRenderers.Length)
  40. activeRenderers[i].material.SetTexture("_MainTex", activeTextures[i]);
  41. }
  42. else
  43. {
  44. if (i < activeRenderers.Length)
  45. activeRenderers[i].material.SetTexture("_MainTex", defaultTexture);
  46. }
  47. }
  48. }
  49. }
  50. }