52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using Sandbox.ModAPI.Ingame;
|
|
|
|
namespace IngameScript
|
|
{
|
|
partial class Program
|
|
{
|
|
public class BlockActionDoor : IBlockAction
|
|
{
|
|
public enum DoorAction
|
|
{
|
|
Open,
|
|
Close,
|
|
}
|
|
|
|
public bool Running { get; private set; } = false;
|
|
|
|
private IMyDoor _door;
|
|
private DoorAction _action;
|
|
private bool _lockDoor;
|
|
|
|
public BlockActionDoor(
|
|
IMyDoor door,
|
|
DoorAction action,
|
|
bool lockDoor = true
|
|
)
|
|
{
|
|
_door = door;
|
|
_action = action;
|
|
_lockDoor = lockDoor;
|
|
}
|
|
|
|
public IEnumerator<bool> Run()
|
|
{
|
|
switch (_action)
|
|
{
|
|
case DoorAction.Open:
|
|
_door.Enabled = true;
|
|
_door.OpenDoor();
|
|
while (_door.Status != DoorStatus.Open) yield return true;
|
|
break;
|
|
case DoorAction.Close:
|
|
_door.Enabled = true;
|
|
_door.CloseDoor();
|
|
while (_door.Status != DoorStatus.Closed) yield return true;
|
|
break;
|
|
}
|
|
if (_lockDoor) _door.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
} |