space_engineers/Mixins/ActionGroups/BlockActionRotor.cs

46 lines
1.2 KiB
C#

using System.Collections.Generic;
using Sandbox.ModAPI.Ingame;
namespace IngameScript
{
partial class Program
{
public class BlockActionRotor : IBlockAction
{
public bool Running { get; private set; } = false;
private IMyMotorStator _rotor;
private float _angle;
private float _velocity;
private MyRotationDirection _direction;
public BlockActionRotor(
IMyMotorStator rotor,
float angle,
float velocity = 5f,
MyRotationDirection direction = MyRotationDirection.AUTO
)
{
_rotor = rotor;
_angle = angle;
_velocity = velocity;
_direction = direction;
}
public IEnumerator<bool> Run()
{
_rotor.RotorLock = false;
_rotor.RotateToAngle(_direction, _angle, _velocity);
float _lastAngle = -1;
while (_rotor.Angle != _lastAngle)
{
_lastAngle = _rotor.Angle;
yield return true;
}
_rotor.RotorLock = true;
}
}
}
}