using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using SC.XR.Unity.Module_InputSystem; using UnityEngine.Events; using UnityEngine.XR; namespace XRTool.Util { public class XBoundingBox : BoundingBox { private bool isJiXingScale = false; public bool IsJiXingScale { get => isJiXingScale; set { isJiXingScale = value; SetScaleModel(isJiXingScale); } } /// /// 设置边角的颜色(锁定) /// /// public void SetZoomColor(bool isLock, Color color) { List hands = new List(); hands.AddRange(SideBoundingBoxRoot.handles); hands.AddRange(CornerBoundingBoxRoot.handles); for (int i = 0; i < hands.Count; i++) { Handle handle = hands[i]; UnityUtil.ChangeMateColor(handle.visual.GetComponent(), color); handle.root.GetComponent().enabled = !isLock; } } /// /// 设置缩放模式 /// /// 是否是畸形缩放模式,true代表畸形,false代表整体缩放模式 public void SetScaleModel(bool isJiXing = true) { //if (!isJiXing) //{ // ActiveHandle = HandleType.Rotation | HandleType.Scale; //} //else //{ // ActiveHandle = HandleType.Rotation | HandleType.Scale | HandleType.AxisScale; //} } /// /// 获取相对于Point最近的点 /// /// /// public Vector3 GetCastPoint(Vector3 point) { Vector3 center = transform.position; if (SideBoundingBoxRoot != null && SideBoundingBoxRoot.handles != null) { point.y = center.y; center = SideBoundingBoxRoot.handles[0].visual.transform.position; float min = center.y; float minDis = Vector3.Distance(center, point); for (int i = 1; i < SideBoundingBoxRoot.handles.Length; i++) { float dis = Vector3.Distance(point, SideBoundingBoxRoot.handles[i].visual.transform.position); if (dis < minDis && Mathf.Abs(Vector3.Dot(Vector3.up, SideBoundingBoxRoot.handles[i].visual.transform.up)) < 0.5f) { center = SideBoundingBoxRoot.handles[i].visual.transform.position; minDis = dis; } if (SideBoundingBoxRoot.handles[i].visual.transform.position.y < min) { min = SideBoundingBoxRoot.handles[i].visual.transform.position.y; } } center.y = min; } return center; } } }