Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 /// <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;
                }
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        public void registerCallback(int operation, Action <object> callback)
        {
            CharacterOperation characterOperation = (CharacterOperation)operation;

            if (callbacks.ContainsKey(characterOperation))
            {
                callbacks[characterOperation] = callback;
            }
            else
            {
                callbacks.Add(characterOperation, callback);
            }
        }
Esempio n. 6
0
 public void registerCallback(CharacterOperation operation, Action <object> callback)
 {
     this.registerCallback((int)operation, callback);
 }
Esempio n. 7
0
 public OperationMessage(CharacterOperation operation)
 {
     this.Operation = operation;
 }
Esempio n. 8
0
 public void registerCallback(CharacterOperation operation, Action<object> callback)
 {
     this.registerCallback((int)operation, callback);
 }