DragComponent.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. using SC.InputSystem;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. using DG.Tweening;
  8. using static SC.InputSystem.InputDeviceEventBase;
  9. public abstract class DragComponent : MonoBehaviour, ISCPointerDragHandler, ISCPointerEnterHandler, ISCPointerExitHandler, ISCPointerDownHandler,ISCPointerUpHandler, ISCBothHandPointerDownHandler, ISCBothHandPointerDragHandler, ISCBothHandPointerUpHandler
  10. {
  11. //空物体父体
  12. [HideInInspector]
  13. public GameObject parentGame;
  14. //空物体子体
  15. [HideInInspector]
  16. public GameObject childGame;
  17. //scale的模型集
  18. [HideInInspector]
  19. public List<GameObject> scaleGameList;
  20. //euler的模型集
  21. [HideInInspector]
  22. public List<GameObject> eulerGameList;
  23. [HideInInspector]
  24. public GameObject editGame;
  25. [HideInInspector]
  26. public BoxCollider box;
  27. [HideInInspector]
  28. public bool isBoth;
  29. private float initDis;
  30. float xishu = 1.1f;
  31. [HideInInspector]
  32. public Vector3 initPos;
  33. [HideInInspector]
  34. public Vector3 scale3;
  35. [HideInInspector]
  36. public Vector3 Tscale3;
  37. Vector3 dragInitLocalPosition = Vector3.zero;
  38. [HideInInspector]
  39. public LineRenderer lr;
  40. private Material mat;
  41. [HideInInspector]
  42. public float totalx;
  43. [HideInInspector]
  44. public float totaly;
  45. [HideInInspector]
  46. public float totalz;
  47. [HideInInspector]
  48. public Vector3[] veces;
  49. [HideInInspector]
  50. public int testIndex = 0;
  51. [HideInInspector]
  52. public bool isFangda;
  53. [HideInInspector]
  54. public Vector3 sScale;
  55. [HideInInspector]
  56. public Vector3 rScale;
  57. [HideInInspector]
  58. public Vector3 rotEurl;
  59. Vector3[] v3;
  60. [HideInInspector]
  61. public Material boxMaterial;
  62. [HideInInspector]
  63. public Material boxClickMaterial;
  64. private GameObject boxDisplay;
  65. public bool isVertexScale;
  66. [HideInInspector]
  67. public DragManager dm;
  68. [HideInInspector]
  69. public GameObject eulerGame;
  70. [HideInInspector]
  71. public GameObject scaleGame;
  72. [HideInInspector]
  73. public Material LineMaterial;
  74. public float LineSize = 0.005f;
  75. // 定义枚举
  76. [Serializable]
  77. public enum EditTypeEnum
  78. {
  79. [EnumAttirbute("无边框拖拽")]
  80. DEFECT = 0,
  81. [EnumAttirbute("有边框拖拽")]
  82. NORMAL = 1,
  83. [EnumAttirbute("旋转放大拖拽")]
  84. ALLEDIT = 2
  85. }
  86. // 定义枚举属性
  87. [EnumAttirbute("编辑类型")]
  88. public EditTypeEnum editType;
  89. // 定义枚举
  90. [Serializable]
  91. public enum EditManagerEnum
  92. {
  93. [EnumAttirbute("默认框")]
  94. Default = 0,
  95. [EnumAttirbute("自定义框")]
  96. Custom = 1
  97. }
  98. // 定义枚举属性
  99. [EnumAttirbute("材质类型")]
  100. public EditManagerEnum editManagerType;
  101. private bool initRib;
  102. private Dictionary<string, bool> partEnterList;
  103. private Dictionary<string, bool> partDownList;
  104. public virtual void Start()
  105. {
  106. partEnterList = new Dictionary<string, bool>();
  107. partDownList = new Dictionary<string, bool>();
  108. if (editManagerType == EditManagerEnum.Default)
  109. {
  110. dm = ((GameObject)Resources.Load("ShadowEidtBox")).GetComponent<DragManager>();
  111. }
  112. parentGame = new GameObject();
  113. parentGame.name = "parentGame_"+this.name;
  114. parentGame.transform.parent = this.transform.parent;
  115. parentGame.transform.localEulerAngles = new Vector3(0,0,0);
  116. childGame = new GameObject();
  117. childGame.name = "childGame";
  118. childGame.transform.parent = parentGame.transform;
  119. childGame.transform.localEulerAngles = new Vector3(0, 0, 0);
  120. editGame = new GameObject();
  121. editGame.name = "editGame";
  122. editGame.transform.parent = parentGame.transform;
  123. editGame.transform.localEulerAngles = new Vector3(0, 0, 0);
  124. scaleGameList = new List<GameObject>();
  125. eulerGameList = new List<GameObject>();
  126. boxMaterial = dm.boxMaterial;
  127. boxClickMaterial = dm.boxClickMaterial;
  128. box = this.GetComponent<BoxCollider>();
  129. lr = this.gameObject.AddComponent<LineRenderer>();
  130. LineMaterial = dm.LineMaterial;
  131. if (LineMaterial == null)
  132. {
  133. lr.material = new Material(Shader.Find("Standard"));
  134. }
  135. else
  136. {
  137. lr.material = LineMaterial;
  138. }
  139. lr.widthMultiplier = LineSize;
  140. scale3 = this.transform.localScale;
  141. Tscale3 = scale3;
  142. veces = GetBoxColliderVertexPositions(box);
  143. lr.positionCount =16;
  144. eulerGame = dm.eulerGame;
  145. scaleGame = dm.scaleGame;
  146. if (scaleGame != null)
  147. {
  148. createSaleGame();
  149. }
  150. if (eulerGame != null)
  151. {
  152. createEulerGame();
  153. }
  154. // AddBoxDisplay();
  155. InitEulerManager();
  156. InitScaleManager();
  157. HideBoxEdit();
  158. lr.enabled = false;
  159. }
  160. public void OnSCPointerEnter(InputDevicePartBase part, SCPointEventData eventData)
  161. {
  162. changeEnterPart(part.name,true);
  163. ShowBoxEdit();
  164. }
  165. public void OnSCPointerExit(InputDevicePartBase part, SCPointEventData eventData)
  166. {
  167. if (eventData.hitOtherPointer != null)
  168. {
  169. if (eventData.hitOtherPointer.transform.parent != null && eventData.hitOtherPointer.transform.parent.name == editGame.name)
  170. {
  171. return;
  172. }
  173. }
  174. changeEnterPart(part.name, false);
  175. if (isEnterChoose())
  176. {
  177. return;
  178. }
  179. HideBoxEdit();
  180. }
  181. public bool isEnterChoose()
  182. {
  183. foreach (KeyValuePair<string, bool> kv in partEnterList)
  184. {
  185. if (kv.Value)
  186. {
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. public void changeEnterPart(string name, bool choose)
  193. {
  194. if (!partEnterList.ContainsKey(name))
  195. {
  196. partEnterList.Add(name, choose);
  197. }
  198. else
  199. {
  200. partEnterList[name] = choose;
  201. }
  202. }
  203. public bool isDownChoose()
  204. {
  205. foreach (KeyValuePair<string, bool> kv in partDownList)
  206. {
  207. if (kv.Value)
  208. {
  209. return true;
  210. }
  211. }
  212. return false;
  213. }
  214. public void changeDownPart(string name, bool choose)
  215. {
  216. if (!partDownList.ContainsKey(name))
  217. {
  218. partDownList.Add(name, choose);
  219. }
  220. else
  221. {
  222. partDownList[name] = choose;
  223. }
  224. }
  225. public virtual void OnSCPointerDown(InputDevicePartBase part, SCPointEventData eventData)
  226. {
  227. try
  228. {
  229. changeDownPart(part.name,true);
  230. //dragInitLocalPosition = InputSystem.InputDeviceCurrent.inputDeviceUIBase.model.transform.InverseTransformPoint(transform.position);
  231. //doTweeningPos = InputSystem.InputDeviceCurrent.inputDeviceUIBase.model.transform.TransformPoint(dragInitLocalPosition);
  232. Rigidbody rb = this.GetComponent<Rigidbody>();
  233. if (rb!=null)
  234. {
  235. initRib = rb.isKinematic;
  236. rb.isKinematic = true;
  237. }
  238. switch (editType)
  239. {
  240. case EditTypeEnum.ALLEDIT:
  241. lr.enabled = true;
  242. // boxDisplay.SetActive(true);
  243. break;
  244. case EditTypeEnum.DEFECT:
  245. // boxDisplay.SetActive(false);
  246. break;
  247. case EditTypeEnum.NORMAL:
  248. lr.enabled = true;
  249. // boxDisplay.SetActive(true); ;
  250. break;
  251. }
  252. // ApplyMaterialToAllRenderers(boxDisplay, boxClickMaterial);
  253. HideBoxEdit();
  254. isMove = true;
  255. // InputDeviceEventBase.anyKeyUpDelegate += onUp;
  256. }
  257. catch (Exception e)
  258. {
  259. }
  260. }
  261. public virtual void OnSCPointerUp(InputDevicePartBase part, SCPointEventData eventData)
  262. {
  263. changeDownPart(part.name, false);
  264. if(isDownChoose())
  265. {
  266. return;
  267. }
  268. Rigidbody rb = this.GetComponent<Rigidbody>();
  269. if (rb != null)
  270. {
  271. rb.isKinematic = initRib;
  272. }
  273. ShowBoxEdit();
  274. lr.enabled = false;
  275. // InputDeviceEventBase.anyKeyUpDelegate -= onUp;
  276. isMove = false;
  277. }
  278. public virtual void OnSCPointerDrag(InputDevicePartBase part, SCPointEventData eventData)
  279. {
  280. if (!isBoth&& isMove)
  281. transform.position = eventData.dragSlowPosition;
  282. }
  283. private void AddBoxDisplay()
  284. {
  285. if (boxMaterial != null)
  286. {
  287. boxDisplay = GameObject.CreatePrimitive(PrimitiveType.Cube);
  288. Destroy(boxDisplay.GetComponent<Collider>());
  289. boxDisplay.SetActive(false);
  290. boxDisplay.name = "bounding box";
  291. ApplyMaterialToAllRenderers(boxDisplay, boxMaterial);
  292. boxDisplay.transform.parent = this.transform;
  293. boxDisplay.transform.localScale = box.size * xishu;
  294. boxDisplay.transform.localPosition = new Vector3(0,0,0);
  295. }
  296. }
  297. private static void ApplyMaterialToAllRenderers(GameObject root, Material material)
  298. {
  299. if (material != null)
  300. {
  301. Renderer[] renderers = root.GetComponentsInChildren<Renderer>();
  302. for (int i = 0; i < renderers.Length; ++i)
  303. {
  304. renderers[i].material = material;
  305. }
  306. }
  307. }
  308. public virtual void ShowBoxEdit()
  309. {
  310. // ApplyMaterialToAllRenderers(boxDisplay, boxMaterial);
  311. switch (editType)
  312. {
  313. case EditTypeEnum.ALLEDIT:
  314. editGame.SetActive(true);
  315. // boxDisplay.SetActive(true);
  316. // lr.enabled = true;
  317. changeLine();
  318. break;
  319. case EditTypeEnum.DEFECT:
  320. editGame.SetActive(false);
  321. // boxDisplay.SetActive(false);
  322. // lr.enabled = false;
  323. changeLine();
  324. break;
  325. case EditTypeEnum.NORMAL:
  326. editGame.SetActive(false);
  327. // boxDisplay.SetActive(true);
  328. // lr.enabled = true;
  329. changeLine();
  330. break;
  331. }
  332. }
  333. public virtual void HideBoxEdit()
  334. {
  335. editGame.SetActive(false);
  336. // lr.enabled = false;
  337. }
  338. public virtual void InitEulerManager()
  339. {
  340. if(eulerGameList.Count>11)
  341. {
  342. for (int i = 0; i < 12; i++)
  343. {
  344. if (i == 1 || i == 3 || i == 5 || i == 10)
  345. {
  346. eulerGameList[i].transform.localEulerAngles = new Vector3(0, 0, 90);
  347. }
  348. if (i == 0 || i == 2 || i == 6 || i == 7)
  349. {
  350. eulerGameList[i].transform.localEulerAngles = new Vector3(90, 0, 0);
  351. }
  352. }
  353. }
  354. }
  355. public virtual void InitScaleManager()
  356. {
  357. if(scaleGameList.Count>7)
  358. {
  359. for (int i = 0; i < 8; i++)
  360. {
  361. switch (i)
  362. {
  363. case 0:
  364. scaleGameList[i].transform.localEulerAngles = new Vector3(0, 90, 0);
  365. break;
  366. case 1:
  367. scaleGameList[i].transform.localEulerAngles = new Vector3(0, 180, 0);
  368. break;
  369. case 2:
  370. scaleGameList[i].transform.localEulerAngles = new Vector3(0, 0, 0);
  371. break;
  372. case 3:
  373. scaleGameList[i].transform.localEulerAngles = new Vector3(-90, 0, 0);
  374. break;
  375. case 4:
  376. scaleGameList[i].transform.localEulerAngles = new Vector3(90, 90, 0);
  377. break;
  378. case 5:
  379. scaleGameList[i].transform.localEulerAngles = new Vector3(90, 90, -90);
  380. break;
  381. case 6:
  382. scaleGameList[i].transform.localEulerAngles = new Vector3(90, 0, 0);
  383. break;
  384. case 7:
  385. scaleGameList[i].transform.localEulerAngles = new Vector3(90, -90, 0);
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. private void createEulerGame()
  392. {
  393. GameObject go;
  394. RotManager rm;
  395. for (int i = 0; i <12; i++)
  396. {
  397. go = GameObject.Instantiate(eulerGame);
  398. go.SetActive(true);
  399. rm = go.AddComponent<RotManager>();
  400. rm.index = i;
  401. rm.dc = this;
  402. // rm.model.transform.localEulerAngles = new Vector3() ;
  403. go.transform.parent = editGame.transform;
  404. rScale = go.transform.localScale;
  405. eulerGameList.Add(go);
  406. }
  407. }
  408. private Vector3 scInputPos;
  409. void createSaleGame()
  410. {
  411. GameObject go;
  412. for (int i = 0; i < veces.Length; i++)
  413. {
  414. go = GameObject.Instantiate(scaleGame);
  415. go.SetActive(true);
  416. go.AddComponent<ScaleManager>();
  417. go.GetComponent<ScaleManager>().index = i;
  418. go.GetComponent<ScaleManager>().dc = this;
  419. // rm.model.transform.localEulerAngles = new Vector3();
  420. go.transform.parent = editGame.transform;
  421. sScale = go.transform.localScale;
  422. scaleGameList.Add(go);
  423. }
  424. }
  425. public void OnDrag( PointerEventData eventData ) {
  426. try
  427. {
  428. } catch(Exception e) {
  429. }
  430. }
  431. private void moveTW()
  432. {
  433. // doTweeningPos = InputSystem.InputDeviceCurrent.inputDeviceUIBase.model.transform.TransformPoint(dragInitLocalPosition);
  434. tw = this.transform.DOMove(doTweeningPos, 0.2f).OnComplete(moveTW);
  435. }
  436. private Vector3 doTweeningPos;
  437. public bool isMove;
  438. Tweener tw;
  439. public virtual void OnPointerDown( PointerEventData eventData ) {
  440. }
  441. public virtual void onUp(InputKeyCode keyCode)
  442. {
  443. // ApplyMaterialToAllRenderers(boxDisplay, boxMaterial);
  444. ShowBoxEdit();
  445. tw.Kill(false);
  446. // InputDeviceEventBase.anyKeyUpDelegate -= onUp;
  447. isMove = false;
  448. }
  449. public void OnPointerUp( PointerEventData eventData ) {
  450. }
  451. public virtual void Update()
  452. {
  453. if (isMove)
  454. {
  455. // doTweeningPos = InputSystem.InputDeviceCurrent.inputDeviceUIBase.model.transform.TransformPoint(dragInitLocalPosition);
  456. // Debug.Log(Vector3.Lerp(doTweeningPos, this.transform.position,Time.deltaTime*10));
  457. // this.transform.position = InputSystem.InputDeviceCurrent.inputDeviceUIBase.model.transform.TransformPoint(dragInitLocalPosition);
  458. }
  459. if (isVertexScale)
  460. {
  461. changePos();
  462. }
  463. }
  464. private void changePos()
  465. {
  466. if(isFangda)
  467. {
  468. Vector3 position = -new Vector3((1) * (totalx * 0.5f - totalx * (box.transform.localScale.x) * 0.5f), (1) * (totaly * 0.5f - totaly * (box.transform.localScale.y) * 0.5f), (1) * (totalz * 0.5f - totalz * (box.transform.localScale.z) * 0.5f)) - box.center * box.transform.localScale.x; // left justified;
  469. this.transform.localPosition = initPos+ position + changeOfferSize() + changeOfferPos();
  470. }
  471. }
  472. public void changeLine()
  473. {
  474. veces = GetBoxColliderVertexPositions(box, xishu);
  475. lr.SetPosition(0, veces[0]);
  476. lr.SetPosition(1, veces[1]);
  477. lr.SetPosition(2, veces[3]);
  478. lr.SetPosition(3, veces[2]);
  479. lr.SetPosition(4, veces[0]);
  480. lr.SetPosition(5, veces[4]);
  481. lr.SetPosition(6, veces[6]);
  482. lr.SetPosition(7, veces[7]);
  483. lr.SetPosition(8, veces[5]);
  484. lr.SetPosition(9, veces[4]);
  485. lr.SetPosition(10, veces[6]);
  486. lr.SetPosition(11, veces[2]);
  487. lr.SetPosition(12, veces[3]);
  488. lr.SetPosition(13, veces[7]);
  489. lr.SetPosition(14, veces[5]);
  490. lr.SetPosition(15, veces[1]);
  491. for (int i = 0; i < veces.Length; i++)
  492. {
  493. if (scaleGameList.Count > i)
  494. {
  495. scaleGameList[i].transform.position = veces[i];
  496. }
  497. }
  498. eulerGameList[0].transform.position = (veces[0] + veces[1]) / 2;
  499. eulerGameList[1].transform.position = (veces[1] + veces[3]) / 2;
  500. eulerGameList[2].transform.position = (veces[3] + veces[2]) / 2;
  501. eulerGameList[3].transform.position = (veces[2] + veces[0]) / 2;
  502. eulerGameList[4].transform.position = (veces[0] + veces[4]) / 2;
  503. eulerGameList[5].transform.position = (veces[4] + veces[6]) / 2;
  504. eulerGameList[6].transform.position = (veces[6] + veces[7]) / 2;
  505. eulerGameList[7].transform.position = (veces[5] + veces[4]) / 2;
  506. eulerGameList[8].transform.position = (veces[6] + veces[2]) / 2;
  507. eulerGameList[9].transform.position = (veces[3] + veces[7]) / 2;
  508. eulerGameList[10].transform.position = (veces[5] + veces[7]) / 2;
  509. eulerGameList[11].transform.position = (veces[5] + veces[1]) / 2;
  510. }
  511. public Vector3 changeOfferPos()
  512. {
  513. Vector3 vOfferPos = new Vector3(0, 0, 0);
  514. vOfferPos = new Vector3((box.center.x) * this.scale3.x, (box.center.y) * this.scale3.y, (box.center.z) * this.scale3.z);
  515. return vOfferPos;
  516. }
  517. public Vector3 changeOfferSize()
  518. {
  519. Vector3 vOfferSize = new Vector3(0,0,0);
  520. float offX = box.size.x;
  521. float offY = box.size.y;
  522. float offZ = box.size.z;
  523. switch (testIndex)
  524. {
  525. case 0:
  526. vOfferSize = new Vector3((box.size.x / 2f * (1 - scale3.x)), (box.size.y / 2f * (1 - scale3.y)), (box.size.z / 2f * (1 - scale3.z)));
  527. break;
  528. case 1:
  529. vOfferSize = new Vector3((box.size.x / 2f * (1-scale3.x)), (box.size.y / 2f * (1 - scale3.y)), -(box.size.z / 2f * (1 - scale3.z)));
  530. break;
  531. case 2:
  532. vOfferSize = new Vector3(-(box.size.x / 2f * (1 - scale3.x)), (box.size.y / 2f * (1 - scale3.y)), (box.size.z / 2f * (1 - scale3.z)));
  533. break;
  534. case 3:
  535. vOfferSize = new Vector3(-(box.size.x / 2f * (1 - scale3.x)), (box.size.y / 2f * (1 - scale3.y)), -(box.size.z / 2f * (1 - scale3.z)));
  536. break;
  537. case 4:
  538. vOfferSize = new Vector3((box.size.x / 2f * (1 - scale3.x)), -(box.size.y / 2f * (1 - scale3.y)), (box.size.z / 2f * (1 - scale3.z)));
  539. break;
  540. case 5:
  541. vOfferSize = new Vector3((box.size.x / 2f * (1 - scale3.x)), -(box.size.y / 2f * (1 - scale3.y)), -(box.size.z / 2f * (1 - scale3.z)));
  542. break;
  543. case 6:
  544. vOfferSize = new Vector3(-(box.size.x / 2f * (1 - scale3.x)), -(box.size.y / 2f * (1 - scale3.y)), (box.size.z / 2f * (1 - scale3.z)));
  545. break;
  546. case 7:
  547. vOfferSize = new Vector3(-(box.size.x / 2f * (1 - scale3.x)), -(box.size.y / 2f * (1 - scale3.y)), -(box.size.z / 2f * (1 - scale3.z)));
  548. break;
  549. }
  550. return vOfferSize;
  551. }
  552. Vector3[] GetBoxColliderVertexPositions(BoxCollider boxcollider,float xishu=1)
  553. {
  554. var vertices = new Vector3[8];
  555. //上面4个点
  556. vertices[0] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(boxcollider.size.x, boxcollider.size.y, boxcollider.size.z) * 0.5f * xishu);
  557. vertices[1] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(boxcollider.size.x, boxcollider.size.y, -boxcollider.size.z) * 0.5f * xishu);
  558. vertices[2] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(-boxcollider.size.x, boxcollider.size.y, boxcollider.size.z) * 0.5f * xishu);
  559. vertices[3] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(-boxcollider.size.x, boxcollider.size.y, -boxcollider.size.z) * 0.5f * xishu);
  560. //下面4个点
  561. vertices[4] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(boxcollider.size.x, -boxcollider.size.y, boxcollider.size.z) * 0.5f * xishu);
  562. vertices[6] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(-boxcollider.size.x, -boxcollider.size.y, boxcollider.size.z) * 0.5f * xishu) ;
  563. vertices[7] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(-boxcollider.size.x, -boxcollider.size.y, -boxcollider.size.z) * 0.5f * xishu) ;
  564. vertices[5] = boxcollider.transform.TransformPoint(boxcollider.center + new Vector3(boxcollider.size.x, -boxcollider.size.y, -boxcollider.size.z) * 0.5f * xishu) ;
  565. return vertices;
  566. }
  567. public void changeTotal(int indexType)
  568. {
  569. testIndex = indexType;
  570. v3 = GetBoxColliderVertexPositions(box);
  571. switch (indexType)
  572. {
  573. //右上1
  574. case 0:
  575. totalx = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  576. totaly = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  577. totalz = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  578. break;
  579. //右上2
  580. case 1:
  581. totalx = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  582. totaly = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  583. totalz = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  584. break;
  585. //左上1
  586. case 2:
  587. totalx = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  588. totaly = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  589. totalz = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  590. break;
  591. //左上2
  592. case 3:
  593. totalx = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  594. totaly = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  595. totalz = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  596. break;
  597. //右下1
  598. case 4:
  599. totalx = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  600. totaly = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  601. totalz = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  602. break;
  603. //右下2
  604. case 5:
  605. totalx = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  606. totaly = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  607. totalz = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  608. break;
  609. //左下1
  610. case 6:
  611. totalx = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  612. totaly = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  613. totalz = Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  614. break;
  615. //左下2
  616. case 7:
  617. totalx = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[2]));
  618. totaly = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[4]));
  619. totalz = -Vector3.Distance(box.transform.InverseTransformPoint(v3[0]), box.transform.InverseTransformPoint(v3[1]));
  620. break;
  621. }
  622. }
  623. private float initDisRot;
  624. private Vector3 initBothRot;
  625. public void OnSCBothHandPointerDown(InputDevicePartBase part1, SCPointEventData part1EventData, InputDevicePartBase part2, SCPointEventData part2EventData)
  626. {
  627. switch (editType)
  628. {
  629. case EditTypeEnum.ALLEDIT:
  630. isBoth = true;
  631. changeLine();
  632. break;
  633. }
  634. switch (editType)
  635. {
  636. case EditTypeEnum.ALLEDIT:
  637. break;
  638. case EditTypeEnum.DEFECT:
  639. break;
  640. case EditTypeEnum.NORMAL:
  641. break;
  642. }
  643. initDis = SvrManager.Instance.head.InverseTransformPoint(part1.inputDeviceUIBase.model.lineIndicate.StartPoint.position).x - SvrManager.Instance.head.InverseTransformPoint(part2.inputDeviceUIBase.model.lineIndicate.StartPoint.position).x;
  644. initDisRot = SvrManager.Instance.head.InverseTransformPoint(part1.inputDeviceUIBase.model.lineIndicate.StartPoint.position).z- SvrManager.Instance.head.InverseTransformPoint(part2.inputDeviceUIBase.model.lineIndicate.StartPoint.position).z;
  645. scale3 = this.transform.localScale;
  646. this.sScale = this.scaleGameList[0].transform.localScale;
  647. this.rScale = this.eulerGameList[0].transform.localScale;
  648. initBothRot = this.transform.eulerAngles;
  649. }
  650. public TextMesh text;
  651. public void OnSCBothHandPointerDrag(InputDevicePartBase part1, SCPointEventData part1EventData, InputDevicePartBase part2, SCPointEventData part2EventData)
  652. {
  653. if(isBoth)
  654. {
  655. float disRot = SvrManager.Instance.head.InverseTransformPoint(part1.inputDeviceUIBase.model.lineIndicate.StartPoint.position).z - SvrManager.Instance.head.InverseTransformPoint(part2.inputDeviceUIBase.model.lineIndicate.StartPoint.position).z;
  656. float dis = SvrManager.Instance.head.InverseTransformPoint(part1.inputDeviceUIBase.model.lineIndicate.StartPoint.position).x - SvrManager.Instance.head.InverseTransformPoint(part2.inputDeviceUIBase.model.lineIndicate.StartPoint.position).x;
  657. float aaa = Mathf.Abs(disRot - initDisRot);
  658. float bbb = Mathf.Abs(dis - initDis);
  659. if (aaa < bbb&& bbb>0.01f)
  660. {
  661. float perValue = dis / initDis;
  662. if ((scale3 * perValue).x > (Tscale3 / 5).x && (scale3 * perValue).x < (Tscale3 * 5).x)
  663. {
  664. this.transform.localScale = scale3 * (perValue);
  665. this.lr.widthMultiplier = this.LineSize * (perValue);
  666. for (int i = 0; i < this.veces.Length; i++)
  667. {
  668. this.scaleGameList[i].transform.localScale = this.sScale * (perValue);
  669. }
  670. for (int i = 0; i < 12; i++)
  671. {
  672. this.eulerGameList[i].transform.localScale = this.rScale * (perValue);
  673. }
  674. }
  675. initDisRot = SvrManager.Instance.head.InverseTransformPoint(part1.inputDeviceUIBase.model.lineIndicate.StartPoint.position).z - SvrManager.Instance.head.InverseTransformPoint(part2.inputDeviceUIBase.model.lineIndicate.StartPoint.position).z;
  676. }
  677. else if(Mathf.Abs(disRot - initDisRot) * 200>5)
  678. {
  679. initDis = SvrManager.Instance.head.InverseTransformPoint(part1.inputDeviceUIBase.model.lineIndicate.StartPoint.position).x - SvrManager.Instance.head.InverseTransformPoint(part2.inputDeviceUIBase.model.lineIndicate.StartPoint.position).x;
  680. this.transform.eulerAngles = new Vector3(initBothRot.x, initBothRot.y + (disRot - initDisRot) * 200, initBothRot.z);
  681. this.changeLine();
  682. }
  683. }
  684. }
  685. public void OnSCBothHandPointerUp(InputDevicePartBase part1, SCPointEventData part1EventData, InputDevicePartBase part2, SCPointEventData part2EventData)
  686. {
  687. isBoth = false;
  688. this.parentGame.transform.eulerAngles = this.transform.eulerAngles;
  689. isMove = false;
  690. // this.changeLine();
  691. }
  692. }