예제 #1
0
        public async Task SetTileMapState(JsonTileMapState jsonTileMapState)
        {
            await ConnectToContract();

            TileMapState tileMapStateTx = new TileMapState();

            tileMapStateTx.Data = JsonUtility.ToJson(jsonTileMapState);
            await this.contract.CallAsync("SetTileMapState", tileMapStateTx);
        }
예제 #2
0
        private void ChainEventReceivedHandler(object sender, ChainEventArgs e)
        {
            if (e.EventName != "onTileMapStateUpdate")
            {
                return;
            }

            string           stringData         = Encoding.UTF8.GetString(e.Data);
            JsonTileMapState tileMapStateParsed = JsonUtility.FromJson <JsonTileMapState>(stringData);

            this.eventActions.Enqueue(() => {
                TileMapStateUpdated?.Invoke(tileMapStateParsed);
            });
        }
예제 #3
0
        public async Task <JsonTileMapState> GetTileMapState()
        {
            await ConnectToContract();

            TileMapState result = await this.contract.StaticCallAsync <TileMapState>("GetTileMapState", new TileMapState());

            if (result == null)
            {
                throw new Exception("Smart contract didn't return anything!");
            }

            JsonTileMapState jsonTileMapState = JsonUtility.FromJson <JsonTileMapState>(result.Data);

            return(jsonTileMapState);
        }
예제 #4
0
        private async Task ConnectClient()
        {
            ReconnectButton.gameObject.SetActive(false);
            StatusText.gameObject.SetActive(true);
            StatusText.text = "Connecting...";
            try
            {
                await this.client.ConnectToContract();

                JsonTileMapState jsonTileMapState = await this.client.GetTileMapState();

                UpdateTileMap(jsonTileMapState);

                StatusText.gameObject.SetActive(false);
            } catch (Exception e)
            {
                StatusText.text = "Error: " + e.Message;
                ReconnectButton.gameObject.SetActive(true);
                Debug.LogException(e);
            }
        }
예제 #5
0
        private void UpdateTileMap(JsonTileMapState jsonTileMapState)
        {
            this.jsonTileMapState = jsonTileMapState ?? new JsonTileMapState();

            foreach (GameObject tile in this.tileGameObjects)
            {
                Destroy(tile);
            }

            this.tileGameObjects.Clear();
            foreach (JsonTileMapState.Tile tile in this.jsonTileMapState.tiles)
            {
                GameObject go = new GameObject("Tile");
                go.transform.localScale = Vector3.one * 16f;
                go.transform.position   = new Vector3(tile.point.x, GameFieldSize.y - tile.point.y, 0);
                SpriteRenderer spriteRenderer = go.AddComponent <SpriteRenderer>();
                spriteRenderer.sprite = PointSprite;
                spriteRenderer.color  = new Color32((byte)tile.color.r, (byte)tile.color.g, (byte)tile.color.b, 255);

                this.tileGameObjects.Add(go);
            }
        }
예제 #6
0
 private void ClientOnTileMapStateUpdated(JsonTileMapState obj)
 {
     UpdateTileMap(obj);
 }