347 lines
11 KiB
C#
347 lines
11 KiB
C#
using HighlightingSystem;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using ZXK.UTility;
|
|
using DG.Tweening;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 每个端子控制
|
|
*******************************************************************************/
|
|
namespace ZXK.BYSS
|
|
{
|
|
|
|
public class TerminalCtrl : MonoBehaviour
|
|
{
|
|
private TerminalModel _curTerminalData = null;
|
|
public TerminalModel _CurTerminalData { get => _curTerminalData; }
|
|
[MyReadOnly]
|
|
public int _ConnectErrorNumber = 0;
|
|
|
|
|
|
private float _centerColAdjust = 0.0f;
|
|
private float _sizeColAdjust = 0.0f;
|
|
|
|
private BoxCollider _col;
|
|
//private Highlighter _light;
|
|
private OutLineRender _light;
|
|
|
|
/// <summary>
|
|
/// 显示线段闪光
|
|
/// </summary>
|
|
public void ShowHighlightOutLine() {
|
|
|
|
// _light.OutLineStrength = 2;
|
|
_light.OutLineColor = Color.blue;
|
|
_light.enabled = true;
|
|
_light.HightOutLine();
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 取消线段闪光
|
|
/// </summary>
|
|
public void HideHighlightOutLine()
|
|
{
|
|
//WDebug.Log("!!!!!!!TerminalCtrl"+transform.name+"!!!!!!!!!!!!!");
|
|
_light.enabled = false;
|
|
|
|
_light.OutLineColor = Color.blue;
|
|
// _light.enabled = false;
|
|
_light.NoHightOutLine();
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (gameObject.GetComponent<OutLineRender>())
|
|
{
|
|
_light = gameObject.GetComponent<OutLineRender>();
|
|
|
|
_light.OutLineColor = Color.blue;
|
|
_light.OutLineStrength = 0;
|
|
_light.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
gameObject.AddComponent<OutLineRender>();
|
|
_light = gameObject.GetComponent<OutLineRender>();
|
|
|
|
_light.OutLineColor = Color.blue;
|
|
_light.OutLineStrength = 0;
|
|
_light.enabled = true;
|
|
}
|
|
}
|
|
public void Init(TerminalModel data)
|
|
{
|
|
if (_curTerminalData != null)
|
|
{
|
|
_curTerminalData._LinesID.Add(data._LinesID[0]);
|
|
}
|
|
else
|
|
{
|
|
_curTerminalData = data;
|
|
}
|
|
gameObject.layer = LayerMask.NameToLayer(ConstCtrl.LAYER_TERMINAL);
|
|
|
|
if (!gameObject.TryGetComponent<BoxCollider>(out _col))
|
|
{
|
|
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ)
|
|
{
|
|
gameObject.AddComponent<MeshCollider>();
|
|
}
|
|
else
|
|
{
|
|
_col = gameObject.AddComponent<BoxCollider>();
|
|
}
|
|
}
|
|
TriAreaChangeByChaTouNumber();
|
|
}
|
|
/// <summary>
|
|
/// 触发区域由于插头数量而变化
|
|
/// </summary>
|
|
private void TriAreaChangeByChaTouNumber()
|
|
{
|
|
if (AppManagement.Instance._CurType == EnumCtrl.Type.XHBY)
|
|
{
|
|
if (_curTerminalData._CtrlBoard.Equals("信号转接板"))
|
|
{
|
|
_centerColAdjust = 0.018f;
|
|
_sizeColAdjust = 0.038f;
|
|
}
|
|
else
|
|
{
|
|
_centerColAdjust = 0.025f;
|
|
_sizeColAdjust = 0.07f;
|
|
}
|
|
}
|
|
else if (AppManagement.Instance._CurType == EnumCtrl.Type.QDCY)
|
|
{
|
|
if (_curTerminalData._CtrlBoard.Equals("信号转接板"))
|
|
{
|
|
_centerColAdjust = 0.05f;
|
|
_sizeColAdjust = 0.095f;
|
|
}
|
|
else
|
|
{
|
|
_centerColAdjust = 0.038f;
|
|
_sizeColAdjust = 0.075f;
|
|
}
|
|
}
|
|
else if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ)
|
|
{
|
|
//接线方式不同,不需要
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 接入一个插头
|
|
/// </summary>
|
|
/// <param name="chatou"></param>
|
|
public void SetChaTouPos(Transform chatou)
|
|
{
|
|
if (transform.childCount > 0)
|
|
{//已经有线插入
|
|
Transform lastTran = transform.GetChild(transform.childCount - 1);
|
|
chatou.SetParent(lastTran);
|
|
chatou.localPosition = Vector3.right * 0.029f;//lastTran.localPosition +
|
|
chatou.localRotation = Quaternion.Euler(Vector3.right * -180);//lastTran.localRotation.eulerAngles +
|
|
chatou.SetParent(transform);
|
|
}
|
|
else
|
|
{
|
|
chatou.SetParent(transform);
|
|
chatou.localPosition = _CurTerminalData._ChaTouPos;
|
|
chatou.localRotation = Quaternion.Euler(_CurTerminalData._ChaTouRot);
|
|
}
|
|
ChaTouNumber(true);
|
|
InsertLightState(true);
|
|
}
|
|
/// <summary>
|
|
/// 碰撞体加长
|
|
/// </summary>
|
|
/// <param name="addChaTou"></param>
|
|
public void ChaTouNumber(bool addChaTou)
|
|
{
|
|
if (_col)
|
|
{
|
|
if (addChaTou)
|
|
{
|
|
_col.center = new Vector3(_col.center.x, _col.center.y, _col.center.z + _centerColAdjust);
|
|
_col.size = new Vector3(_col.size.x, _col.size.y, _col.size.z + _sizeColAdjust);
|
|
}
|
|
else
|
|
{
|
|
_col.center = new Vector3(_col.center.x, _col.center.y, _col.center.z - _centerColAdjust);
|
|
_col.size = new Vector3(_col.size.x, _col.size.y, _col.size.z - _sizeColAdjust);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 直插式接入端子,例如:材料分拣模块
|
|
/// </summary>
|
|
public void StraightSetChaTouPos()
|
|
{
|
|
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ)
|
|
{
|
|
float posX = transform.localPosition.x;
|
|
if (transform.name.Contains("Q0.") || transform.name.Contains("Q1."))
|
|
{
|
|
transform.DOLocalMoveX(posX + 0.05f, 0.5f).OnComplete(() =>
|
|
{
|
|
InsertLightState(true);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
transform.DOLocalMoveX(posX + 0.01f, 0.5f).OnComplete(() =>
|
|
{
|
|
InsertLightState(true);
|
|
});
|
|
}
|
|
}
|
|
//搬运输送
|
|
else if (AppManagement.Instance._CurType == EnumCtrl.Type.BYSS)
|
|
{
|
|
|
|
float posZ = transform.localPosition.z;
|
|
//标签
|
|
if (transform.name.Contains("-BiaoQian"))
|
|
{
|
|
//标签不做动画
|
|
}
|
|
|
|
else
|
|
{
|
|
//线段做动画
|
|
|
|
|
|
//移动1点
|
|
var v = GameObject.Find(transform.name + "_Pos1").gameObject;
|
|
//移动2点
|
|
var v2 = GameObject.Find(transform.name + "_Pos2").gameObject;
|
|
|
|
transform.DOLocalMove(v.transform.localPosition, 0.2f).OnComplete(() =>
|
|
{
|
|
transform.DOLocalMove(v2.transform.localPosition, 0.2f).OnComplete(() =>
|
|
{
|
|
|
|
|
|
InsertLightState(true);
|
|
|
|
});
|
|
|
|
|
|
});
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 立刻执行
|
|
/// </summary>
|
|
public void StraightSetChaTouPos_Rightaway() {
|
|
|
|
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ)
|
|
{
|
|
float posX = transform.localPosition.x;
|
|
if (transform.name.Contains("Q0.") || transform.name.Contains("Q1."))
|
|
{
|
|
transform.DOLocalMoveX(posX + 0.05f, 0.5f).OnComplete(() =>
|
|
{
|
|
InsertLightState(true);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
transform.DOLocalMoveX(posX + 0.01f, 0.5f).OnComplete(() =>
|
|
{
|
|
InsertLightState(true);
|
|
});
|
|
}
|
|
}
|
|
//搬运输送
|
|
else if (AppManagement.Instance._CurType == EnumCtrl.Type.BYSS)
|
|
{
|
|
|
|
float posZ = transform.localPosition.z;
|
|
//标签
|
|
if (transform.name.Contains("-BiaoQian"))
|
|
{
|
|
//标签不做动画
|
|
}
|
|
|
|
else
|
|
{
|
|
//线段做动画
|
|
|
|
|
|
//移动1点
|
|
var v = GameObject.Find(transform.name + "_Pos1").gameObject;
|
|
//移动2点
|
|
var v2 = GameObject.Find(transform.name + "_Pos2").gameObject;
|
|
|
|
transform.DOLocalMove(v.transform.localPosition, 0f).OnComplete(() =>
|
|
{
|
|
transform.DOLocalMove(v2.transform.localPosition,0f).OnComplete(() =>
|
|
{
|
|
|
|
|
|
InsertLightState(true);
|
|
|
|
});
|
|
|
|
|
|
});
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 撤销直插式接入端子
|
|
/// </summary>
|
|
public void RecallStraightChaTouPos()
|
|
{
|
|
|
|
//材料分拣特殊模式设置
|
|
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ)
|
|
{
|
|
float posX = transform.localPosition.x;
|
|
if (transform.name.Contains("Q0.") || transform.name.Contains("Q1."))
|
|
{
|
|
//transform.localPosition = new Vector3(posX - 0.01f, transform.localPosition.y, transform.localPosition.z);
|
|
transform.DOLocalMoveX(posX - 0.05f, 0.5f);
|
|
}
|
|
else
|
|
{
|
|
//transform.localPosition = new Vector3(posX - 0.01f, transform.localPosition.y, transform.localPosition.z);
|
|
transform.DOLocalMoveX(posX - 0.01f, 0.5f);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 端子泛光变化
|
|
/// </summary>
|
|
/// <param name="right">连接是否正确</param>
|
|
public void InsertLightState(bool right)
|
|
{
|
|
_light.OutLineColor = Color.blue;
|
|
_light.enabled = true;
|
|
_light.OutLineStrength = 2;
|
|
int time = 0;
|
|
DOTween.To(() => time, t => t = time, 5, 0.5f).OnComplete(() =>
|
|
{
|
|
_light.OutLineStrength = 0;
|
|
_light.enabled = false;
|
|
});
|
|
|
|
}
|
|
}
|
|
} |