BITKit/Packages/Common~/Scripts/Door/PhysicsDoor.cs

60 lines
1.3 KiB
C#

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;
void Start()
{
Set();
}
public void Excute()
{
switch (state)
{
case State.Open:
state = State.Close;
Set();
break;
case State.Close:
state = State.Open;
Set();
break;
}
}
void Set(bool isClosed)
{
if (isClosed)
{
root.localEulerAngles = closeEuler;
}
else
{
root.localEulerAngles = openEuler;
}
}
void Set()
{
var isClosed = state switch
{
State.Locked => true,
State.Close => true,
State.Open => false,
_ => true
};
Set(isClosed);
}
}
}