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


C# IMyEntity.FindWorkingCockpits方法代码示例

本文整理汇总了C#中IMyEntity.FindWorkingCockpits方法的典型用法代码示例。如果您正苦于以下问题:C# IMyEntity.FindWorkingCockpits方法的具体用法?C# IMyEntity.FindWorkingCockpits怎么用?C# IMyEntity.FindWorkingCockpits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMyEntity的用法示例。


在下文中一共展示了IMyEntity.FindWorkingCockpits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MoveTo

        /// <summary>
        /// Move a player, to another entity (which can be of Grid, Voxel).
        /// </summary>
        /// <param name="sourcePlayer"></param>
        /// <param name="target"></param>
        /// <param name="safely"></param>
        /// <param name="updatedPosition"></param>
        /// <param name="emptySourceMessage"></param>
        /// <param name="emptyTargetMessage"></param>
        /// <param name="noSafeLocationMessage"></param>
        /// <returns></returns>
        public static bool MoveTo(IMyPlayer sourcePlayer, IMyEntity target, bool safely,
            Action<Vector3D> updatedPosition, Action emptySourceMessage, Action emptyTargetMessage, Action noSafeLocationMessage)
        {
            if (sourcePlayer == null)
            {
                if (emptySourceMessage != null)
                    emptySourceMessage.Invoke();
                return false;
            }

            if (target == null || target.Closed)
            {
                if (emptyTargetMessage != null)
                    emptyTargetMessage.Invoke();
                return false;
            }

            if (sourcePlayer.Controller.ControlledEntity is IMyCubeBlock)
            {
                // player is piloting a ship. Move ship to entity.
                return MoveTo(sourcePlayer.Controller.ControlledEntity.Entity.GetTopMostParent(), target, safely, updatedPosition, emptySourceMessage, emptyTargetMessage, noSafeLocationMessage);
            }

            // Player is free floating, we move the player only.
            if (target is IMyCubeGrid)
            {
                var grid = (Sandbox.Game.Entities.MyCubeGrid)target;

                // Station or Large ship grids.
                if (((IMyCubeGrid)target).GridSizeEnum != MyCubeSize.Small)
                {
                    IMyControllableEntity targetCockpit = null;

                    if (grid.HasMainCockpit())
                    {
                        // Select the main cockpit.
                        targetCockpit = (IMyControllableEntity)grid.MainCockpit;
                    }
                    else
                    {
                        var cockpits = target.FindWorkingCockpits();
                        var operationalCockpit = cockpits.FirstOrDefault(c => ((Sandbox.ModAPI.Ingame.IMyCockpit)c).IsShipControlEnabled());

                        if (operationalCockpit != null)
                            // find a cockpit which is not a passenger seat.
                            targetCockpit = operationalCockpit;
                        else if (cockpits.Length > 0)
                            targetCockpit = cockpits[0];
                    }

                    if (targetCockpit != null)
                        return MovePlayerToCube(sourcePlayer, (IMyCubeBlock)targetCockpit, safely, updatedPosition, noSafeLocationMessage);
                }

                // Small ship grids. Also the fallback if a large ship does not have a cockpit.
                return MovePlayerToShipGrid(sourcePlayer, (IMyCubeGrid)target, safely, updatedPosition, noSafeLocationMessage);
            }

            if (target is IMyVoxelBase)
            {
                return MovePlayerToVoxel(sourcePlayer, (IMyVoxelBase)target, safely, updatedPosition, emptySourceMessage, emptyTargetMessage, noSafeLocationMessage);
            }

            return false;
        }
开发者ID:Intueor,项目名称:Space-Engineers-Admin-script-mod,代码行数:76,代码来源:Support.cs

示例2: MovePlayerPilotToShip

        private void MovePlayerPilotToShip(IMyPlayer sourcePlayer, IMyEntity targetedShip)
        {
            if (sourcePlayer == null)
            {
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Source Player no longer exists.");
                return;
            }

            if (targetedShip == null)
            {
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Targeted Ship not found.");
                return;
            }

            if (targetedShip.Closed)
            {
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Targeted Ship no longer exists.");
                return;
            }

            bool success;

            if (sourcePlayer.Controller.ControlledEntity is IMyCubeBlock)
            {
                // TODO: complete code.
                success = Support.MoveShipToShip(sourcePlayer.Controller.ControlledEntity.Entity.GetTopMostParent(), targetedShip);
            }
            else
            {
                // Move the player only.
                var cockpits = targetedShip.FindWorkingCockpits();
                if (cockpits.Length > 0 && ((IMyCubeGrid)targetedShip).GridSizeEnum != Sandbox.Common.ObjectBuilders.MyCubeSize.Small)
                {
                    success = Support.MovePlayerToCockpit(sourcePlayer, (IMyEntity)cockpits[0]);
                }
                else
                {
                    success = Support.MovePlayerToShipGrid(sourcePlayer, targetedShip);
                }
            }

            if (!success)
                MyAPIGateway.Utilities.ShowMessage("Teleport failed", "Could not find a safe location to teleport to.");
        }
开发者ID:zrisher,项目名称:Space-Engineers-Admin-script-mod,代码行数:44,代码来源:CommandTeleport.cs


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