123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- using BeinLab.Util;
- using DG.Tweening;
- using SC.XR.Unity.Module_InputSystem;
- using ShadowStudio.Model;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using XRTool.Util;
- namespace ShadowStudio.Tool
- {
- ///// <summary>
- ///// 编辑状态
- ///// </summary>
- //public enum TransferState
- //{
- // Start = 0,
- // Doing = 1,
- // Stop = 2
- //}
- //[RequireComponent(typeof(XBoundingBox))]
- //[RequireComponent(typeof(XDragComponent))]
- public class TransferComponent : MonoBehaviour/*, IPointerDownHandler*/
- {
- //[SerializeField]
- ///// <summary>
- ///// 是否垂直水平面
- ///// </summary>
- //private bool isLookHead;
- ///// <summary>
- ///// 拖拽事件
- ///// </summary>
- //public event Action<TransferState> DragTransfer;
- ///// <summary>
- ///// 缩放事件
- ///// </summary>
- //public event Action<TransferState> ZoomTransfer;
- ///// <summary>
- ///// 旋转事件
- ///// </summary>
- //public event Action<TransferState> RoteTransfer;
- ///// <summary>
- ///// 编辑事件
- ///// 当物体进行拖拽,缩放,旋转时都会触发
- ///// </summary>
- //public event Action<TransferState> EditTransfer;
- ///// <summary>
- ///// 选中和非选中的事件
- ///// </summary>
- //public event Action<TransferComponent, bool> TransferSelect;
- //public static TransferComponent curActiveCell;
- //private XDragComponent dragCell;
- //private XBoundingBox boundBox;
- //private Coroutine editCoroutine;
- //private bool isLock;
- ///// <summary>
- ///// 编辑模式
- ///// -1代表未编辑
- ///// 0代表拖拽
- ///// 1代表旋转
- ///// 2代表缩放
- ///// 开始前/结束后要设置为-1
- ///// 开始后到执行中设置对应的状态
- ///// </summary>
- //private int editType = -1;
- //private Timer dragTimer;
- //public float autoDisDrag = 5f;
- //private Stack<Posture> postureHistroy;
- //private Stack<Posture> postureFuture;
- //private GameObject boundCell;
- //[SerializeField]
- //private bool isDragEnable;
- ///// <summary>
- ///// 后退的栈
- ///// </summary>
- //public Stack<Posture> PostureBack
- //{
- // get
- // {
- // if (postureHistroy == null)
- // {
- // postureHistroy = new Stack<Posture>();
- // }
- // return postureHistroy;
- // }
- //}
- ///// <summary>
- ///// 前进的栈
- ///// </summary>
- //public Stack<Posture> PostureAhead
- //{
- // get
- // {
- // if (postureFuture == null)
- // {
- // postureFuture = new Stack<Posture>();
- // }
- // return postureFuture;
- // }
- //}
- ///// <summary>
- ///// 锁定
- ///// </summary>
- //public bool IsLock
- //{
- // get
- // {
- // return isLock;
- // }
- // set
- // {
- // isLock = value;
- // if (isLock)
- // {
- // PostureAhead.Clear();
- // PostureBack.Clear();
- // IsDragEnable = false;
- // SetBoundActive(true);
- // SetBoundColor(value, Color.yellow);
- // }
- // else
- // {
- // SetBoundColor(value, Color.white);
- // if (curActiveCell != this)
- // {
- // SetBoundActive(false);
- // }
- // }
- // }
- //}
- ///// <summary>
- ///// 拖拽组件
- ///// </summary>
- //public XDragComponent DragCell
- //{
- // get
- // {
- // if (!dragCell)
- // {
- // dragCell = GetComponent<XDragComponent>();
- // dragCell.PointerDrag.AddListener(OnPointerDrag);
- // //dragCell.PointerDown.AddListener(OnPointerDown);
- // dragCell.PointerUp.AddListener(OnPointerUp);
- // }
- // return dragCell;
- // }
- //}
- ///// <summary>
- ///// 包围盒显示对象
- ///// </summary>
- //public GameObject BoundCell
- //{
- // get
- // {
- // if (!boundCell)
- // {
- // boundCell = UnityUtil.GetBreadthChild(transform, "XRTool.Util.XBoundingBox");
- // }
- // return boundCell;
- // }
- //}
- ///// <summary>
- ///// 包围盒算法组件
- ///// </summary>
- //public XBoundingBox BoundBox
- //{
- // get
- // {
- // if (!boundBox)
- // {
- // boundBox = GetComponent<XBoundingBox>();
- // if (!boundBox)
- // {
- // UnityLog.Instance.LogError(gameObject.name + "this is no XBoundingBox");
- // }
- // else
- // {
- // DragTransfer += state => { EditTransfer?.Invoke(state); };
- // ZoomTransfer += state => { EditTransfer?.Invoke(state); };
- // RoteTransfer += state => { EditTransfer?.Invoke(state); };
- // EditTransfer += OnEditTransfer;
- // boundBox.ScaleStarted.AddListener(OnScaleStarted);
- // boundBox.ScaleStopped.AddListener(OnScaleStopped);
- // boundBox.RotateStarted.AddListener(OnRotateStarted);
- // boundBox.RotateStopped.AddListener(OnRotateStopped);
- // }
- // }
- // return boundBox;
- // }
- //}
- //public void SetBoundActive(bool isShow)
- //{
- // if (BoundCell)
- // {
- // BoundCell.SetActive(isShow);
- // }
- //}
- ///// <summary>
- ///// 初始化
- ///// </summary>
- //private void Start()
- //{
- // if (BoundBox)
- // {
- // TimerMgr.Instance.CreateTimer(() =>
- // {
- // IsDragEnable = false;
- // }, 0);
- // }
- //}
- ///// <summary>
- ///// 当编辑物体的时候
- ///// </summary>
- ///// <param name="state"></param>
- //private void OnEditTransfer(TransferState state)
- //{
- // if (state == TransferState.Start)
- // {
- // ClearTime();
- // AddBackNode(UnityUtil.GetPosture(transform));
- // }
- // if (state == TransferState.Stop)
- // {
- // ClearTime();
- // if (autoDisDrag > 0)
- // {
- // dragTimer = TimerMgr.Instance.CreateTimer(() => { IsDragEnable = false; }, autoDisDrag);
- // }
- // }
- // print(editType + "__" + state);
- //}
- ///// <summary>
- ///// 清除协程
- ///// </summary>
- //private void ClearEditor()
- //{
- // if (editCoroutine != null)
- // {
- // StopCoroutine(editCoroutine);
- // editCoroutine = null;
- // }
- //}
- ///// <summary>
- ///// 旋转结束
- ///// </summary>
- //private void OnRotateStopped()
- //{
- // ClearEditor();
- // RoteTransfer?.Invoke(TransferState.Stop);
- // editType = -1;
- //}
- ///// <summary>
- ///// 旋转开始
- ///// </summary>
- //private void OnRotateStarted()
- //{
- // ClearEditor();
- // RoteTransfer?.Invoke(TransferState.Start);
- // editCoroutine = StartCoroutine(EditorCoroutine(1));
- //}
- ///// <summary>
- ///// 缩放结束
- ///// </summary>
- //private void OnScaleStopped()
- //{
- // ClearEditor();
- // ZoomTransfer?.Invoke(TransferState.Stop);
- // editType = -1;
- // TimerMgr.Instance.CreateTimer(RemoveBound, 0.01f);
- //}
- ///// <summary>
- ///// 缩放开始
- ///// </summary>
- //private void OnScaleStarted()
- //{
- // ClearEditor();
- // ZoomTransfer?.Invoke(TransferState.Start);
- // editCoroutine = StartCoroutine(EditorCoroutine(2));
- //}
- ///// <summary>
- ///// 编辑的协程
- ///// </summary>
- ///// <returns></returns>
- //private IEnumerator EditorCoroutine(int state)
- //{
- // editType = state;
- // while (editType != -1)
- // {
- // if (editType == 1)
- // {
- // RoteTransfer?.Invoke(TransferState.Doing);
- // }
- // else if (editType == 2)
- // {
- // ZoomTransfer?.Invoke(TransferState.Doing);
- // }
- // yield return new WaitForFixedUpdate();
- // }
- //}
- ///// <summary>
- ///// 当按下的时候
- ///// 如果物体没有被锁定,处于可操作的状态时,显示操作框
- ///// </summary>
- ///// <param name="eventData"></param>
- //public void OnPointerDown(PointerEventData eventData)
- //{
- // if (IsLock || (SCInputModule.Instance && !SCInputModule.Instance.CanDrag))
- // {
- // return;
- // }
- // transform.DOKill();
- // editType = -1;
- // IsDragEnable = true;
- // if (BoundBox)
- // {
- // BoundBox.OnPointerDown(eventData);
- // }
- // if (DragCell)
- // {
- // DragCell.OnPointerDown(eventData);
- // }
- //}
- ///// <summary>
- ///// 当抬起的时候
- ///// </summary>
- ///// <param name="eventData"></param>
- //public void OnPointerUp(PointerEventData eventData)
- //{
- // if (SCInputModule.Instance && !SCInputModule.Instance.CanDrag)
- // {
- // return;
- // }
- // if (editType != -1)
- // {
- // DragTransfer?.Invoke(TransferState.Stop);
- // editType = -1;
- // }
- //}
- ///// <summary>
- ///// 拖拽事件
- ///// </summary>
- ///// <param name="eventData"></param>
- //private void OnPointerDrag(PointerEventData eventData)
- //{
- // if (editType == -1)
- // {
- // DragTransfer?.Invoke(TransferState.Start);
- // //EditorTransfer?.Invoke(state, false);
- // }
- // if (isLookHead)
- // {
- // editType = 1;
- // }
- // else
- // {
- // editType = 0;
- // }
- // if (isLookHead && GameSession.Instance && GameSession.Instance.gameHead)
- // {
- // Vector3 pos = GameSession.Instance.gameHead.position;
- // pos.y = transform.position.y;
- // Vector3 forward = (transform.position - pos).normalized;
- // pos.y = 0;
- // if (forward != Vector3.zero)
- // {
- // transform.forward = forward;
- // }
- // }
- // DragTransfer?.Invoke(TransferState.Doing);
- //}
- ///// <summary>
- ///// 添加一个后退的节点
- ///// 当退出一个前进的节点或者编辑物体的时候添加
- ///// </summary>
- ///// <param name="posture"></param>
- //public void AddBackNode(Posture posture)
- //{
- // if (PostureBack != null)
- // {
- // PostureBack.Push(posture);
- // }
- //}
- ///// <summary>
- ///// 退出一个后退的节点
- ///// </summary>
- //public bool PeekBackNode()
- //{
- // if (PostureBack != null && PostureBack.Count > 0)
- // {
- // AddAheadNode(UnityUtil.GetPosture(transform));
- // Posture posture = PostureBack.Pop();
- // DelaySyn(posture, 0.2f);
- // return true;
- // }
- // return false;
- //}
- ///// <summary>
- ///// 延时控制
- ///// </summary>
- ///// <param name="posture"></param>
- ///// <param name="time"></param>
- //public void DelaySyn(Posture posture, float time)
- //{
- // ClearTime();
- // editType = -1;
- // EditTransfer?.Invoke(TransferState.Start);
- // editType = 2;
- // UnityUtil.SetPosture(transform, posture, time);
- // ///同步3次位置,保持位移的实时性
- // TimerMgr.Instance.CreateTimer(() =>
- // {
- // EditTransfer?.Invoke(TransferState.Doing);
- // }, time / 4f, 3);
- // TimerMgr.Instance.CreateTimer(() =>
- // {
- // EditTransfer?.Invoke(TransferState.Stop);
- // editType = -1;
- // }, time + 0.01f);
- //}
- ///// <summary>
- ///// 添加一个前进的节点,仅当回退的时候添加
- ///// </summary>
- ///// <param name="posture"></param>
- //public void AddAheadNode(Posture posture)
- //{
- // if (PostureAhead != null)
- // {
- // PostureAhead.Push(posture);
- // }
- //}
- ///// <summary>
- ///// 退出一个前进的节点
- ///// </summary>
- //public bool PeekAheadNode()
- //{
- // if (PostureAhead != null && PostureAhead.Count > 0)
- // {
- // AddBackNode(UnityUtil.GetPosture(transform));
- // Posture posture = PostureAhead.Pop();
- // DelaySyn(posture, 0.2f);
- // return true;
- // }
- // return false;
- //}
- ///// <summary>
- ///// 清理此计时器
- ///// </summary>
- //private void ClearTime()
- //{
- // if (dragTimer != null && TimerMgr.Instance)
- // {
- // TimerMgr.Instance.DestroyTimer(dragTimer);
- // }
- // dragTimer = null;
- //}
- ///// <summary>
- ///// 重构包围盒
- ///// </summary>
- ///// <param name="isReStart"></param>
- //public void RemoveBound()
- //{
- // if (BoundCell)
- // {
- // Destroy(BoundCell);
- // }
- // BoundBox.Start();
- //}
- ///// <summary>
- ///// 设置编辑框的颜色
- ///// 用来判定颜色无法被选中的效果
- ///// </summary>
- ///// <param name="color"></param>
- //public void SetBoundColor(bool isLock, Color color)
- //{
- // if (BoundBox)
- // {
- // BoundBox.SetZoomColor(isLock, color);
- // }
- //}
- ///// <summary>
- ///// 获得距离最近的低啊
- ///// </summary>
- ///// <param name="point"></param>
- ///// <returns></returns>
- //public Vector3 GetCastPoint(Vector3 point)
- //{
- // if (BoundBox)
- // {
- // return BoundBox.GetCastPoint(point);
- // }
- // return transform.position;
- //}
- ///// <summary>
- ///// 设置位移编辑激活和失活
- ///// </summary>
- ///// <param name="isActive"></param>
- //public void SetTransferActive(bool isActive)
- //{
- // if (BoundBox && BoundBox.isActiveAndEnabled != isActive)
- // {
- // BoundBox.enabled = isActive;
- // }
- // if (DragCell && DragCell.isActiveAndEnabled != isActive)
- // {
- // DragCell.enabled = isActive;
- // }
- // SetBoundActive(isActive);
- // if (!isActive)
- // {
- // DisActiveCell();
- // }
- //}
- ///// <summary>
- ///// 设置可操作性
- ///// </summary>
- //public bool IsDragEnable
- //{
- // get => isDragEnable;
- // set
- // {
- // isDragEnable = value;
- // SetTransferActive(isDragEnable);
- // if (isDragEnable && !IsLock)
- // {
- // ChangeActive();
- // }
- // }
- //}
- //public void ChangeActive()
- //{
- // if (curActiveCell && curActiveCell != this)
- // {
- // if (!curActiveCell.IsLock)
- // {
- // curActiveCell.IsDragEnable = false;
- // }
- // }
- // if (!IsLock)
- // {
- // if (curActiveCell != this)
- // {
- // curActiveCell = this;
- // TransferSelect?.Invoke(this, true);
- // }
- // if (curActiveCell)
- // {
- // curActiveCell.SetBoundActive(true);
- // }
- // }
- //}
- //public void DisActiveCell()
- //{
- // if (curActiveCell == this)
- // {
- // TransferSelect?.Invoke(this, false);
- // curActiveCell = null;
- // }
- //}
- }
- }
|