コード例 #1
0
        public async Task SetTileMapState(JsonTileMapState jsonTileMapState)
        {
            await ConnectToContract();

            string tileMapState = JsonUtility.ToJson(jsonTileMapState);

            await this.contract.CallAsync("SetTileMapState", tileMapState);
        }
コード例 #2
0
        public async Task <JsonTileMapState> GetTileMapState()
        {
            await ConnectToContract();

            TileMapStateOutput result = await this.contract.StaticCallDTOTypeOutputAsync <TileMapStateOutput>("GetTileMapState");

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

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

            return(jsonTileMapState);
        }
コード例 #3
0
        private void EventReceivedHandler(object sender, EvmChainEventArgs e)
        {
            if (e.EventName != "OnTileMapStateUpdate")
            {
                return;
            }

            OnTileMapStateUpdateEvent onTileMapStateUpdateEvent = e.DecodeEventDTO <OnTileMapStateUpdateEvent>();
            JsonTileMapState          jsonTileMapState          = JsonUtility.FromJson <JsonTileMapState>(onTileMapStateUpdateEvent.State);

            this.eventActions.Enqueue(() =>
            {
                TileMapStateUpdated?.Invoke(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);
 }