/// <summary> /// Lets you register a command to be called when the game is directly sent a message. /// /// The callback you register must have a CmdName attribute. That attibute will determine /// which event the callback gets dispatched for. /// </summary> /// <example> /// <code> /// <![CDATA[ /// [CmdName("color")] /// private class MessageColor : MessageCmdData { /// public string color = ""; // in CSS format rgb(r,g,b) /// }; /// /// ... /// gameServer.RegisterCmdHandler<MessageColor>(OnColor); /// ... /// void OnColor(MessageColor) { /// Debug.Log("received msg with color: " + color); /// } /// ]]> /// </code> /// </example> /// <param name="callback">Typed callback</param> public void RegisterCmdHandler <T>(TypedCmdEventHandler <T> callback) where T : MessageCmdData { string name = HFTMessageCmdDataNameDB.GetCmdName(typeof(T)); if (name == null) { throw new System.InvalidOperationException("no CmdNameAttribute on " + typeof(T).Name); } RegisterCmdHandler <T>(name, callback); }
// Only NetPlayer should call this. public void SendCmd(string cmd, MessageCmdData data, string id = "-1") { string name = HFTMessageCmdDataNameDB.GetCmdName(data.GetType()); SendCmd(cmd, name, data, id); }
public void SendEvent(MessageCmdData data) { string cmd = HFTMessageCmdDataNameDB.GetCmdName(data.GetType()); SendEvent(cmd, data); }
/// <summary> /// Unregisters the command handler for a given MessageCmdData. Gets the Command name from the MessgeCmdData's /// CmdData attribute. /// </summary> /// <returns>true if there was a command handler, false if not</returns> public bool UnregisterCmdHandler <T>() where T : MessageCmdData { string name = HFTMessageCmdDataNameDB.GetCmdName(typeof(T)); return(UnregisterCmdHandler(name)); }
/// <summary> /// Sends a message to this player's phone /// </summary> /// <param name="data">The message. It must be derived from MessageCmdData and must have a /// CmdName attribute</param> /// <example> /// <code> /// </code> /// </example> public override void SendCmd(MessageCmdData data) { string cmd = HFTMessageCmdDataNameDB.GetCmdName(data.GetType()); SendCmd(cmd, data); }