123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 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);
- }
- }
- /// <summary>
- /// 设置边角的颜色(锁定)
- /// </summary>
- /// <param name="color"></param>
- public void SetZoomColor(bool isLock, Color color)
- {
- List<Handle> hands = new List<Handle>();
- 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<Renderer>(), color);
- handle.root.GetComponent<Collider>().enabled = !isLock;
- }
- }
- /// <summary>
- /// 设置缩放模式
- /// </summary>
- /// <param name="isJiXing">是否是畸形缩放模式,true代表畸形,false代表整体缩放模式</param>
- public void SetScaleModel(bool isJiXing = true)
- {
- //if (!isJiXing)
- //{
- // ActiveHandle = HandleType.Rotation | HandleType.Scale;
- //}
- //else
- //{
- // ActiveHandle = HandleType.Rotation | HandleType.Scale | HandleType.AxisScale;
- //}
- }
- /// <summary>
- /// 获取相对于Point最近的点
- /// </summary>
- /// <param name="point"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|