XBoundingBox.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using SC.XR.Unity.Module_InputSystem;
  6. using UnityEngine.Events;
  7. using UnityEngine.XR;
  8. namespace XRTool.Util
  9. {
  10. public class XBoundingBox : BoundingBox
  11. {
  12. private bool isJiXingScale = false;
  13. public bool IsJiXingScale
  14. {
  15. get => isJiXingScale;
  16. set
  17. {
  18. isJiXingScale = value;
  19. SetScaleModel(isJiXingScale);
  20. }
  21. }
  22. /// <summary>
  23. /// 设置边角的颜色(锁定)
  24. /// </summary>
  25. /// <param name="color"></param>
  26. public void SetZoomColor(bool isLock, Color color)
  27. {
  28. Debug.Log("SetZoomColor " + isLock);
  29. List<Handle> hands = new List<Handle>();
  30. hands.AddRange(SideBoundingBoxRoot.handles);
  31. hands.AddRange(CornerBoundingBoxRoot.handles);
  32. for (int i = 0; i < hands.Count; i++)
  33. {
  34. Handle handle = hands[i];
  35. UnityUtil.ChangeMateColor(handle.visual.GetComponent<Renderer>(), color);
  36. handle.root.GetComponent<Collider>().enabled = !isLock;
  37. }
  38. }
  39. /// <summary>
  40. /// 设置缩放模式
  41. /// </summary>
  42. /// <param name="isJiXing">是否是畸形缩放模式,true代表畸形,false代表整体缩放模式</param>
  43. public void SetScaleModel(bool isJiXing = true)
  44. {
  45. //if (!isJiXing)
  46. //{
  47. // ActiveHandle = HandleType.Rotation | HandleType.Scale;
  48. //}
  49. //else
  50. //{
  51. // ActiveHandle = HandleType.Rotation | HandleType.Scale | HandleType.AxisScale;
  52. //}
  53. }
  54. /// <summary>
  55. /// 获取相对于Point最近的点
  56. /// </summary>
  57. /// <param name="point"></param>
  58. /// <returns></returns>
  59. public Vector3 GetCastPoint(Vector3 point)
  60. {
  61. Vector3 center = transform.position;
  62. if (SideBoundingBoxRoot != null && SideBoundingBoxRoot.handles != null)
  63. {
  64. point.y = center.y;
  65. center = SideBoundingBoxRoot.handles[0].visual.transform.position;
  66. float min = center.y;
  67. float minDis = Vector3.Distance(center, point);
  68. for (int i = 1; i < SideBoundingBoxRoot.handles.Length; i++)
  69. {
  70. float dis = Vector3.Distance(point, SideBoundingBoxRoot.handles[i].visual.transform.position);
  71. if (dis < minDis && Mathf.Abs(Vector3.Dot(Vector3.up, SideBoundingBoxRoot.handles[i].visual.transform.up)) < 0.5f)
  72. {
  73. center = SideBoundingBoxRoot.handles[i].visual.transform.position;
  74. minDis = dis;
  75. }
  76. if (SideBoundingBoxRoot.handles[i].visual.transform.position.y < min)
  77. {
  78. min = SideBoundingBoxRoot.handles[i].visual.transform.position.y;
  79. }
  80. }
  81. center.y = min;
  82. }
  83. return center;
  84. }
  85. }
  86. }