/// <summary>
        ///     Attaches a client to an entity.
        /// </summary>
        /// <param name="entity">Entity to attach the client to.</param>
        public void AttachEntity(IEntity entity)
        {
            // Detach and cleanup first
            DetachEntity();

            ControlledEntity = entity;

            if (ControlledEntity.HasComponent <IMoverComponent>())
            {
                ControlledEntity.RemoveComponent <IMoverComponent>();
            }

            ControlledEntity.AddComponent <PlayerInputMoverComponent>();

            if (!ControlledEntity.TryGetComponent <EyeComponent>(out var eye))
            {
                eye = ControlledEntity.AddComponent <EyeComponent>();
            }
            eye.Current = true;

            var transform = ControlledEntity.GetComponent <IGodotTransformComponent>();

            transform.OnMove += OnPlayerMoved;

            EntityAttached?.Invoke(this, EventArgs.Empty);
            entity.SendMessage(null, new PlayerAttachedMsg());

            // notify ECS Systems
            ControlledEntity.EntityManager.RaiseEvent(this, new PlayerAttachSysMessage(ControlledEntity));
        }
Exemple #2
0
        /// <summary>
        ///     Attaches a client to an entity.
        /// </summary>
        /// <param name="entity">Entity to attach the client to.</param>
        public void AttachEntity(IEntity entity)
        {
            // Detach and cleanup first
            DetachEntity();

            ControlledEntity = entity;

            if (!ControlledEntity.TryGetComponent <EyeComponent>(out var eye))
            {
                eye = ControlledEntity.AddComponent <EyeComponent>();
            }
            eye.Current = true;

            EntityAttached?.Invoke(new EntityAttachedEventArgs(entity));
            entity.SendMessage(null, new PlayerAttachedMsg());

            // notify ECS Systems
            ControlledEntity.EntityManager.EventBus.RaiseEvent(this, new PlayerAttachSysMessage(ControlledEntity));
        }
Exemple #3
0
        /// <summary>
        ///     Attaches a client to an entity.
        /// </summary>
        /// <param name="entity">Entity to attach the client to.</param>
        public void AttachEntity(IEntity entity)
        {
            // Detach and cleanup first
            DetachEntity();

            ControlledEntity = entity;
            InternalSession.AttachedEntity = entity;

            if (!ControlledEntity.TryGetComponent <EyeComponent>(out var eye))
            {
                eye = ControlledEntity.AddComponent <EyeComponent>();
            }
            eye.Current = true;

            EntityAttached?.Invoke(new EntityAttachedEventArgs(entity));

            // notify ECS Systems
            ControlledEntity.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PlayerAttachSysMessage(ControlledEntity));
            ControlledEntity.EntityManager.EventBus.RaiseLocalEvent(ControlledEntity.Uid, new PlayerAttachedEvent(ControlledEntity));
        }
        /// <summary>
        ///     Attaches a client to an entity.
        /// </summary>
        /// <param name="entity">Entity to attach the client to.</param>
        public void AttachEntity(EntityUid entity)
        {
            // Detach and cleanup first
            DetachEntity();

            ControlledEntity = entity;
            InternalSession.AttachedEntity = entity;

            var entMan = IoCManager.Resolve <IEntityManager>();

            if (!entMan.TryGetComponent <EyeComponent?>(entity, out var eye))
            {
                eye = entMan.AddComponent <EyeComponent>(entity);
            }
            eye.Current = true;

            EntityAttached?.Invoke(new EntityAttachedEventArgs(entity));

            // notify ECS Systems
            var eventBus = entMan.EventBus;

            eventBus.RaiseEvent(EventSource.Local, new PlayerAttachSysMessage(entity));
            eventBus.RaiseLocalEvent(entity, new PlayerAttachedEvent(entity));
        }