Ejemplo n.º 1
0
    public static Vec2 Deserialize(byte[] bytes)
    {
        var playObj = CodecUtils.DeserializePlayObject(bytes);

        return(new Vec2 {
            X = playObj.GetFloat("x"),
            Y = playObj.GetFloat("y")
        });
    }
Ejemplo n.º 2
0
    public static Move Deserialize(byte[] bytes)
    {
        var playObj = CodecUtils.DeserializePlayObject(bytes);

        return(new Move {
            Pos = playObj.Get <Vec2>("p"),
            Dir = playObj.Get <Vec2>("d"),
            Time = playObj.GetLong("t")
        });
    }
Ejemplo n.º 3
0
    public static byte[] Serialize(object obj)
    {
        var vec     = obj as Vec2;
        var playObj = new PlayObject {
            { "x", vec.X },
            { "y", vec.Y }
        };

        return(CodecUtils.SerializePlayObject(playObj));
    }
Ejemplo n.º 4
0
    public static byte[] Serialize(object obj)
    {
        var move    = obj as Move;
        var playObj = new PlayObject {
            { "p", move.Pos },
            { "d", move.Dir },
            { "t", move.Time }
        };

        return(CodecUtils.SerializePlayObject(playObj));
    }
Ejemplo n.º 5
0
    public static Food Deserialize(byte[] bytes)
    {
        var playObj = CodecUtils.DeserializePlayObject(bytes);
        var food    = new Food {
            Id   = playObj.GetInt("id"),
            Type = playObj.GetInt("type"),
            X    = playObj.GetFloat("x"),
            Y    = playObj.GetFloat("y")
        };

        return(food);
    }
Ejemplo n.º 6
0
    public static byte[] Serialize(object obj)
    {
        Food food    = obj as Food;
        var  playObj = new PlayObject {
            { "id", food.Id },
            { "type", food.Type },
            { "x", food.X },
            { "y", food.Y }
        };

        return(CodecUtils.SerializePlayObject(playObj));
    }
Ejemplo n.º 7
0
        IPromise <Codec> _loadAsync(FileImage key)
        {
            var coroutine = Window.instance.startCoroutine(this._loadBytes(key));

            return(coroutine.promise.Then(obj => {
                if (obj is byte[] bytes)
                {
                    return CodecUtils.getCodec(bytes);
                }

                return CodecUtils.getCodec(new Image((Texture2D)obj));
            }));
        }
Ejemplo n.º 8
0
 public static Client InitClient(string userId)
 {
     // 注册自定义类型的序列化
     CodecUtils.RegisterType(typeof(Food), 2, Food.Serialize, Food.Deserialize);
     CodecUtils.RegisterType(typeof(Move), 3, Move.Serialize, Move.Deserialize);
     CodecUtils.RegisterType(typeof(Vec2), 4, Vec2.Serialize, Vec2.Deserialize);
     client = new Client("vAGmhiMWKL36JMXdepqx3sgV-gzGzoHsz", "Gt9CnVkM20XGFkAFkEkCKULE", userId);
     //client = new Client("FQr8l8LLvdxIwhMHN77sNluX-9Nh9j0Va", "MJSm46Uu6LjF5eNmqfbuUmt6", userId);
     client.OnPlayerCustomPropertiesChanged += (player, changedProps) => {
         Debug.Log(changedProps);
     };
     return(client);
 }
Ejemplo n.º 9
0
        IPromise <Codec> _loadAsync(AssetBundleImageKey key)
        {
            var coroutine = Window.instance.startCoroutine(this._loadAssetAsync(key));

            return(coroutine.promise.Then(result => {
                if (result == null)
                {
                    if (key.bundle == null)
                    {
                        throw new Exception($"Unable to find asset \"{key.name}\" from Resources folder");
                    }

                    throw new Exception($"Unable to find asset \"{key.name}\" from asset bundle \"{key.bundle}\"");
                }

                if (result is Texture2D texture)
                {
                    return CodecUtils.getCodec(new Image(texture, isAsset: true, bundle: key.bundle));
                }
                else if (result is TextAsset text)
                {
                    var bytes = text.bytes;
                    if (key.bundle == null)
                    {
                        Resources.UnloadAsset(text);
                    }
                    else
                    {
                        key.bundle.Unload(text);
                    }

                    return CodecUtils.getCodec(bytes);
                }
                else
                {
                    throw new Exception($"Unknown type for asset \"{key.name}\": \"{result.GetType()}\"");
                }
            }));
        }
        IPromise <Codec> _loadAsync(CachedNetworkImageProvider key)
        {
            var localPath = SQLiteDBManager.instance.GetCachedFilePath(url: key.url);

            //the cached file might be deleted by the OS
            if (!File.Exists(path: localPath))
            {
                localPath = null;
            }

            var coroutine = localPath != null
                ? Window.instance.startCoroutine(this._loadFromFile(file : localPath))
                            : Window.instance.startCoroutine(this._loadFromNetwork(url : key.url));

            return(coroutine.promise.Then(obj => {
                if (obj is byte[] bytes)
                {
                    return CodecUtils.getCodec(bytes: bytes);
                }

                return CodecUtils.getCodec(new Image((Texture2D)obj));
            }));
        }
Ejemplo n.º 11
0
        IPromise <Codec> _loadAsync(MemoryImage key)
        {
            D.assert(key == this);

            return(CodecUtils.getCodec(this.bytes));
        }