44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using Sandbox.ModAPI.Ingame;
|
|
|
|
namespace IngameScript
|
|
{
|
|
partial class Program
|
|
{
|
|
public enum ConnectorAction
|
|
{
|
|
Connect,
|
|
Disconnect,
|
|
}
|
|
|
|
public class BlockActionConnector : BlockAction
|
|
{
|
|
private IMyShipConnector _connector;
|
|
private ConnectorAction _action;
|
|
|
|
public BlockActionConnector(
|
|
IMyShipConnector connector,
|
|
ConnectorAction action
|
|
)
|
|
{
|
|
_connector = connector;
|
|
_action = action;
|
|
}
|
|
|
|
protected override IEnumerator<bool> onRun()
|
|
{
|
|
switch (_action)
|
|
{
|
|
case ConnectorAction.Connect:
|
|
_connector.Connect();
|
|
while (_connector.Status != MyShipConnectorStatus.Connected) yield return true;
|
|
break;
|
|
case ConnectorAction.Disconnect:
|
|
_connector.Disconnect();
|
|
while (_connector.Status == MyShipConnectorStatus.Connected) yield return true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |