299 lines
8.9 KiB
C#
299 lines
8.9 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity.VisualScripting.Antlr3.Runtime;
|
|
using UnityEngine;
|
|
|
|
public class Device_TerminalBoard : Device_Base
|
|
{
|
|
public bool isInstall;
|
|
/// <summary>
|
|
/// 固定螺丝
|
|
/// </summary>
|
|
public Tool_Screw fix_1_screw;
|
|
/// <summary>
|
|
/// 固定螺丝
|
|
/// </summary>
|
|
public Tool_Screw fix_2_screw;
|
|
|
|
#region 封印
|
|
public Device_Seal seal_1;
|
|
public Device_Seal seal_2;
|
|
public DeviceTrigger trigger_seal_1;
|
|
public DeviceTrigger trigger_seal_2;
|
|
#endregion
|
|
|
|
#region 盖子
|
|
/// <summary>
|
|
/// 盖子
|
|
/// </summary>
|
|
public DeviceTrigger cover;
|
|
/// <summary>
|
|
/// 盖子是否打开
|
|
/// </summary>
|
|
public bool isCoverOpen;
|
|
/// <summary>
|
|
/// 盖子关闭位置
|
|
/// </summary>
|
|
public Vector3 CloseLocalPos;
|
|
/// <summary>
|
|
/// 盖子打开位置
|
|
/// </summary>
|
|
public Vector3 OpenLocalPos;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 拨片
|
|
/// </summary>
|
|
public List<ClickMove> boPians;
|
|
/// <summary>
|
|
/// 接线螺丝
|
|
/// </summary>
|
|
public List<Tool_Screw> jeixian_screws;
|
|
|
|
/// <summary>
|
|
/// 安装和取下的回调
|
|
/// </summary>
|
|
public Action<bool> inOrUnstallAction;
|
|
|
|
//protected override void OnMDown()
|
|
//{
|
|
// base.OnMDown();
|
|
// Remove();
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 安装端子盒
|
|
/// </summary>
|
|
/// <param name="device_Control"></param>
|
|
/// <param name="localPos"></param>
|
|
/// <param name="loacalAng"></param>
|
|
/// <param name="callback"></param>
|
|
public void Add(Device_Control device_Control, Vector3 localPos, Vector3 loacalAng, string triggerName, Action<bool> inOrUnstallAction)
|
|
{
|
|
this.inOrUnstallAction = inOrUnstallAction;
|
|
transform.parent = device_Control.transform;
|
|
isMoving = true;
|
|
isInstall = true;
|
|
inOrUnstallAction?.Invoke(true);
|
|
hand_out_action?.Invoke();
|
|
|
|
//设置断开状态
|
|
SetUninstallState();
|
|
//封印剪除
|
|
seal_1.Cut();
|
|
seal_2.Cut();
|
|
//盖子打开
|
|
SetCoverOpen();
|
|
//设置封印
|
|
SetTrigger();
|
|
transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
|
|
//禁用拿取碰撞
|
|
GetComponent<BoxCollider>().enabled = false;
|
|
|
|
transform.DOLocalMove(localPos, 2).OnStart(() => { transform.localEulerAngles = loacalAng; }).OnComplete(() =>
|
|
{
|
|
Debug.Log("端子盒已安装");
|
|
isMoving = false;
|
|
triggerAction?.Invoke(triggerName, true);
|
|
base.CallScoreAction(true);
|
|
//删除手里的tip
|
|
LiveSceneManager.Instance.OnCheckSubProcess(false);
|
|
|
|
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆除端子盒
|
|
/// </summary>
|
|
public void Remove()
|
|
{
|
|
if (!fix_1_screw.isInstall && !fix_2_screw.isInstall)
|
|
{
|
|
Debug.Log("端子盒已拆除");
|
|
inOrUnstallAction?.Invoke(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 直接安装上
|
|
/// </summary>
|
|
/// <param name="isinstalled"></param>
|
|
/// <param name="device_Control"></param>
|
|
/// <param name="localPos"></param>
|
|
/// <param name="loacalAng"></param>
|
|
public void SetState(bool isinstalled, Device_Control device_Control, Vector3 localPos, Vector3 loacalAng)
|
|
{
|
|
if (isinstalled)
|
|
{
|
|
//安装状态
|
|
transform.parent = device_Control.transform;
|
|
isInstall = true;
|
|
//设置断开状态
|
|
SetUninstallState();
|
|
transform.localPosition = localPos;
|
|
transform.localEulerAngles = loacalAng;
|
|
|
|
//封印剪除
|
|
seal_1.Cut();
|
|
seal_2.Cut();
|
|
//盖子打开
|
|
SetCoverOpen();
|
|
//设置封印
|
|
SetTrigger();
|
|
|
|
//手动初始化
|
|
transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
|
|
|
|
//禁用拿取碰撞
|
|
GetComponent<BoxCollider>().enabled = false;
|
|
}
|
|
else
|
|
{
|
|
//拆下状态
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置螺丝拆开状态
|
|
/// </summary>
|
|
public void SetUninstallState()
|
|
{
|
|
fix_1_screw.isInstall = false;
|
|
fix_1_screw.transform.localPosition = new Vector3(fix_1_screw.transform.localPosition.x, fix_1_screw.initPostionY - 0.02f, fix_1_screw.transform.localPosition.z);
|
|
fix_2_screw.isInstall = false;
|
|
fix_2_screw.transform.localPosition = new Vector3(fix_2_screw.transform.localPosition.x, fix_2_screw.initPostionY - 0.02f, fix_2_screw.transform.localPosition.z);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置螺丝安装状态
|
|
/// </summary>
|
|
public void SetInstallState()
|
|
{
|
|
fix_1_screw.isInstall = true;
|
|
fix_1_screw.transform.localPosition = new Vector3(fix_1_screw.transform.localPosition.x, fix_1_screw.initPostionY, fix_1_screw.transform.localPosition.z);
|
|
fix_2_screw.isInstall = true;
|
|
fix_2_screw.transform.localPosition = new Vector3(fix_2_screw.transform.localPosition.x, fix_2_screw.initPostionY, fix_2_screw.transform.localPosition.z);
|
|
}
|
|
|
|
public void SetCoverOpen()
|
|
{
|
|
cover.transform.localPosition = OpenLocalPos;
|
|
isCoverOpen = true;
|
|
}
|
|
public void SetCoverClose()
|
|
{
|
|
cover.transform.localPosition = CloseLocalPos;
|
|
isCoverOpen = false;
|
|
}
|
|
|
|
public void SetTrigger()
|
|
{
|
|
//封印触发安装事件
|
|
trigger_seal_1.clickAction += () =>
|
|
{
|
|
//盖上了盖子
|
|
//螺丝拧上了就安装封印
|
|
if (!isCoverOpen && fix_1_screw.isInstall)
|
|
{
|
|
if ((triggerAction == null ? 0 : triggerAction.Invoke(trigger_seal_1.triggerName, true)) == 0)
|
|
{
|
|
//盖子左封印
|
|
seal_1.Install();
|
|
//触发区域隐藏
|
|
trigger_seal_1.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
};
|
|
//封印触发安装事件
|
|
trigger_seal_2.clickAction += () =>
|
|
{
|
|
//盖上了盖子
|
|
//螺丝拧上了就安装封印
|
|
if (!isCoverOpen && fix_2_screw.isInstall)
|
|
{
|
|
if ((triggerAction == null ? 0 : triggerAction.Invoke(trigger_seal_2.triggerName, true)) == 0)
|
|
{
|
|
//盖子左封印
|
|
seal_2.Install();
|
|
//触发区域隐藏
|
|
trigger_seal_2.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
};
|
|
|
|
//盖子事件
|
|
cover.clickAction += () =>
|
|
{
|
|
if (!cover.isMoving && !fix_1_screw.isInstall && !fix_2_screw.isInstall)
|
|
{
|
|
if (triggerAction==null || triggerAction?.Invoke(cover.triggerName, false) == 0)
|
|
{
|
|
cover.isMoving = true;
|
|
if (isCoverOpen)
|
|
{
|
|
cover.transform.DOLocalMove(CloseLocalPos, 1).OnComplete(() =>
|
|
{
|
|
isCoverOpen = false;
|
|
cover.isMoving = false;
|
|
triggerAction?.Invoke(cover.triggerName, true);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
cover.transform.DOLocalMove(OpenLocalPos, 1).OnComplete(() =>
|
|
{
|
|
isCoverOpen = true;
|
|
cover.isMoving = false;
|
|
triggerAction?.Invoke(cover.triggerName, true);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
fix_1_screw.AddCheckAction(() =>{ return seal_1.isCut;});
|
|
fix_2_screw.AddCheckAction(() => { return seal_2.isCut; });
|
|
|
|
//注册工具拿出和收回,显示隐藏物体的封印的触发
|
|
EventCenter.Instance.AddEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, CheckTriggerShow);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查显示或隐藏封印触发器
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
private void CheckTriggerShow(GameObject obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
//收回
|
|
Debug.Log("收回");
|
|
trigger_seal_1.gameObject.SetActive(false);
|
|
trigger_seal_2.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
//拿出
|
|
Debug.Log("拿出");
|
|
if (obj.name == "盒装封印")
|
|
{
|
|
if (!isCoverOpen && seal_1.isCut && fix_1_screw.isInstall)
|
|
trigger_seal_1.gameObject.SetActive(true);
|
|
|
|
if (!isCoverOpen && seal_2.isCut && fix_2_screw.isInstall)
|
|
trigger_seal_2.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
EventCenter.Instance.RemoveEventListener<GameObject>(Enum_EventType.TakeOutAndRetrievingTheTools, CheckTriggerShow);
|
|
}
|
|
}
|