using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using System; using UnityEngine.Events; using DG.Tweening; public class SelectionManage : MonoBehaviour { public static SelectionManage instance; public Optional CurrentSelection; /// /// 延迟操作 /// private bool isSelected; /// /// 是否相同选择 /// private bool isSame; /// /// 高亮MR /// MeshRenderer[] highlightRenderers; public static bool IsSelected => instance.CurrentSelection != null; //public UnityEvent OnSelection; /// /// 可操作距离 /// [SerializeField] private int operableDistance = 5; public static int OperableDistance => instance.operableDistance; public bool Test; private void Awake() { instance = this; //测试 设置为排故阶段 #if UNITY_EDITOR ToolData.AddToolData("望远镜"); ToolData.AddToolData("梯子"); //ToolData.toolList.Add("相色标志"); //ToolData.toolList.Add("拉线警示套管"); //ToolData.toolList.Add("一次接线图"); //ToolData.toolList.Add("剩余电流断路器试验记录卡"); //ToolData.toolList.Add("出线电缆名称牌"); //ToolData.toolList.Add("梯子"); //ToolData.toolList.Add("电杆防撞标识"); //GameManage.OperationPhase = OperationPhase.Troubleshooting; #endif } // Start is called before the first frame update void Start() { //OnSelection.AddListener(() => { XFrame.Core.UI.XUIPanel.ShowPanel(); }); } // Update is called once per frame void Update() { //if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && CurrentSelection != null && isSelected && !isSame) //{ // //未点击在UI上 // if (!EventSystem.current.IsPointerOverGameObject()) // { // CurrentSelection = null; // UnSelected(); // } //} } /// /// 更新当前选择 /// /// public bool UpdateSelection(Optional _optional, MeshRenderer[] _highlightRenderers) { Debug.Log("拿取对应工具进行排故"); if (ToolHolder.instance == null) return false; ToolModel_Material tool = ToolHolder.instance.GetCurrentTool(); if (tool.toolName.Equals(_optional.typeName)) { tool.transform.DOMove(_optional.GetTransform().position, 0.5f); tool.transform.DORotate(_optional.GetTransform().eulerAngles, 0.5f).OnComplete(() => { if (tool.replaceTex != null) _optional.SolveIssue(tool.replaceTex); else _optional.SolveIssue(); tool.transform.parent = _optional.GetTransform(); // //构造数据 // _optional.defectDetails.HasHandle = true; Debug.Log("上传成功"+ _optional.typeName); // 新增 PackagePanel.instacne.AddToolIntoPackageFromHand(tool); if (tool.isNotInfinet) { PackagePanel.instacne.ReduceTool_OnlyCount(tool); } // 上传数据 //Destroy(tool.gameObject); }); return true; } else return false; //isSame = CurrentSelection == _optional; //CurrentSelection = _optional; //highlightRenderers = _highlightRenderers; //CancelInvoke(); //Invoke("OnSelected", 0.5f); //OnSelection?.Invoke(); //return (highlightRenderers != null && highlightRenderers.Length != 0); } /// /// 是否拿取对应设备 /// /// /// public static bool Hand(Optional _optional) { if (ToolHolder.instance == null) return false; ToolModel_Material tool = ToolHolder.instance.GetCurrentTool(); return tool == null ? false : string.IsNullOrEmpty(tool.toolDetails) ? tool.toolName.Equals(_optional.typeName) : tool.toolDetails.Equals(_optional.toolDetails); } /// /// 处理选中 /// //void OnSelected() //{ // isSelected = true; // isSame = false; // if (CurrentSelection == null) isSelected = false; // if (highlightRenderers != null && highlightRenderers.Length != 0) // Array.ForEach(highlightRenderers, mr => // { // //if (mr != null) // //mr.material.SetColor("g_vOutlineColor", Color.red); // }); //} /// /// 处理取消选择 /// //void UnSelected() //{ // isSelected = false; // HighLight_VR.instance.CloseHight(); // highlightRenderers = null; //} /// /// 解决缺陷 显示 /// public void SolveIssue(string _name) { if (IsSelected) { if (_name.Equals(CurrentSelection.typeName)) CurrentSelection.SolveIssue(); } } /// /// 解决缺陷 显示替换贴图 /// /// /// public void SolveIssue(string _name, Texture _tex) { if (IsSelected) { if (_name.Equals(CurrentSelection.typeName)) CurrentSelection.SolveIssue(_tex); } } /// /// 是否能操作 /// /// public static bool CanOperate() { #if !UNITY_EDITOR return ScenesRecorder.instance != null && ScenesRecorder.OperationPhase.Equals(OperationPhase.Troubleshooting) ; #endif if (instance.Test) return true; else return ScenesRecorder.instance != null && ScenesRecorder.OperationPhase.Equals(OperationPhase.Troubleshooting); } }