277 lines
9.1 KiB
C#
277 lines
9.1 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 3相4线电能表
|
|
/// </summary>
|
|
public class Device_3Phase4WireMeter : Device_Base
|
|
{
|
|
/// <summary>
|
|
/// 铭牌
|
|
/// </summary>
|
|
public Device_NamePlate namePlate;
|
|
|
|
/// <summary>
|
|
/// 接线盖子
|
|
/// </summary>
|
|
public Device_Cover cover;
|
|
|
|
/// <summary>
|
|
/// 电能表固定螺丝左
|
|
/// </summary>
|
|
public Tool_Screw fix_screw_left;
|
|
/// <summary>
|
|
/// 电能表固定螺丝右
|
|
/// </summary>
|
|
public Tool_Screw fix_screw_right;
|
|
/// <summary>
|
|
/// 电能表接线螺丝
|
|
/// </summary>
|
|
public List<Tool_Screw> jieXian_screws;
|
|
/// <summary>
|
|
/// 电能表屏显
|
|
/// </summary>
|
|
public Device_ScreemControl screemControl;
|
|
/// <summary>
|
|
/// 连线点
|
|
/// </summary>
|
|
public List<Line_end> line_Ends;
|
|
/// <summary>
|
|
/// 强弱电隔离板
|
|
/// </summary>
|
|
public ClickMove isolationBoard;
|
|
/// <summary>
|
|
/// 拆除的位置
|
|
/// </summary>
|
|
public Vector3 unInstallLocalPosition;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
//安装拆卸条件
|
|
isolationBoard.canOpen += () => {return cover.isOpen;};
|
|
}
|
|
/// <summary>
|
|
/// 初始化电能表状态(默认是装好的状态不用设置)
|
|
/// </summary>
|
|
/// <param name="isIntsalledState"></param>
|
|
public void Init(bool isIntsalledState)
|
|
{
|
|
if(isIntsalledState)
|
|
{
|
|
//Debug.Log("电能表设置为初始状态");
|
|
//盖子装上的状态
|
|
CoverInstallState();
|
|
//封印安装上
|
|
CoverSealInstallState();
|
|
//接线螺丝全部拧上状态
|
|
JieXianScrewInstallState();
|
|
//铭牌
|
|
namePlate.isChecked = false;
|
|
//固定螺丝拧上状态
|
|
FixScrewInstall();
|
|
//隔离板打开
|
|
isolationBoard.SetState(false);
|
|
gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("电能表设置为拆下状态");
|
|
//盖子拆下状态
|
|
CoverUnstallState();
|
|
//封印拆掉
|
|
CoverSealUninstallState();
|
|
//接线螺丝拧下状态
|
|
JieXianScrewUninstallState();
|
|
//固定螺丝拧下状态
|
|
FixScrewUninstall();
|
|
//隔离板打开
|
|
isolationBoard.SetState(true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 盖子取下的状态
|
|
/// </summary>
|
|
public void CoverUnstallState()
|
|
{
|
|
//盖子拆除
|
|
cover.isOpen = true;
|
|
cover.transform.localPosition = cover.openLocalPos;
|
|
//左螺丝拧下
|
|
cover.cover_screw_Left.isInstall = false;
|
|
cover.cover_screw_Left.transform.localPosition = new Vector3(cover.cover_screw_Left.transform.localPosition.x, cover.cover_screw_Left.initPostionY-0.03f, cover.cover_screw_Left.transform.localPosition.z);
|
|
//右螺丝拧下
|
|
cover.cover_screw_Right.isInstall = false;
|
|
cover.cover_screw_Right.transform.localPosition = new Vector3(cover.cover_screw_Right.transform.localPosition.x, cover.cover_screw_Right.initPostionY-0.03f, cover.cover_screw_Right.transform.localPosition.z);
|
|
}
|
|
/// <summary>
|
|
/// 盖子装上的状态
|
|
/// </summary>
|
|
public void CoverInstallState()
|
|
{
|
|
//盖子盖上
|
|
cover.isOpen = false;
|
|
cover.transform.localPosition = cover.closeLocalPos;
|
|
//左螺丝拧上
|
|
cover.cover_screw_Left.isInstall = true;
|
|
cover.cover_screw_Left.transform.localPosition = new Vector3(cover.cover_screw_Left.transform.localPosition.x,cover.cover_screw_Left.initPostionY, cover.cover_screw_Left.transform.localPosition.z);
|
|
//右螺丝拧上
|
|
cover.cover_screw_Right.isInstall = true;
|
|
cover.cover_screw_Right.transform.localPosition = new Vector3(cover.cover_screw_Right.transform.localPosition.x, cover.cover_screw_Right.initPostionY, cover.cover_screw_Right.transform.localPosition.z);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 盖子封印装上
|
|
/// </summary>
|
|
public void CoverSealInstallState()
|
|
{
|
|
//左封印安装
|
|
cover.cover_seal_Left.isCut = false;
|
|
cover.cover_seal_Left.gameObject.SetActive(true);
|
|
//右封印安装
|
|
cover.cover_seal_Right.isCut = false;
|
|
cover.cover_seal_Right.gameObject.SetActive(true);
|
|
}
|
|
/// <summary>
|
|
/// 封印卸载
|
|
/// </summary>
|
|
public void CoverSealUninstallState()
|
|
{
|
|
//左封印被剪开
|
|
cover.cover_seal_Left.isCut = true;
|
|
cover.cover_seal_Left.gameObject.SetActive(false);
|
|
//右封印被剪开
|
|
cover.cover_seal_Right.isCut = true;
|
|
cover.cover_seal_Right.gameObject.SetActive(false);
|
|
}
|
|
/// <summary>
|
|
/// 接线螺丝拧上状态
|
|
/// </summary>
|
|
public void JieXianScrewInstallState()
|
|
{
|
|
//接线螺丝全部拧上
|
|
jieXian_screws.ForEach(a =>
|
|
{
|
|
a.isInstall = true;
|
|
a.transform.localPosition = new Vector3(a.transform.localPosition.x, a.initPostionY, a.transform.localPosition.z);
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 接线螺丝拧下状态
|
|
/// </summary>
|
|
public void JieXianScrewUninstallState()
|
|
{
|
|
jieXian_screws.ForEach(a =>
|
|
{
|
|
a.isInstall = false;
|
|
a.transform.localPosition = new Vector3(a.transform.localPosition.x, a.initPostionY - 0.03f, a.transform.localPosition.z);
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 固定螺丝装上
|
|
/// </summary>
|
|
public void FixScrewInstall()
|
|
{
|
|
//左固定螺丝拧上
|
|
fix_screw_left.isInstall = true;
|
|
fix_screw_left.transform.localPosition = new Vector3(fix_screw_left.transform.localPosition.x, fix_screw_left.initPostionY, fix_screw_left.transform.localPosition.z);
|
|
//右固定螺丝拧上
|
|
fix_screw_right.isInstall = true;
|
|
fix_screw_right.transform.localPosition = new Vector3(fix_screw_right.transform.localPosition.x, fix_screw_right.initPostionY, fix_screw_right.transform.localPosition.z);
|
|
|
|
}
|
|
/// <summary>
|
|
/// 固定螺丝拧下
|
|
/// </summary>
|
|
public void FixScrewUninstall()
|
|
{
|
|
//左固定螺丝拧下
|
|
fix_screw_left.isInstall = false;
|
|
fix_screw_left.transform.localPosition = new Vector3(fix_screw_left.transform.localPosition.x, fix_screw_left.initPostionY - 0.03f, fix_screw_left.transform.localPosition.z);
|
|
//右固定螺丝拧下
|
|
fix_screw_right.isInstall = false;
|
|
fix_screw_right.transform.localPosition = new Vector3(fix_screw_right.transform.localPosition.x, fix_screw_right.initPostionY - 0.03f, fix_screw_right.transform.localPosition.z);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆下电能表
|
|
/// </summary>
|
|
public void Remove(Action<bool> callback)
|
|
{
|
|
if (!isMoving)
|
|
{
|
|
//拆下电能表
|
|
if (!fix_screw_left.isInstall && !fix_screw_right.isInstall)
|
|
{
|
|
isMoving = true;
|
|
callback(true);
|
|
hand_out_action?.Invoke();
|
|
Debug.Log("电能表已拆除");
|
|
transform.DOLocalMove(unInstallLocalPosition,1).OnComplete(() =>
|
|
{
|
|
isMoving = false;
|
|
CallScoreAction(false);
|
|
Destroy(gameObject);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
callback(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安装电能表到柜子上
|
|
/// </summary>
|
|
public void Add(DeviceTrigger deviceTrigger ,Vector3 uninstallLocalPostion,Action<bool> installAction)
|
|
{
|
|
if (!isMoving)
|
|
{
|
|
isMoving = true;
|
|
this.unInstallLocalPosition = uninstallLocalPostion;
|
|
transform.parent = deviceTrigger.transform.parent;
|
|
transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
|
|
//默认是拆除的状态
|
|
Init(false);
|
|
hand_out_action?.Invoke();
|
|
//从手里飞过去
|
|
transform.localEulerAngles = deviceTrigger.transform.localEulerAngles;
|
|
transform.DOLocalMove(deviceTrigger.transform.localPosition, 2).OnComplete(() =>
|
|
{
|
|
isMoving = false;
|
|
installAction?.Invoke(true);
|
|
triggerAction?.Invoke(deviceTrigger.triggerName,true);
|
|
LiveSceneManager.Instance.OnCheckSubProcess(false);
|
|
Debug.Log("电能表已安装");
|
|
CallScoreAction(true);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 直接安装上
|
|
/// </summary>
|
|
public void SetAddState(DeviceTrigger deviceTrigger, Vector3 uninstallLocalPostion)
|
|
{
|
|
this.unInstallLocalPosition = uninstallLocalPostion;
|
|
transform.parent = deviceTrigger.transform.parent;
|
|
transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
|
|
//默认是拆除的状态
|
|
Init(false);
|
|
//从手里飞过去
|
|
transform.localEulerAngles = deviceTrigger.transform.localEulerAngles;
|
|
transform.localPosition = deviceTrigger.transform.localPosition;
|
|
|
|
//手动初始化
|
|
transform.GetComponentsInChildren<Tool_Base>(true).ToList().ForEach(a => a.Awake());
|
|
transform.GetComponentsInChildren<Device_Base>(true).ToList().ForEach(a => a.Awake());
|
|
}
|
|
}
|