当前位置: 首页>>代码示例>>C#>>正文


C# EventDriver类代码示例

本文整理汇总了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);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:27,代码来源:simpleairlock.cs

示例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);
                }
            }
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:33,代码来源:losminer.cs

示例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);
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:33,代码来源:yawpitchauto.cs

示例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);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:27,代码来源:reversethrust.cs

示例5: Init

 public void Init(ZACommons commons, EventDriver eventDriver,
                  params DockingHandler[] dockingHandlers)
 {
     DockingHandlers = dockingHandlers;
     var docked = ZACommons.IsConnectedAnywhere(commons.Blocks);
     ManageShip(commons, eventDriver, docked);
 }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:7,代码来源:dockingmanager.cs

示例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);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:28,代码来源:dumbshell.cs

示例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);
 }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:7,代码来源:damagecontrol.cs

示例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);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:34,代码来源:doorautocloser.cs

示例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);
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:32,代码来源:sequencer.cs

示例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;
             }
     }
 }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:34,代码来源:reactormanager.cs

示例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);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:29,代码来源:sequencer.cs

示例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);
                }
            });
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:31,代码来源:doorautocloser.cs

示例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);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:34,代码来源:reactormanager.cs

示例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;
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:33,代码来源:losminer.cs

示例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;
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:25,代码来源:rotorrangefinder.cs


注:本文中的EventDriver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。