public async Task SetTileMapState(JsonTileMapState jsonTileMapState) { await ConnectToContract(); string tileMapState = JsonUtility.ToJson(jsonTileMapState); await this.contract.CallAsync("SetTileMapState", tileMapState); }
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); }
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); }); }
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); } }
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); } }
private void ClientOnTileMapStateUpdated(JsonTileMapState obj) { UpdateTileMap(obj); }