ScaleManager.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using SC.InputSystem;
  2. using SC.InputSystem.InputDeviceHandShank;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. public class ScaleManager : ChangeFcous
  9. {
  10. [HideInInspector]
  11. public DragComponent dc;
  12. //[HideInInspector]
  13. public int index;
  14. [HideInInspector]
  15. public float perValue;
  16. // Start is called before the first frame update
  17. SCButton scbt;
  18. void Start()
  19. {
  20. if(dc!=null)
  21. {
  22. }
  23. model = dc.dm.focusScalModel;
  24. // scbt = this.gameObject.AddComponent<SCButton>();
  25. // UnityEvent onSCDown = new UnityEvent();
  26. // onSCDown.AddListener(onDown);
  27. // scbt.onDown = onSCDown;
  28. }
  29. public override void OnSCPointerExit(InputDevicePartBase part, SCPointEventData eventData)
  30. {
  31. base.OnSCPointerExit(part, eventData);
  32. dc.changeEnterPart(part.name,false);
  33. if (!dc.isEnterChoose())
  34. dc.HideBoxEdit();
  35. }
  36. override public void OnSCPointerDown(InputDevicePartBase part, SCPointEventData eventData)
  37. {
  38. onDown();
  39. dragInitLocalPosition = eventData.dragPosition;
  40. //Debug.Log("xlv3Down===========》" + dragInitLocalPosition);
  41. }
  42. override public void OnSCPointerUp(InputDevicePartBase part, SCPointEventData eventData)
  43. {
  44. onUp();
  45. }
  46. override public void OnSCPointerDrag(InputDevicePartBase part, SCPointEventData eventData)
  47. {
  48. if (!dc.isBoth && !dc.isMove && isDown)
  49. {
  50. float temp = 0;
  51. float temp2 = 0;
  52. float temp3 = 0;
  53. Vector3 poslocal = eventData.dragPosition;
  54. Vector3 xlv3 = GetNormal(dragInitLocalPosition, poslocal);
  55. //Debug.Log("xlv3===========》"+xlv3);
  56. // xlv3 = new Vector3(xlv3.x, xlv3.y, 0);
  57. // xlv3 = dc.testRot2.transform.InverseTransformPoint(xlv3);
  58. temp = xlv3.x;
  59. temp2 = xlv3.y;
  60. temp3 = xlv3.z;
  61. float xishu = 0.7f;
  62. switch (index)
  63. {
  64. case 0:
  65. perValue = (1 + (temp + temp2 + temp3) * xishu);
  66. break;
  67. case 1:
  68. perValue = (1 + (temp + temp2 - temp3) * xishu);
  69. break;
  70. case 2:
  71. perValue = (1 + (-temp + temp2 + temp3) * xishu);
  72. break;
  73. case 3:
  74. perValue = (1 + (-temp + temp2 - temp3) * xishu);
  75. break;
  76. case 4:
  77. perValue = (1 + (temp - temp2 - temp3) * xishu);
  78. break;
  79. case 5:
  80. perValue = (1 + (temp - temp2 - temp3) * xishu);
  81. break;
  82. case 6:
  83. perValue = (1 + (-temp - temp2 + temp3) * xishu);
  84. break;
  85. case 7:
  86. perValue = (1 + (-temp - temp2 - temp3) * xishu);
  87. break;
  88. }
  89. if ((dc.scale3 * perValue).x > (dc.Tscale3 / 5).x && (dc.scale3 * perValue).x < (dc.Tscale3 * 5).x)
  90. {
  91. dc.transform.localScale = dc.scale3 * (perValue);
  92. dc.lr.widthMultiplier = dc.LineSize * (perValue);
  93. if (dc.transform != dc.editGame.transform.parent)
  94. {
  95. for (int i = 0; i < dc.veces.Length; i++)
  96. {
  97. dc.scaleGameList[i].transform.localScale = dc.sScale * (perValue);
  98. }
  99. for (int i = 0; i < 12; i++)
  100. {
  101. dc.eulerGameList[i].transform.localScale = dc.rScale * (perValue);
  102. }
  103. }
  104. }
  105. dc.changeLine();
  106. }
  107. else
  108. {
  109. dc.isFangda = false;
  110. }
  111. }
  112. private void onUp()
  113. {
  114. // InputDeviceEventBase.anyKeyUpDelegate -= onUp;
  115. isDown = false;
  116. dc.isFangda = false;
  117. dc.box.enabled = true;
  118. dc.transform.parent = dc.parentGame.transform.parent;
  119. for (int i = 0; i < dc.veces.Length; i++)
  120. {
  121. dc.scaleGameList[i].GetComponent<BoxCollider>().enabled = true;
  122. }
  123. for (int i = 0; i < 12; i++)
  124. {
  125. dc.eulerGameList[i].GetComponent<BoxCollider>().enabled = true;
  126. }
  127. dc.ShowBoxEdit();
  128. }
  129. Vector3 GetNormal(Vector3 b, Vector3 c)
  130. {
  131. b = dc.childGame.transform.InverseTransformPoint(b);
  132. c = dc.childGame.transform.InverseTransformPoint(c);
  133. return c - b;
  134. }
  135. Vector3 dragInitLocalPosition;
  136. Vector3 dragInitLocalPosition2;
  137. // Update is called once per frame
  138. Vector3 nowxz = new Vector3(0, 0, 0);
  139. override public void Update()
  140. {
  141. this.model.transform.LookAt(SvrManager.Instance.head);
  142. this.model.transform.eulerAngles = new Vector3(this.model.transform.eulerAngles.x, this.model.transform.eulerAngles.y, this.model.transform.eulerAngles.z + this.transform.localEulerAngles.z);
  143. }
  144. private bool isDown;
  145. public void onDown()
  146. {
  147. /*
  148. for (int i = 0; i < dc.veces.Length; i++)
  149. {
  150. dc.scaleGameList[i].GetComponent<BoxCollider>().enabled = false;
  151. }
  152. for (int i = 0; i < 12; i++)
  153. {
  154. dc.eulerGameList[i].GetComponent<BoxCollider>().enabled = false;
  155. }*/
  156. // InputDeviceEventBase.anyKeyUpDelegate += onUp;
  157. dc.changeTotal(index);
  158. dc.isFangda = true;
  159. dc.parentGame.transform.localEulerAngles = dc.transform.localEulerAngles;
  160. dc.transform.parent = dc.parentGame.transform;
  161. dc.scale3 = dc.transform.localScale;
  162. dc.sScale = dc.scaleGameList[0].transform.localScale;
  163. dc.rScale = dc.eulerGameList[0].transform.localScale;
  164. dc.LineSize = dc.lr.widthMultiplier;
  165. dc.rotEurl = dc.transform.localEulerAngles;
  166. dc.childGame.transform.localEulerAngles = new Vector3(0, 0, 0);
  167. dc.childGame.transform.localScale = dc.transform.localScale;
  168. dc.initPos = dc.transform.localPosition;
  169. // dc.box.enabled = false;
  170. isDown = true;
  171. }
  172. }