225 lines
6.9 KiB
C#
225 lines
6.9 KiB
C#
using DG.Tweening;
|
|
using Sirenix.Utilities;
|
|
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;
|
|
|
|
|
|
private BoxCollider boxCollider;
|
|
|
|
|
|
/// <summary>
|
|
/// 初始化电能表状态(默认是装好的状态不用设置)
|
|
/// </summary>
|
|
/// <param name="isIntsalledState"></param>
|
|
public void Init(bool isIntsalledState)
|
|
{
|
|
if(isIntsalledState)
|
|
{
|
|
Debug.Log("电能表设置为初始状态");
|
|
//盖子装上的状态
|
|
CoverInstallState();
|
|
//封印安装上
|
|
CoverSealInstallState();
|
|
//接线螺丝全部拧上状态
|
|
JieXianScrewInstallState();
|
|
//铭牌
|
|
namePlate.isChecked = false;
|
|
//固定螺丝拧上状态
|
|
FixScrewInstall();
|
|
gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("电能表设置为拆下状态");
|
|
//盖子拆下状态
|
|
CoverUnstallState();
|
|
//封印拆掉
|
|
CoverSealUninstallState();
|
|
//接线螺丝拧下状态
|
|
JieXianScrewUninstallState();
|
|
//固定螺丝拧下状态
|
|
FixScrewUninstall();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 盖子取下的状态
|
|
/// </summary>
|
|
public void CoverUnstallState()
|
|
{
|
|
//盖子拆除
|
|
cover.isOpen = true;
|
|
cover.transform.localPosition = new Vector3(0.0001220703f, 0.1388763f, -0.2485413f);
|
|
//左螺丝拧下
|
|
cover.cover_screw_Left.isInstall = false;
|
|
cover.cover_screw_Left.transform.localPosition = new Vector3(cover.cover_screw_Left.transform.localPosition.x, -0.1840515f, -0.2512321f);
|
|
//右螺丝拧下
|
|
cover.cover_screw_Right.isInstall = false;
|
|
cover.cover_screw_Right.transform.localPosition = new Vector3(cover.cover_screw_Right.transform.localPosition.x, -0.1840515f, -0.2512321f);
|
|
}
|
|
/// <summary>
|
|
/// 盖子装上的状态
|
|
/// </summary>
|
|
public void CoverInstallState()
|
|
{
|
|
//盖子盖上
|
|
cover.isOpen = false;
|
|
cover.transform.localPosition = new Vector3(0.0001220703f, -0.01112366f, -0.09854126f);
|
|
//左螺丝拧上
|
|
cover.cover_screw_Left.isInstall = true;
|
|
cover.cover_screw_Left.transform.localPosition = new Vector3(cover.cover_screw_Left.transform.localPosition.x, -0.01405334f, -0.1012321f);
|
|
//右螺丝拧上
|
|
cover.cover_screw_Right.isInstall = true;
|
|
cover.cover_screw_Right.transform.localPosition = new Vector3(cover.cover_screw_Right.transform.localPosition.x, -0.01405334f, -0.1012321f);
|
|
}
|
|
|
|
/// <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 (!fix_screw_left.isInstall && !fix_screw_right.isInstall)
|
|
{
|
|
callback(true);
|
|
hand_out_action?.Invoke();
|
|
Debug.Log("电能表已拆除");
|
|
transform.DOLocalMove(transform.localPosition - new Vector3(0, 0.2f, 0.2f), 2).OnComplete(() =>
|
|
{
|
|
CallScoreAction(false);
|
|
gameObject.SetActive(false);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
callback(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安装电能表到柜子上
|
|
/// </summary>
|
|
public void Add(Device_Control control,Vector3 localPos,Vector3 localAng)
|
|
{
|
|
transform.parent = control.transform;
|
|
transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
|
|
//默认是拆除的状态
|
|
Init(false);
|
|
hand_out_action?.Invoke();
|
|
//从手里飞过去
|
|
transform.localEulerAngles= localAng;
|
|
transform.DOLocalMove(localPos, 2).OnComplete(() =>
|
|
{
|
|
LiveSceneManager.Instance.OnCheckSubProcess(false);
|
|
|
|
Debug.Log("电能表已安装");
|
|
CallScoreAction(true);
|
|
});
|
|
}
|
|
}
|