BITFALL/Assets/BITKit/Unity/Scripts/Door/PhysicsDoor.cs

54 lines
1.3 KiB
C#
Raw Normal View History

2023-06-08 14:09:50 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class PhysicsDoor : MonoBehaviour, IAction
{
public enum State
{
Close,
Open,
HalfOpen,
Locked,
}
public Transform root;
public Vector3 openEuler;
public Vector3 closeEuler;
public State state;
2023-08-27 02:58:19 +08:00
private void Start()
2023-06-08 14:09:50 +08:00
{
Set();
}
2023-08-12 01:43:24 +08:00
public void Execute()
2023-06-08 14:09:50 +08:00
{
switch (state)
{
case State.Open:
state = State.Close;
Set();
break;
case State.Close:
state = State.Open;
Set();
break;
}
}
2023-08-27 02:58:19 +08:00
public void Set(bool isClosed)
2023-06-08 14:09:50 +08:00
{
2023-08-27 02:58:19 +08:00
state = isClosed ? State.Close : State.Open;
root.localEulerAngles = isClosed ? closeEuler : openEuler;
2023-06-08 14:09:50 +08:00
}
2023-08-27 02:58:19 +08:00
private void Set()
2023-06-08 14:09:50 +08:00
{
var isClosed = state switch
{
State.Locked => true,
State.Close => true,
State.Open => false,
_ => true
};
Set(isClosed);
}
}
}