212 lines
6.0 KiB
C#
212 lines
6.0 KiB
C#
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;
|
|
/// <summary>
|
|
/// 延迟操作
|
|
/// </summary>
|
|
private bool isSelected;
|
|
/// <summary>
|
|
/// 是否相同选择
|
|
/// </summary>
|
|
private bool isSame;
|
|
/// <summary>
|
|
/// 高亮MR
|
|
/// </summary>
|
|
MeshRenderer[] highlightRenderers;
|
|
|
|
public static bool IsSelected => instance.CurrentSelection != null;
|
|
|
|
//public UnityEvent OnSelection;
|
|
|
|
/// <summary>
|
|
/// 可操作距离
|
|
/// </summary>
|
|
[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<PackagePanel>(); });
|
|
}
|
|
|
|
// 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();
|
|
// }
|
|
//}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新当前选择
|
|
/// </summary>
|
|
/// <param name="_optional"></param>
|
|
public bool UpdateSelection(Optional _optional, MeshRenderer[] _highlightRenderers)
|
|
{
|
|
Debug.Log("拿取对应工具进行排故");
|
|
|
|
if (ToolHolder.instance == null) return false;
|
|
ToolModel_Material tool = ToolHolder.instance.GetCurrentTool<ToolModel_Material>();
|
|
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否拿取对应设备
|
|
/// </summary>
|
|
/// <param name="_optional"></param>
|
|
/// <returns></returns>
|
|
public static bool Hand(Optional _optional)
|
|
{
|
|
if (ToolHolder.instance == null) return false;
|
|
ToolModel_Material tool = ToolHolder.instance.GetCurrentTool<ToolModel_Material>();
|
|
return tool == null ? false :
|
|
string.IsNullOrEmpty(tool.toolDetails) ? tool.toolName.Equals(_optional.typeName) : tool.toolDetails.Equals(_optional.toolDetails);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理选中
|
|
/// </summary>
|
|
//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);
|
|
// });
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 处理取消选择
|
|
/// </summary>
|
|
//void UnSelected()
|
|
//{
|
|
// isSelected = false;
|
|
// HighLight_VR.instance.CloseHight();
|
|
// highlightRenderers = null;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 解决缺陷 显示
|
|
/// </summary>
|
|
public void SolveIssue(string _name)
|
|
{
|
|
if (IsSelected)
|
|
{
|
|
if (_name.Equals(CurrentSelection.typeName))
|
|
CurrentSelection.SolveIssue();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 解决缺陷 显示替换贴图
|
|
/// </summary>
|
|
/// <param name="_name"></param>
|
|
/// <param name="_tex"></param>
|
|
public void SolveIssue(string _name, Texture _tex)
|
|
{
|
|
if (IsSelected)
|
|
{
|
|
if (_name.Equals(CurrentSelection.typeName))
|
|
CurrentSelection.SolveIssue(_tex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否能操作
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
}
|