639 lines
19 KiB
C#
639 lines
19 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
public class Optional : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 高亮MR
|
|
/// </summary>
|
|
MeshRenderer[] highlightRenderers;
|
|
/// <summary>
|
|
/// 对应材料、工器具
|
|
/// </summary>
|
|
public ErrorModelType modelType;
|
|
|
|
/// <summary>
|
|
/// 是否为缺陷
|
|
/// </summary>
|
|
public bool isIssue = true;
|
|
/// <summary>
|
|
/// 故障类型
|
|
/// </summary>
|
|
public FaultType faultType;
|
|
/// <summary>
|
|
/// 是否为蓝图模式
|
|
/// </summary>
|
|
public bool isBlueprint = false; //蓝图模式,将物体摆放至该物体下
|
|
/// <summary>
|
|
/// 是否显示子物体下隐藏mesh的高亮
|
|
/// </summary>
|
|
public bool highlightWithHideChilds = true;
|
|
/// <summary>
|
|
/// 是否为自身材质
|
|
/// </summary>
|
|
public bool SelfMR = true;
|
|
/// <summary>
|
|
/// 缺陷操作物体
|
|
/// </summary>
|
|
public List<GameObject> IssueObjects = new List<GameObject>();
|
|
|
|
/// <summary>
|
|
/// 是否初始化缺陷
|
|
/// </summary>
|
|
public bool issueInit;
|
|
/// <summary>
|
|
/// 缺陷是否解决
|
|
/// </summary>
|
|
public bool IssueSolved;
|
|
|
|
/// <summary>
|
|
/// 类型名称
|
|
/// </summary>
|
|
public string typeName;
|
|
/// <summary>
|
|
/// 细节
|
|
/// </summary>
|
|
public string toolDetails;
|
|
|
|
/// <summary>
|
|
/// 是否在高亮
|
|
/// </summary>
|
|
bool highLighting;
|
|
|
|
/// <summary>
|
|
/// 鼠标是否在该物体上
|
|
/// </summary>
|
|
bool isHovering;
|
|
|
|
/// <summary>
|
|
/// 非缺陷 是否已有物体
|
|
/// </summary>
|
|
public bool hasObject;
|
|
|
|
/// <summary>
|
|
/// 蓝图物体
|
|
/// </summary>
|
|
public GameObject blueprintObject;
|
|
/// <summary>
|
|
/// 缓存下发数据
|
|
/// </summary>
|
|
|
|
public AttrData data;
|
|
|
|
void Start()
|
|
{
|
|
if (!isIssue) //禁止合闸警示牌
|
|
{
|
|
IssueSolved = false;
|
|
hasObject = false;
|
|
typeName = GetComponent<ErrorBase>().modelType.ToString();
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (highLighting)
|
|
{
|
|
if (Camera.main == null || Vector3.Distance(Camera.main.transform.position, transform.position) > SelectionManage.OperableDistance)
|
|
{
|
|
HighlightOff();
|
|
}
|
|
}
|
|
|
|
if (isHovering && !highLighting)
|
|
{
|
|
if (Camera.main != null && Vector3.Distance(Camera.main.transform.position, transform.position) < SelectionManage.OperableDistance)
|
|
{
|
|
HighlightOn();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 缺陷初始化
|
|
/// </summary>
|
|
/// <param name="texture2D"></param>
|
|
/// <param name="inactave"> 是否为缺失</param>
|
|
public void IssueInit(AttrData data/*DefectDetails details*/,Texture2D texture2D = null,bool inactave = true)
|
|
{
|
|
var eb = GetComponent<ErrorBase>();
|
|
if (eb != null)
|
|
modelType = eb.modelType;
|
|
|
|
if (faultType.Equals(FaultType.Malposition)) { }
|
|
else if (faultType.Equals(FaultType.Error))
|
|
{
|
|
var _target = gameObject.GetChildByNameContains("_错误", true);
|
|
if (inactave) {
|
|
_target.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
if (texture2D != null)
|
|
_target.SetMeshRendererActive(true, texture2D);
|
|
_target.SetActive(true);
|
|
}
|
|
var _true = gameObject.GetChildByNameContains("_正确", true);
|
|
_true.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
if (SelfMR)
|
|
{
|
|
gameObject.SetMeshRendererActive(false);
|
|
}
|
|
else
|
|
{
|
|
IssueObjects.ForEach(issue => { issue.SetMeshRendererActive(false); });
|
|
}
|
|
}
|
|
IssueSolved = false;
|
|
hasObject = false;
|
|
issueInit = true;
|
|
this.data = data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 正常初始化
|
|
/// </summary>
|
|
public void NormalInit()
|
|
{
|
|
issueInit = false;
|
|
var normal = transform.Find("正确");
|
|
if (normal != null)
|
|
{
|
|
if (normal.childCount == 1)
|
|
{
|
|
normal.GetChild(0).gameObject.SetActive(true);
|
|
}
|
|
else if (normal.childCount > 1)
|
|
{
|
|
var area = ScenesRecorder.instance == null ? normal.Find("敏行") : normal.Find(ScenesRecorder.AreaName);
|
|
if (area != null)
|
|
{
|
|
gameObject.SetMeshRendererActive(false);
|
|
area.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
Debug.Log("未找到 :" + transform.name + "_" + normal.name + "_" + ScenesRecorder.AreaName + " !");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (faultType)
|
|
{
|
|
case FaultType.Defect:
|
|
if (SelfMR)
|
|
{
|
|
gameObject.SetMeshRendererActive(true);
|
|
}
|
|
else
|
|
{
|
|
IssueObjects.ForEach(issue => { issue.SetMeshRendererActive(true); });
|
|
}
|
|
break;
|
|
case FaultType.Damage:
|
|
Array.ForEach(GetComponentsInChildren<Transform>(), (tra) =>
|
|
{
|
|
if (tra.name.Contains("_正确"))
|
|
{
|
|
tra.gameObject.SetMeshRendererActive(true);
|
|
}
|
|
else if (tra.name.Contains("_错误"))
|
|
{
|
|
tra.gameObject.SetMeshRendererActive(false);
|
|
}
|
|
});
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 正常初始化 附带贴图
|
|
/// </summary>
|
|
public void NormalInit(Texture2D texture2D)
|
|
{
|
|
issueInit = false;
|
|
var normal = transform.Find("正确");
|
|
if (normal != null)
|
|
{
|
|
if (normal.childCount == 1)
|
|
{
|
|
normal.GetChild(0).gameObject.SetActive(true);
|
|
}
|
|
else if (normal.childCount > 1)
|
|
{
|
|
var area = ScenesRecorder.instance == null ? normal.Find("敏行") : normal.Find(ScenesRecorder.AreaName);
|
|
if (area != null)
|
|
{
|
|
area.gameObject.SetMeshRendererActive(true, texture2D);
|
|
area.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
Debug.Log("未找到 :" + transform.name + "_" + normal.name + "_" + ScenesRecorder.AreaName + " !");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (faultType)
|
|
{
|
|
case FaultType.Defect:
|
|
if (SelfMR)
|
|
{
|
|
gameObject.SetMeshRendererActive(true);
|
|
}
|
|
else
|
|
{
|
|
IssueObjects.ForEach(issue => { issue.SetMeshRendererActive(true); });
|
|
}
|
|
break;
|
|
case FaultType.Damage:
|
|
Array.ForEach(GetComponentsInChildren<Transform>(), (tra) =>
|
|
{
|
|
if (tra.name.Contains("_正确"))
|
|
{
|
|
tra.gameObject.SetMeshRendererActive(true);
|
|
}
|
|
else if (tra.name.Contains("_错误"))
|
|
{
|
|
tra.gameObject.SetMeshRendererActive(false);
|
|
}
|
|
});
|
|
break;
|
|
case FaultType.Error:
|
|
if (texture2D != null)
|
|
{
|
|
Array.ForEach(GetComponentsInChildren<Transform>(true), (tra) =>
|
|
{
|
|
if (tra.name.Contains("_正确")&& !tra.Equals(this.transform))
|
|
{
|
|
tra.gameObject.SetActive(true);
|
|
tra.gameObject.SetMeshRendererActive(true,texture2D);
|
|
}
|
|
else if (tra.name.Contains("_错误") && !tra.Equals(this.transform))
|
|
{
|
|
tra.gameObject.SetActive(false);
|
|
tra.gameObject.SetMeshRendererActive(false);
|
|
}
|
|
});
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 直接处理缺陷 显示
|
|
/// </summary>
|
|
public void SolveIssue()
|
|
{
|
|
switch (faultType)
|
|
{
|
|
case FaultType.Defect:
|
|
if (SelfMR)
|
|
{
|
|
gameObject.SetMeshRendererActive(true);
|
|
}
|
|
else
|
|
{
|
|
IssueObjects.ForEach(issue => { issue.SetMeshRendererActive(true); });
|
|
}
|
|
|
|
break;
|
|
case FaultType.Damage:
|
|
Array.ForEach(GetComponentsInChildren<Transform>(), (tra) =>
|
|
{
|
|
//场景物体需整理结构
|
|
if (tra.name.Contains("_正确"))
|
|
{
|
|
tra.gameObject.SetMeshRendererActive(true);
|
|
}
|
|
else if (tra.name.Contains("_错误"))
|
|
{
|
|
tra.gameObject.SetMeshRendererActive(false);
|
|
}
|
|
});
|
|
break;
|
|
case FaultType.Error:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (isIssue)
|
|
IssueSolved = true;
|
|
else
|
|
hasObject = true;
|
|
|
|
// 直接处理 上传处理结果
|
|
|
|
Request.SendFaultData(data, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 非直接处理缺陷 显示并替换贴图
|
|
/// </summary>
|
|
public void SolveIssue(Texture _tex)
|
|
{
|
|
if (SelfMR)
|
|
{
|
|
gameObject.SetMeshRendererActive(true, _tex);
|
|
}
|
|
else
|
|
{
|
|
if(faultType.Equals(FaultType.Error))
|
|
{
|
|
Array.ForEach(GetComponentsInChildren<Transform>(true), (tra) =>
|
|
{
|
|
if (tra.name.Contains("_错误") && !tra.Equals(this.transform))
|
|
{
|
|
tra.gameObject.SetActive(false);
|
|
}
|
|
});
|
|
}
|
|
for (int i = 0; i < IssueObjects.Count; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
IssueObjects[i].SetMeshRendererActive(true, _tex);
|
|
}
|
|
else
|
|
{
|
|
IssueObjects[i].SetMeshRendererActive(true);
|
|
|
|
}
|
|
}
|
|
}
|
|
IssueSolved = true;
|
|
|
|
// 直接处理 并 上传贴图类型
|
|
data.Details.CurreSelectDetail = _tex.name;
|
|
Request.SendFaultData(data, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 蓝图模式修复缺陷
|
|
/// </summary>
|
|
/// <param name="_blueprint"></param>
|
|
public void SolveIssue(GameObject _blueprint)
|
|
{
|
|
blueprintObject = _blueprint;
|
|
}
|
|
|
|
private void OnMouseEnter()
|
|
{
|
|
MouseEnter();
|
|
#region
|
|
//if (EventSystem.current.IsPointerOverGameObject()) return;
|
|
//if (Camera.main == null) return;
|
|
//if (typeName.Equals("禁止合闸警示牌"))
|
|
//{
|
|
// if (!hasObject)
|
|
// if (!SelectionManage.Hand(this)) return;
|
|
// isHovering = true;
|
|
//}
|
|
//else
|
|
//{
|
|
// if (ScenesRecorder.instance != null && !ScenesRecorder.OperationPhase.Equals(OperationPhase.Troubleshooting)) return;
|
|
|
|
// if (isIssue)
|
|
// {
|
|
// //是否处理缺陷后禁止再次操作
|
|
// //if (IssueSolved) return;
|
|
// if (!isBlueprint && !SelectionManage.Hand(this) || isBlueprint && blueprintObject == null) return; //非蓝图下未持有对应物体 或 蓝图下未安装到位 不予高亮
|
|
// isHovering = true;
|
|
// }
|
|
// else
|
|
// {
|
|
// if (!hasObject)
|
|
// if (!SelectionManage.Hand(this)) return;
|
|
// isHovering = true;
|
|
// }
|
|
//}
|
|
#endregion
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
MouseDown();
|
|
#region
|
|
//if (EventSystem.current.IsPointerOverGameObject()) return;
|
|
//if (!highLighting) return;
|
|
//if (typeName.Equals("禁止合闸警示牌"))
|
|
//{
|
|
// //已有,则取出
|
|
// if (hasObject)
|
|
// {
|
|
// //取出放回背包
|
|
// PackagePanel.instacne.AddToolIntoPackageFromHand(this.IssueObjects[0].GetComponentInChildren<ToolModel_Material>(true));
|
|
// IssueInit();
|
|
// }
|
|
// else
|
|
// hasObject = SelectionManage.instance.UpdateSelection(this, highlightRenderers);
|
|
//}
|
|
//else
|
|
//{
|
|
// if (ScenesRecorder.instance != null && !ScenesRecorder.OperationPhase.Equals(OperationPhase.Troubleshooting)) return;
|
|
|
|
// if (isIssue)
|
|
// {
|
|
// //是否处理缺陷后禁止再次操作
|
|
// //if (IssueSolved) return;
|
|
// if (isBlueprint)
|
|
// {
|
|
// Debug.Log("取回蓝图[" + blueprintObject.name + "]");
|
|
// }
|
|
// else
|
|
// {
|
|
// IssueSolved = SelectionManage.instance.UpdateSelection(this, highlightRenderers);
|
|
// //解决缺陷后取消高亮
|
|
// if (IssueSolved) HighlightOff();
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
|
|
// //已有,则取出
|
|
// if (hasObject)
|
|
// {
|
|
// //取出放回背包
|
|
// PackagePanel.instacne.AddToolIntoPackageFromHand(this.IssueObjects[0].GetComponentInChildren<ToolModel_Material>(true));
|
|
// IssueInit();
|
|
// }
|
|
// else
|
|
// hasObject = SelectionManage.instance.UpdateSelection(this, highlightRenderers);
|
|
// }
|
|
//}
|
|
#endregion
|
|
}
|
|
|
|
private void OnMouseExit()
|
|
{
|
|
MouseExit();
|
|
#region
|
|
//isHovering = false;
|
|
//HighlightOff();
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 鼠标进入执行
|
|
/// </summary>
|
|
public void MouseEnter()
|
|
{
|
|
if (EventUtilities.IsOverUI) return;
|
|
if (Camera.main == null) return;
|
|
if (typeName.Equals("禁止合闸警示牌"))
|
|
{
|
|
if (!hasObject)
|
|
if (!SelectionManage.Hand(this)) return;
|
|
isHovering = true;
|
|
}
|
|
else
|
|
{
|
|
if (!SelectionManage.CanOperate()) return;
|
|
if (faultType.Equals(FaultType.Malposition))
|
|
{
|
|
if (!issueInit) return;
|
|
isHovering = true;
|
|
}
|
|
else
|
|
{
|
|
if (isIssue)
|
|
{
|
|
//if (IssueSolved) return;
|
|
if (!issueInit) return;
|
|
if (!isBlueprint && !SelectionManage.Hand(this) || isBlueprint && blueprintObject == null) return; //非蓝图下未持有对应物体 或 蓝图下未安装到位 不予高亮
|
|
isHovering = true;
|
|
}
|
|
else
|
|
{
|
|
if (!hasObject)
|
|
if (!SelectionManage.Hand(this)) return;
|
|
isHovering = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 鼠标点击执行
|
|
/// </summary>
|
|
public void MouseDown()
|
|
{
|
|
if (EventUtilities.IsOverUI) return;
|
|
if (!highLighting) return;
|
|
if (typeName.Equals("禁止合闸警示牌"))
|
|
{
|
|
//已有,则取出
|
|
if (hasObject)
|
|
{
|
|
//取出放回背包
|
|
ToolBase tool= ToolHolder.instance.GetCurrentTool<ToolBase>();
|
|
if (tool)
|
|
{
|
|
if (tool.toolName == "禁止合闸警示牌")
|
|
{
|
|
PackagePanel.instacne.AddToolIntoPackageFromHand(tool);
|
|
}
|
|
}
|
|
//PackagePanel.instacne.AddToolIntoPackageFromHand(this.IssueObjects[0].GetComponentInChildren<ToolModel_Material>(true));
|
|
IssueInit(null);
|
|
}
|
|
else
|
|
hasObject = SelectionManage.instance.UpdateSelection(this, highlightRenderers);
|
|
}
|
|
else
|
|
{
|
|
if (!SelectionManage.CanOperate()) return;
|
|
|
|
if (faultType.Equals(FaultType.Malposition))
|
|
{
|
|
var right = gameObject.GetChildsByNameContains("_正确");
|
|
var fault = gameObject.GetChildsByNameContains("_错误");
|
|
right.ForEach(x => x.SetMeshRendererActive(true));
|
|
fault.ForEach(x => x.SetMeshRendererActive(false));
|
|
IssueSolved = true;
|
|
HighlightOff();
|
|
|
|
//上传数据
|
|
Request.SendFaultData(data, "");
|
|
}
|
|
else
|
|
{
|
|
if (isIssue)
|
|
{
|
|
//if (IssueSolved) return;
|
|
if (isBlueprint)
|
|
{
|
|
Debug.Log("取回蓝图[" + blueprintObject.name + "]");
|
|
}
|
|
else
|
|
{
|
|
IssueSolved = SelectionManage.instance.UpdateSelection(this, highlightRenderers);
|
|
//解决缺陷后取消高亮
|
|
if (IssueSolved) HighlightOff();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
//已有,则取出
|
|
if (hasObject)
|
|
{
|
|
//取出放回背包
|
|
PackagePanel.instacne.AddToolIntoPackageFromHand(this.IssueObjects[0].GetComponentInChildren<ToolModel_Material>(true));
|
|
IssueInit(null);
|
|
}
|
|
else
|
|
hasObject = SelectionManage.instance.UpdateSelection(this, highlightRenderers);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 鼠标退出执行
|
|
/// </summary>
|
|
public void MouseExit()
|
|
{
|
|
isHovering = false;
|
|
HighlightOff();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开高亮
|
|
/// </summary>
|
|
void HighlightOn()
|
|
{
|
|
highLighting = true;
|
|
if (isBlueprint || !highlightWithHideChilds)
|
|
HighLight_VR.instance.SetHight(this.transform);
|
|
else
|
|
HighLight_VR.instance.SetHight(this.transform, true, ref highlightRenderers);
|
|
}
|
|
/// <summary>
|
|
/// 关闭高亮
|
|
/// </summary>
|
|
void HighlightOff()
|
|
{
|
|
highLighting = false;
|
|
HighLight_VR.instance.CloseHight();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取位置 将手上的物体放入该位置
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Transform GetTransform()
|
|
{
|
|
return SelfMR ? transform : (IssueObjects.Count > 0 ? (IssueObjects.Count > 1 ? transform : IssueObjects[0].transform) : transform);
|
|
}
|
|
}
|