/// <summary> /// Message handler for all incoming messages. /// </summary> /// <param name="message">Incoming message</param> /// <remarks>If a message is sent to the interface and not handled by /// the interface then it will be forwarded to the current render camera for /// handling.</remarks> /// <exception cref="ArgumentException">Thrown if a <see cref="MessageType"/> is not handled properly."/></exception> public override bool ExecuteMessage(IMessage message) { switch (message.Type) { case MessageType.CameraSetRender: { MsgSetRenderEntity camMsg = message as MsgSetRenderEntity; message.TypeCheck(camMsg); SetRenderCamera(camMsg.Entity); } return(true); case MessageType.CameraGetRenderEntityID: { MsgGetRenderEntity camMsg = message as MsgGetRenderEntity; message.TypeCheck(camMsg); if (null != renderCamera) { camMsg.EntityID = renderCamera.UniqueID; } } return(true); case MessageType.GraphicsSettingsChanged: { // If we have a render camera, let them know about the change to graphics settings. if (null != renderCamera) { MsgGraphicsSettingsChanged msgChange = ObjectPool.Aquire <MsgGraphicsSettingsChanged>(); msgChange.UniqueTarget = renderCamera.UniqueID; this.game.SendMessage(msgChange); } } return(true); case MessageType.GetLineSegmentToCursor: { MsgGetLineSegmentToCursor msgGetRay = message as MsgGetLineSegmentToCursor; message.TypeCheck(msgGetRay); if (null != renderCamera) { LineSegment segment; CalculateCursorLineSegment(out segment); msgGetRay.lineSegment = segment; } } return(true); default: return(false); } }
/// <summary> /// Sent to a component when its parent entity is added to a scene /// </summary> /// <param name="manager">The <see cref="SceneManager"/> that added the entity to the scene.</param> public override void AddedToScene(SceneManager manager) { // First we need to get the current rendering camera. MsgGetRenderEntity camMsg = ObjectPool.Aquire <MsgGetRenderEntity>(); this.parentEntity.Game.SendInterfaceMessage(camMsg, InterfaceType.Camera); // If the ID we received is not empty, then we're good to go if (camMsg.EntityID != QSGame.UniqueIDEmpty) { MsgAttachSkyToCamera attachCamMsg = ObjectPool.Aquire <MsgAttachSkyToCamera>(); attachCamMsg.CameraEntityID = camMsg.EntityID; attachCamMsg.UniqueTarget = this.parentEntity.UniqueID; this.parentEntity.Game.SendMessage(attachCamMsg); } }