• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ZACommons类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ZACommons的典型用法代码示例。如果您正苦于以下问题:C# ZACommons类的具体用法?C# ZACommons怎么用?C# ZACommons使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ZACommons类属于命名空间,在下文中一共展示了ZACommons类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AcquireTarget

    public void AcquireTarget(ZACommons commons)
    {
        // Find the sole text panel
        var panelGroup = commons.GetBlockGroupWithName("CM Target");
        if (panelGroup == null)
        {
            throw new Exception("Missing group: CM Target");
        }

        var panels = ZACommons.GetBlocksOfType<IMyTextPanel>(panelGroup.Blocks);
        if (panels.Count == 0)
        {
            throw new Exception("Expecting at least 1 text panel");
        }
        var panel = panels[0] as IMyTextPanel; // Just use the first one
        var targetString = panel.GetPublicText();

        // Parse target info
        var parts = targetString.Split(';');
        if (parts.Length != 3)
        {
            throw new Exception("Expecting exactly 3 parts to target info");
        }
        Target = new Vector3D();
        for (int i = 0; i < 3; i++)
        {
            Target.SetDim(i, double.Parse(parts[i]));
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:29,代码来源:missileguidance.cs


示例2: 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


示例3: Reset

 private void Reset(ZACommons commons)
 {
     var thrustControl = ((ShipControlCommons)commons).ThrustControl;
     var collect = ParseCruiseFlags();
     thrustControl.Enable(true, collect);
     thrustControl.Reset(collect);
 }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:7,代码来源:cruisecontrol.cs


示例4: 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


示例5: AcquireTarget

    // Acquire target from CM Target text panel. If anything's wrong,
    // return null.
    private Vector3D? AcquireTarget(ZACommons commons)
    {
        // Find the sole text panel
        var panelGroup = commons.GetBlockGroupWithName("CM Target");
        if (panelGroup == null) return null;

        var panels = ZACommons.GetBlocksOfType<IMyTextPanel>(panelGroup.Blocks);
        if (panels.Count == 0) return null;
        var panel = panels[0] as IMyTextPanel; // Just use the first one
        var targetString = panel.GetPublicText();

        // Parse target info
        var parts = targetString.Split(';');
        if (parts.Length != 3) return null;

        var target = new Vector3D();
        for (int i = 0; i < 3; i++)
        {
            double coord;
            if (!double.TryParse(parts[i], out coord)) return null;
            target.SetDim(i, coord);
        }

        return target;
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:27,代码来源:smartshell.cs


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: HandleCommand

    public void HandleCommand(ZACommons commons, EventDriver eventDriver,
                              string argument)
    {
        argument = argument.Trim().ToLower();

        var parts = argument.Split(new char[] { ' ' }, 2);
        if (parts.Length != 2 || parts[0] != "damecon") return;
        var command = parts[1];

        switch (command)
        {
            case "reset":
            case "stop":
                commons.AllBlocks.ForEach(block => {
                        if (block.GetProperty("ShowOnHUD") != null) block.SetValue<bool>("ShowOnHUD", false);
                    });
                ResetMode(commons);
                break;
            case "show":
                Show(commons);
                ResetMode(commons);
                break;
            case "start":
                Start(commons, eventDriver, false);
                break;
            case "auto":
                Start(commons, eventDriver, true);
                break;
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:30,代码来源:damagecontrol.cs


示例13: Prime

    public void Prime(ZACommons commons, EventDriver eventDriver)
    {
        // Wake up batteries
        var batteryGroup = commons.GetBlockGroupWithName(BATTERY_GROUP + MISSILE_GROUP_SUFFIX);
        if (batteryGroup == null)
        {
            throw new Exception("Group missing: " + BATTERY_GROUP + MISSILE_GROUP_SUFFIX);
        }
        var systemsGroup = commons.GetBlockGroupWithName(SYSTEMS_GROUP + MISSILE_GROUP_SUFFIX);
        if (systemsGroup == null)
        {
            throw new Exception("Group missing: " + SYSTEMS_GROUP + MISSILE_GROUP_SUFFIX);
        }

        var batteries = ZACommons.GetBlocksOfType<IMyBatteryBlock>(batteryGroup.Blocks);
        batteries.ForEach(battery =>
                {
                    battery.SetValue<bool>("OnOff", true);
                    battery.SetValue<bool>("Recharge", false);
                    battery.SetValue<bool>("Discharge", true);
                });

        // Activate flight systems
        ZACommons.EnableBlocks(systemsGroup.Blocks, true);

        eventDriver.Schedule(1.0, Release);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:27,代码来源:missilelaunch.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: 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


示例16: LowBattery

    public void LowBattery(ZACommons commons, EventDriver eventDriver,
                           bool started)
    {
        if (started)
        {
            // Just change the name of the first active antenna
            for (var e = ZACommons.GetBlocksOfType<IMyRadioAntenna>(commons.Blocks).GetEnumerator(); e.MoveNext();)
            {
                var antenna = e.Current;

                if (antenna.IsFunctional && antenna.IsWorking)
                {
                    OldAntennaName = antenna.CustomName;
                    antenna.SetCustomName(Message);
                    break;
                }
            }
        }
        else
        {
            // Scan for the antenna with the message, change it back
            for (var e = ZACommons.GetBlocksOfType<IMyRadioAntenna>(commons.Blocks).GetEnumerator(); e.MoveNext();)
            {
                var antenna = e.Current;

                if (antenna.CustomName == Message)
                {
                    antenna.SetCustomName(OldAntennaName);
                    break;
                }
            }
        }
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:33,代码来源:relaysatellite.cs


示例17: 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


示例18: 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


示例19: 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


示例20: Run

    public void Run(ZACommons commons, EventDriver eventDriver)
    {
        var vents = ZACommons.GetBlocksOfType<IMyAirVent>(commons.AllBlocks,
                                                          vent => vent.IsFunctional &&
                                                          vent.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0 &&
                                                          vent.CustomName.IndexOf("[Intake]", ZACommons.IGNORE_CASE) < 0);

        vents.ForEach(block =>
                {
                    var vent = (IMyAirVent)block;
                    var level = vent.GetOxygenLevel();
                    if (vent.IsDepressurizing && !vent.Enabled && level > 0.0f)
                    {
                        vent.SetValue<bool>("OnOff", true);
                    }
                    else if (!vent.IsDepressurizing)
                    {
                        if (level < MIN_AIR_VENT_PRESSURE && !vent.Enabled)
                        {
                            vent.SetValue<bool>("OnOff", true);
                        }
                        else if (level > MAX_AIR_VENT_PRESSURE && vent.Enabled)
                        {
                            vent.SetValue<bool>("OnOff", false);
                        }
                    }
                });

        eventDriver.Schedule(RunDelay, Run);
    }
开发者ID:ZerothAngel,项目名称:SEScripts,代码行数:30,代码来源:airventmanager.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ZJGEport类代码示例发布时间:2022-05-24
下一篇:
C# Z3_sort类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap