ViveHandAnimator.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ViveHandAnimator : OvrHandAnimator
  5. {
  6. protected override void Start()
  7. {
  8. for (int i = 0; i < this.m_aryFingerData.Length; i++)
  9. {
  10. this.m_aryFingerData[i] = new OvrHandAnimator.FingerMorph();
  11. }
  12. List<Transform> list = new List<Transform>();
  13. this.FindChild(list, this.m_trRootGrasp);
  14. for (int j = 0; j < this.m_listRoot.Length; j++)
  15. {
  16. List<OvrHandAnimator.BonePair> list2 = new List<OvrHandAnimator.BonePair>();
  17. List<Transform> list3 = new List<Transform>();
  18. this.FindChild(list3, this.m_trFingerRoot[j]);
  19. using (List<Transform>.Enumerator enumerator = list3.GetEnumerator())
  20. {
  21. while (enumerator.MoveNext())
  22. {
  23. Transform trBase = enumerator.Current;
  24. Transform transform = list.Find((Transform a) => a.name == trBase.name);
  25. if (transform != null)
  26. {
  27. list2.Add(new OvrHandAnimator.BonePair(trBase, transform));
  28. }
  29. else
  30. {
  31. Debug.LogWarning("指ペアが見つかりません。" + trBase.name);
  32. }
  33. }
  34. }
  35. this.m_listRoot[j] = list2;
  36. }
  37. }
  38. public override void Init(AVRControllerButtons f_CtrlBtn)
  39. {
  40. this.m_CtrlBtn = f_CtrlBtn;
  41. }
  42. private void OnEnable()
  43. {
  44. this.OnChangeScreenSizeOrAA();
  45. }
  46. protected override void FindChild(List<Transform> f_list, Transform f_trParent)
  47. {
  48. for (int i = 0; i < f_trParent.childCount; i++)
  49. {
  50. this.FindChild(f_list, f_trParent.GetChild(i));
  51. }
  52. f_list.Add(f_trParent);
  53. }
  54. public override void FingerRateTarget(OvrHandAnimator.Finger f_eFinger, float f_fRate)
  55. {
  56. this.m_fTargetRate[(int)f_eFinger] = f_fRate;
  57. }
  58. protected override void FingerRateUpdate(OvrHandAnimator.Finger f_eFinger, float f_fRate)
  59. {
  60. OvrHandAnimator.FingerMorph fingerMorph = this.m_aryFingerData[(int)f_eFinger];
  61. fingerMorph.fTarget = f_fRate;
  62. float num = fingerMorph.fTarget - fingerMorph.fNow;
  63. float num2 = num * this.m_fEaseRate;
  64. fingerMorph.fNow += num2;
  65. List<OvrHandAnimator.BonePair> list = this.m_listRoot[(int)f_eFinger];
  66. for (int i = 0; i < list.Count; i++)
  67. {
  68. OvrHandAnimator.BonePair bonePair = list[i];
  69. bonePair.trMain.localRotation = Quaternion.Slerp(bonePair.qBackRot, bonePair.trGrasp.localRotation, fingerMorph.fNow);
  70. }
  71. }
  72. public void OnChangeScreenSizeOrAA()
  73. {
  74. bool flag = QualitySettings.antiAliasing == 0 && !GameMain.Instance.MainCamera.IsBloomEnabled;
  75. if (GameMain.Instance.VRMode && !GameMain.Instance.VRDummyMode)
  76. {
  77. flag = false;
  78. }
  79. foreach (Renderer renderer in base.transform.GetComponentsInChildren<Renderer>(true))
  80. {
  81. if (renderer == null || renderer.materials == null)
  82. {
  83. return;
  84. }
  85. foreach (Material material in renderer.materials)
  86. {
  87. if (flag)
  88. {
  89. material.EnableKeyword("UV_POS_REVERSE");
  90. material.DisableKeyword("UV_POS_NORMAL");
  91. }
  92. else
  93. {
  94. material.DisableKeyword("UV_POS_NORMAL");
  95. material.DisableKeyword("UV_POS_REVERSE");
  96. }
  97. }
  98. }
  99. }
  100. protected override void Update()
  101. {
  102. float triggerRate = this.m_CtrlBtn.GetTriggerRate();
  103. this.FingerRateTarget(OvrHandAnimator.Finger.Thumb, triggerRate);
  104. this.FingerRateTarget(OvrHandAnimator.Finger.Index, triggerRate);
  105. this.FingerRateTarget(OvrHandAnimator.Finger.Middle, triggerRate);
  106. this.FingerRateTarget(OvrHandAnimator.Finger.Ring, triggerRate);
  107. this.FingerRateTarget(OvrHandAnimator.Finger.Little, triggerRate);
  108. for (int i = 0; i < 5; i++)
  109. {
  110. this.FingerRateUpdate((OvrHandAnimator.Finger)i, this.m_fTargetRate[i]);
  111. }
  112. }
  113. }