/// <summary> /// Detaches the client from an entity. /// </summary> public void DetachEntity() { var previous = ControlledEntity; if (ControlledEntity != null && ControlledEntity.Initialized) { ControlledEntity.GetComponent <EyeComponent>().Current = false; var transform = ControlledEntity.Transform; if (transform != null) { transform.OnMove -= OnPlayerMoved; } ControlledEntity.SendMessage(null, new PlayerDetachedMsg()); // notify ECS Systems ControlledEntity.EntityManager.RaiseEvent(this, new PlayerAttachSysMessage(null)); } ControlledEntity = null; if (previous != null) { EntityDetached?.Invoke(new EntityDetachedEventArgs(previous)); } }
/// <summary> /// Detaches the client from an entity. /// </summary> public void DetachEntity() { var previous = ControlledEntity; if (previous != null && previous.Initialized && !previous.Deleted) { previous.GetComponent <EyeComponent>().Current = false; previous.SendMessage(null, new PlayerDetachedMsg()); // notify ECS Systems previous.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PlayerAttachSysMessage(null)); } ControlledEntity = null; if (previous != null) { EntityDetached?.Invoke(new EntityDetachedEventArgs(previous)); } }
/// <summary> /// Detaches the client from an entity. /// </summary> public void DetachEntity() { if (ControlledEntity != null && ControlledEntity.Initialized) { ControlledEntity.RemoveComponent <PlayerInputMoverComponent>(); ControlledEntity.GetComponent <EyeComponent>().Current = false; var transform = ControlledEntity.Transform; if (transform != null) { transform.OnMove -= OnPlayerMoved; } ControlledEntity.SendMessage(null, new PlayerDetachedMsg()); // notify ECS Systems ControlledEntity.EntityManager.RaiseEvent(this, new PlayerAttachSysMessage(null)); } ControlledEntity = null; EntityDetached?.Invoke(this, EventArgs.Empty); }