本文整理汇总了C#中EventDriver类的典型用法代码示例。如果您正苦于以下问题:C# EventDriver类的具体用法?C# EventDriver怎么用?C# EventDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventDriver类属于命名空间,在下文中一共展示了EventDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
var groups = commons.GetBlockGroupsWithPrefix(SIMPLE_AIRLOCK_GROUP_PREFIX);
for (var e = groups.GetEnumerator(); e.MoveNext();)
{
var doors = ZACommons.GetBlocksOfType<IMyDoor>(e.Current.Blocks,
door => door.CubeGrid == commons.Me.CubeGrid &&
door.IsFunctional);
var opened = IsAnyDoorOpen(doors);
for (var f = doors.GetEnumerator(); f.MoveNext();)
{
var door = (IMyDoor)f.Current;
if (door.OpenRatio == 0.0f && opened)
{
// This door is not open and some other door in the group is, lock it down
if (door.Enabled) door.SetValue<bool>("OnOff", false);
}
else
{
if (!door.Enabled) door.SetValue<bool>("OnOff", true);
}
}
}
eventDriver.Schedule(RunDelay, Run);
}
示例2: Init
public void Init(ZACommons commons, EventDriver eventDriver)
{
var previous = commons.GetValue(LOSMinerKey);
if (previous != null)
{
var parts = previous.Split(';');
if (parts.Length == 13)
{
// Resume original mode and line-of-sight vector
var newMode = int.Parse(parts[0]);
StartPoint = new Vector3D();
StartDirection = new Vector3D();
StartUp = new Vector3D();
StartLeft = new Vector3D();
for (int i = 0; i < 3; i++)
{
StartPoint.SetDim(i, double.Parse(parts[i+1]));
StartDirection.SetDim(i, double.Parse(parts[i+4]));
StartUp.SetDim(i, double.Parse(parts[i+7]));
StartLeft.SetDim(i, double.Parse(parts[i+10]));
}
if (newMode == MINING)
{
Start((ShipControlCommons)commons, eventDriver);
}
else if (newMode == REVERSING)
{
StartReverse((ShipControlCommons)commons, eventDriver);
}
}
}
}
示例3: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
if (!AutopilotEngaged)
{
Reset(commons);
return;
}
var shipControl = (ShipControlCommons)commons;
var targetVector = AutopilotTarget - shipControl.ReferencePoint;
var distance = targetVector.Normalize();
double yawError, pitchError;
var gyroControl = seeker.Seek(shipControl, targetVector,
out yawError, out pitchError);
var targetSpeed = Math.Min(distance / AUTOPILOT_TTT_BUFFER,
AutopilotSpeed);
targetSpeed = Math.Max(targetSpeed, AUTOPILOT_MIN_SPEED); // Avoid Zeno's paradox...
cruiser.Cruise(shipControl, eventDriver, targetSpeed);
if (distance < AUTOPILOT_DISENGAGE_DISTANCE)
{
Reset(commons);
if (DoneAction != null) DoneAction(commons, eventDriver);
}
else
{
eventDriver.Schedule(FramesPerRun, Run);
}
}
示例4: Init
public void Init(ZACommons commons, EventDriver eventDriver,
double maxError,
Base6Directions.Direction thrusterDirection = Base6Directions.Direction.Forward)
{
MaxError = maxError;
ThrusterDirection = thrusterDirection;
var shipControl = (ShipControlCommons)commons;
var forward = shipControl.ShipBlockOrientation.TransformDirection(ThrusterDirection);
// Don't really care about "up," just pick a perpindicular direction
seeker.Init(shipControl,
shipUp: Base6Directions.GetPerpendicular(forward),
shipForward: forward);
var gyroControl = shipControl.GyroControl;
gyroControl.Reset();
gyroControl.EnableOverride(true);
LastPosition = shipControl.ReferencePoint;
Enabled = true;
shipControl.ThrustControl.Enable(false);
eventDriver.Schedule(SampleDelay, DetermineVelocity);
}
示例5: Init
public void Init(ZACommons commons, EventDriver eventDriver,
params DockingHandler[] dockingHandlers)
{
DockingHandlers = dockingHandlers;
var docked = ZACommons.IsConnectedAnywhere(commons.Blocks);
ManageShip(commons, eventDriver, docked);
}
示例6: Demass
public void Demass(ZACommons commons, EventDriver eventDriver)
{
var shipControl = (ShipControlCommons)commons;
var deltaTime = (eventDriver.TimeSinceStart - InitialTime).TotalSeconds;
var launcherDelta = LauncherVelocity * deltaTime;
var distanceFromLauncher = (shipControl.ReferencePoint -
(InitialPosition + launcherDelta)).LengthSquared();
if (distanceFromLauncher < DemassDistance * DemassDistance)
{
// Not yet
eventDriver.Schedule(TicksPerRun, Demass);
return;
}
// Disable mass
var group = commons.GetBlockGroupWithName(MASS_GROUP);
if (group != null) ZACommons.EnableBlocks(group.Blocks, false);
// Start roll
shipControl.GyroControl.EnableOverride(true);
shipControl.GyroControl.SetAxisVelocity(GyroControl.Roll,
MathHelper.Pi);
// All done
if (PostLaunch != null) PostLaunch(commons, eventDriver);
}
示例7: Start
private void Start(ZACommons commons, EventDriver eventDriver, bool auto)
{
Show(commons);
if (Mode == IDLE) eventDriver.Schedule(RunDelay, Run);
Mode = auto ? AUTO : ACTIVE;
SaveMode(commons);
}
示例8: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
var groups = commons.GetBlockGroupsWithPrefix(DOOR_AUTO_CLOSER_PREFIX);
if (groups.Count > 0)
{
groups.ForEach(group => {
// Determine open duration
var parts = group.Name.Split(new char[] { DURATION_DELIMITER }, 2);
var duration = DEFAULT_DOOR_OPEN_DURATION;
if (parts.Length == 2)
{
if (!double.TryParse(parts[1], out duration))
{
duration = DEFAULT_DOOR_OPEN_DURATION;
}
}
var doors = ZACommons.GetBlocksOfType<IMyDoor>(group.Blocks,
block => block.IsFunctional);
CloseDoors(commons, eventDriver, doors, duration);
});
}
else
{
// Default behavior (all doors except vanilla Airtight Hangar Doors and tagged doors)
var doors = ZACommons
.GetBlocksOfType<IMyDoor>(commons.Blocks,
block => block.IsFunctional &&
block.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0 &&
block.DefinitionDisplayNameText != "Airtight Hangar Door");
CloseDoors(commons, eventDriver, doors, DEFAULT_DOOR_OPEN_DURATION);
}
eventDriver.Schedule(RunDelay, Run);
}
示例9: HandleCommand
public void HandleCommand(ZACommons commons, EventDriver eventDriver,
string argument)
{
argument = argument.Trim().ToLower();
var parts = argument.Split(new char[] { ' ' }, 3);
if (parts.Length < 3 || parts[0] != "sequence") return;
var command = parts[1];
var sequence = parts[2];
if (command == "start")
{
var blocks = GetSequenceBlocks(commons, sequence);
if (blocks == null) return;
ZACommons.EnableBlocks(blocks, false);
blocks[0].SetValue<bool>("OnOff", true);
var first = Indexes.Count == 0;
if (!Indexes.ContainsKey(sequence)) Indexes.Add(sequence, 0);
if (first)
{
eventDriver.Schedule(SEQUENCER_FRAMES_PER_RUN, Run);
}
}
else if (command == "stop")
{
var blocks = GetSequenceBlocks(commons, sequence);
if (blocks != null) ZACommons.EnableBlocks(blocks, true);
Indexes.Remove(sequence);
}
}
示例10: HandleCommand
public void HandleCommand(ZACommons commons, EventDriver eventDriver,
string argument)
{
var command = argument.Trim().ToLower();
switch (command)
{
case "reactors":
{
// Turn on all reactors
GetAllReactors(commons).ForEach(block => block.SetValue<bool>("OnOff", true));
eventDriver.Schedule(1.0, (c,ed) => {
// Turn off all local batteries
GetBatteries(c).ForEach(block => block.SetValue<bool>("OnOff", false));
});
break;
}
case "batteries":
{
// Turn on all local batteries
// and disable recharge/discharge
GetBatteries(commons).ForEach(block =>
{
block.SetValue<bool>("OnOff", true);
block.SetValue<bool>("Recharge", false);
block.SetValue<bool>("Discharge", false);
});
eventDriver.Schedule(1.0, (c,ed) => {
// Turn off all reactors
GetAllReactors(c).ForEach(block => block.SetValue<bool>("OnOff", false));
});
break;
}
}
}
示例11: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
if (Indexes.Count == 0) return;
var newIndexes = new Dictionary<string, int>();
for (var e = Indexes.GetEnumerator(); e.MoveNext();)
{
var kv = e.Current;
var sequence = kv.Key;
var index = kv.Value;
var blocks = GetSequenceBlocks(commons, sequence);
if (blocks == null) continue;
ZACommons.EnableBlocks(blocks, false);
// TODO sort?
index++;
index %= blocks.Count;
blocks[index].SetValue<bool>("OnOff", true);
newIndexes.Add(sequence, index);
}
Indexes = newIndexes;
eventDriver.Schedule(SEQUENCER_FRAMES_PER_RUN, Run);
}
示例12: CloseDoors
private void CloseDoors(ZACommons commons, EventDriver eventDriver, List<IMyTerminalBlock> doors,
double openDurationSeconds)
{
var openDuration = TimeSpan.FromSeconds(openDurationSeconds);
doors.ForEach(block => {
var door = (IMyDoor)block;
if (door.Open)
{
TimeSpan closeTime;
if (opened.TryGetValue(door, out closeTime))
{
if (closeTime <= eventDriver.TimeSinceStart)
{
// Time to close it
door.SetValue<bool>("Open", false);
opened.Remove(door);
}
}
else
{
opened.Add(door, eventDriver.TimeSinceStart + openDuration);
}
}
else
{
opened.Remove(door);
}
});
}
示例13: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
var myConnectors = ZACommons.GetBlocksOfType<IMyShipConnector>(commons.Blocks,
block => block.DefinitionDisplayNameText == "Connector" &&
((IMyShipConnector)block).IsLocked &&
((IMyShipConnector)block).IsConnected);
var currentConnectorCount = myConnectors.Count;
if (currentConnectorCount > ConnectorCount)
{
// New connection, force re-evaluation
State = null;
}
ConnectorCount = currentConnectorCount;
var myReactors = ZACommons.GetBlocksOfType<IMyReactor>(commons.Blocks,
block => block.IsWorking);
var currentState = myReactors.Count > 0;
// Only on state change
if (State == null || currentState != (bool)State)
{
State = currentState;
if (!(bool)State)
{
// Disable reactors on all connected grids
var reactors = ZACommons.GetBlocksOfType<IMyReactor>(commons.AllBlocks,
block => block.CubeGrid != commons.Me.CubeGrid);
reactors.ForEach(block => block.SetValue<bool>("OnOff", false));
}
}
eventDriver.Schedule(RunDelay, Run);
}
示例14: HandleCommand
public void HandleCommand(ZACommons commons, EventDriver eventDriver,
string argument)
{
var command = argument.Trim().ToLower();
switch (command)
{
case "start":
{
var shipControl = (ShipControlCommons)commons;
SetTarget(shipControl);
Start(shipControl, eventDriver);
SaveTarget(shipControl);
}
break;
case "reverse":
{
var shipControl = (ShipControlCommons)commons;
SetTarget(shipControl);
StartReverse(shipControl, eventDriver);
SaveTarget(shipControl);
}
break;
case "stop":
{
var shipControl = (ShipControlCommons)commons;
shipControl.Reset(gyroOverride: false);
Mode = IDLE;
ForgetTarget(shipControl);
}
break;
}
}
示例15: HandleCommand
public void HandleCommand(ZACommons commons, EventDriver eventDriver,
string argument, Action<ZACommons, Vector3D> targetAction)
{
argument = argument.Trim().ToLower();
switch (argument)
{
case "compute":
var firstReference = GetReference(commons, STATIC_REFERENCE_GROUP);
var rotorReference = GetReference(commons, ROTOR_REFERENCE_GROUP);
var first = new Rangefinder.LineSample(firstReference);
var second = new Rangefinder.LineSample(rotorReference);
Vector3D closestFirst, closestSecond;
if (Rangefinder.Compute(first, second, out closestFirst, out closestSecond))
{
// Take midpoint of closestFirst-closestSecond segment
var target = (closestFirst + closestSecond) / 2.0;
targetAction(commons, target);
}
break;
default:
rotorStepper.HandleCommand(commons, eventDriver, argument);
break;
}
}