Beispiel #1
0
        private void RaiseControlledEntityChanged(IMyControllableEntity old, IMyControllableEntity entity)
        {
            var handler = ControlledEntityChanged;

            if (handler != null)
            {
                handler(old, entity);
            }
        }
Beispiel #2
0
        public void TakeControl(IMyControllableEntity entity)
        {
            if (ControlledEntity == entity)
            {
                return;
            }

            if (entity != null && entity.ControllerInfo.Controller != null)
            {
                Debug.Fail("Entity controlled by another controller, release it first");
                return;
            }

            var old = ControlledEntity;

            if (old != null)
            {
                var entityCameraSettings = old.GetCameraEntitySettings();

                float headLocalXAngle = old.HeadLocalXAngle;
                float headLocalYAngle = old.HeadLocalYAngle;

                old.Entity.OnClosing         -= m_controlledEntityClosing;
                old.ControllerInfo.Controller = null; // This will call OnControlReleased
                ControlledEntity = null;

                bool firstPerson = entityCameraSettings != null? entityCameraSettings.IsFirstPerson : (MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator);

                if (!MySandboxGame.IsDedicated)
                {
                    MySession.Static.Cameras.SaveEntityCameraSettings(
                        Player.Id,
                        old.Entity.EntityId,
                        firstPerson,
                        MyThirdPersonSpectator.Static.GetViewerDistance(),
                        headLocalXAngle,
                        headLocalYAngle);
                }
            }
            if (entity != null)
            {
                ControlledEntity = entity;
                ControlledEntity.Entity.OnClosing         += m_controlledEntityClosing;
                ControlledEntity.ControllerInfo.Controller = this; // This will call OnControlAcquired

                if (!MySandboxGame.IsDedicated && ControlledEntity.Entity is IMyCameraController)
                {
                    MySession.Static.SetEntityCameraPosition(Player.Id, ControlledEntity.Entity);
                }
            }

            if (old != entity)
            {
                RaiseControlledEntityChanged(old, entity);
            }
        }
        public void TakeControl(IMyControllableEntity entity)
        {
            if (ControlledEntity == entity)
                return;

            if (entity != null && entity.ControllerInfo.Controller != null)
            {
                Debug.Fail("Entity controlled by another controller, release it first");
                return;
            }

            var old = ControlledEntity;

            if (old != null)
            {
                var entityCameraSettings = old.GetCameraEntitySettings();

                float headLocalXAngle = old.HeadLocalXAngle;
                float headLocalYAngle = old.HeadLocalYAngle;

                old.Entity.OnClosing -= m_controlledEntityClosing;
                old.ControllerInfo.Controller = null; // This will call OnControlReleased
                ControlledEntity = null;

                bool firstPerson = entityCameraSettings != null? entityCameraSettings.IsFirstPerson : (MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator);

                if (!MySandboxGame.IsDedicated)
                {
                    MySession.Static.Cameras.SaveEntityCameraSettings(
                        Player.Id,
                        old.Entity.EntityId,
                        firstPerson,
                        MyThirdPersonSpectator.Static.GetViewerDistance(),
                        headLocalXAngle,
                        headLocalYAngle);
                }

            }
            if (entity != null)
            {
                ControlledEntity = entity;
                ControlledEntity.Entity.OnClosing += m_controlledEntityClosing;
                ControlledEntity.ControllerInfo.Controller = this; // This will call OnControlAcquired

                if (!MySandboxGame.IsDedicated && ControlledEntity.Entity is IMyCameraController)
                {
                    MySession.Static.SetEntityCameraPosition(Player.Id, ControlledEntity.Entity);
                }
            }

            if (old != entity)
                RaiseControlledEntityChanged(old, entity);
        }
 private void RaiseControlledEntityChanged(IMyControllableEntity old, IMyControllableEntity entity)
 {
     var handler = ControlledEntityChanged;
     if (handler != null) handler(old, entity);
 }
Beispiel #5
0
 UseActionResult IMyUsableEntity.CanUse(UseActionEnum actionEnum, Sandbox.Game.Entities.IMyControllableEntity user) =>
 (base.MarkedForClose ? UseActionResult.Closed : UseActionResult.OK);