109 lines
2.5 KiB
C#
109 lines
2.5 KiB
C#
using DG.Tweening;
|
|
using HighlightPlus;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
/// <summary>
|
|
/// 普通门
|
|
/// </summary>
|
|
public class Door : Device_Base
|
|
{
|
|
public bool isOpen;
|
|
public ZhouEnum zhouEnum;
|
|
public float angele;
|
|
public float duration;
|
|
|
|
|
|
Dictionary<bool, Vector3> dic;
|
|
//[SerializeField]
|
|
private Vector3 initR;
|
|
//[SerializeField]
|
|
private Vector3 nextR;
|
|
|
|
/// <summary>
|
|
/// 判断是否可以打开或关闭
|
|
/// </summary>
|
|
public Func<bool> canOpen;
|
|
|
|
|
|
/// <summary>
|
|
/// 验电位置
|
|
/// </summary>
|
|
public Transform testPosAndRot;
|
|
/// <summary>
|
|
/// 是否带电
|
|
/// </summary>
|
|
[ReconnetAtrribute]
|
|
public bool hasElectricity;
|
|
|
|
public DoorGroup group;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
GetEndAngle();
|
|
}
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
|
|
if (LiveSceneManager.Instance?.currentTool != null && LiveSceneManager.Instance?.currentTool.name == "验电笔")
|
|
return;
|
|
|
|
if (group != null)
|
|
{
|
|
if (triggerAction == null || triggerAction.Invoke(triggerName, true) == 0)
|
|
group.OpenOrClose();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
bool canopen = (canOpen != null ? canOpen.Invoke() : true);
|
|
if (canopen)
|
|
{
|
|
if (triggerAction == null || triggerAction.Invoke(triggerName, true) == 0)
|
|
{
|
|
CanOpen();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CanOpen()
|
|
{
|
|
isOpen = !isOpen;
|
|
transform.DOLocalRotate(dic[isOpen], duration).OnComplete(() => { base.CallScoreAction(isOpen); });
|
|
}
|
|
|
|
private void GetEndAngle()
|
|
{
|
|
initR = transform.localEulerAngles;
|
|
transform.Rotate(new Vector3(zhouEnum == ZhouEnum.X ? 1 : 0, zhouEnum == ZhouEnum.Y ? 1 : 0, zhouEnum == ZhouEnum.Z ? 1 : 0), angele, Space.Self);
|
|
nextR = transform.localEulerAngles;
|
|
transform.localEulerAngles = initR;
|
|
|
|
dic = new Dictionary<bool, Vector3>();
|
|
dic.Add(isOpen, initR);
|
|
dic.Add(!isOpen, nextR);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置门状态
|
|
/// </summary>
|
|
/// <param name="isOpen"></param>
|
|
public void SetState(bool isOpen)
|
|
{
|
|
this.isOpen = isOpen;
|
|
transform.localEulerAngles = dic[isOpen];
|
|
}
|
|
}
|
|
public enum ZhouEnum
|
|
{
|
|
X,
|
|
Y,
|
|
Z
|
|
}
|