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; /// /// 固定螺丝 /// public Tool_Screw fix_1_screw; /// /// 固定螺丝 /// 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 盖子 /// /// 盖子 /// public DeviceTrigger cover; /// /// 盖子是否打开 /// public bool isCoverOpen; /// /// 盖子关闭位置 /// public Vector3 CloseLocalPos; /// /// 盖子打开位置 /// public Vector3 OpenLocalPos; #endregion /// /// 拨片 /// public List boPians; /// /// 接线螺丝 /// public List jeixian_screws; /// /// 安装和取下的回调 /// public Action inOrUnstallAction; //protected override void OnMDown() //{ // base.OnMDown(); // Remove(); //} /// /// 安装端子盒 /// /// /// /// /// public void Add(Device_Control device_Control, Vector3 localPos, Vector3 loacalAng, string triggerName, Action 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(true).ToList().ForEach(a => a.Awake()); //禁用拿取碰撞 GetComponent().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); }); } /// /// 拆除端子盒 /// public void Remove() { if (!fix_1_screw.isInstall && !fix_2_screw.isInstall) { Debug.Log("端子盒已拆除"); inOrUnstallAction?.Invoke(false); } } /// /// 直接安装上 /// /// /// /// /// 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(true).ToList().ForEach(a => a.Awake()); //禁用拿取碰撞 GetComponent().enabled = false; } else { //拆下状态 } } /// /// 设置螺丝拆开状态 /// 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); } /// /// 设置螺丝安装状态 /// 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(Enum_EventType.TakeOutAndRetrievingTheTools, CheckTriggerShow); } /// /// 检查显示或隐藏封印触发器 /// /// 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(Enum_EventType.TakeOutAndRetrievingTheTools, CheckTriggerShow); } }