DummyVRHandAnimator.cs 4.1 KB

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