public object Convert(int operation, string packet) { object _packet = null; CharacterOperation key = (CharacterOperation)operation; JsonReaderSettings settings = new JsonReaderSettings(); settings.AddTypeConverter(new VectorConverter()); settings.AddTypeConverter(new QuaternionConverter()); JsonReader jsonReader = new JsonReader(packet, settings); switch (key) { case CharacterOperation.GROUNDCLICK: _packet = jsonReader.Deserialize <GroundClick>(); break; case CharacterOperation.INSTANTIATE: _packet = jsonReader.Deserialize <InstantiateChar>(); break; case CharacterOperation.DESTROY: _packet = jsonReader.Deserialize <DestroyChar>(); break; default: break; } return(_packet); }
/// <summary> /// Execute the given operation in the js env /// </summary> /// <param name="operation"></param> public void PerformOperation(CharacterOperation operation) { if (JsOnOperation != null) { JsOnOperation(operation); } }
private void HandlePlatformMessage(PlatformMessage message) { //Convert the PlatformMessage to specific message or handle it directly if (message.Content.ContainsKey(PlatformMessage.TYPE)) { string type = message.Content[PlatformMessage.TYPE] as string; if (type == PlatformMessage.TYPE_OPERATION) { //Got an operation string operation = (string)message.GetContent(PlatformMessage.CONTENT_OPERATION); try { CharacterOperation co = CharacterOperation.Deserialize(operation); OperationMessage opMessage = new OperationMessage(co); GameManager.SafeQueueMessage(opMessage); } catch (Exception ex) { Debug.Log(ex.Message); } return; } } }
public void handlePacket(int operation, string packet) { CharacterOperation key = (CharacterOperation)operation; if (callbacks.ContainsKey(key)) { Action <object> callback = callbacks[key]; object _packet = this.Convert(operation, packet); callback.Invoke(_packet); } }
public void registerCallback(int operation, Action <object> callback) { CharacterOperation characterOperation = (CharacterOperation)operation; if (callbacks.ContainsKey(characterOperation)) { callbacks[characterOperation] = callback; } else { callbacks.Add(characterOperation, callback); } }
public void registerCallback(CharacterOperation operation, Action <object> callback) { this.registerCallback((int)operation, callback); }
public OperationMessage(CharacterOperation operation) { this.Operation = operation; }
public void registerCallback(CharacterOperation operation, Action<object> callback) { this.registerCallback((int)operation, callback); }