public void OnClickGridElement(GridElement sender) { Log.Debug("Clicked grid element (valve: {0}, row={1}, pos={2})", sender.isValve, sender.vertexRow, sender.vertexPos); if (Ets.Room == null) { return; } if (game.State != GameState.Running) { return; } if (!sender.isValve) { return; } EtsMockupInterface mockup = Ets.Room.Physical as EtsMockupInterface; if (mockup != null) { mockup.ToggleValve(sender.vertexRow, sender.vertexPos); } }
public void OnGameStateChanged(Game <IEtsInterface> sender, GameStateChangedEventArgs e) { if (e.NewState == GameState.Initialized) { foreach (Image img in gridElementImages.Values) { Destroy(img.gameObject); } gridElementImages.Clear(); foreach (Fan fan in game.Fans()) { GameObject go = Instantiate(gridElementPrefab, pnlGrid); go.name = string.Format("Fan (row={0}, pos={1}, px={2})", fan.Row, fan.PositionInRow, fan.PxCoords); go.layer = LayerMask.NameToLayer("UI"); GridElement gridElement = go.GetComponent <GridElement>(); gridElement.vertexRow = fan.Row; gridElement.vertexPos = fan.PositionInRow; gridElement.isValve = false; Image img = go.GetComponent <Image>(); img.sprite = fanSprite; img.color = fan.IsRunning ? activeFan : inactiveFan; RectTransform rect = go.GetComponent <RectTransform>(); rect.sizeDelta = img.sprite.rect.size; rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(0, 1); Vector2 offset = new Vector2(-img.sprite.rect.size.x / 2, img.sprite.rect.size.y / 2); rect.anchoredPosition = fan.PxCoords + offset; gridElementImages[fan.PxCoords] = img; } foreach (Valve valve in game.Valves()) { GameObject go = Instantiate(gridElementPrefab, pnlGrid); go.name = string.Format("Valve (row={0}, pos={1}, px={2})", valve.Row, valve.PositionInRow, valve.PxCoords); go.layer = LayerMask.NameToLayer("UI"); GridElement gridElement = go.GetComponent <GridElement>(); gridElement.vertexRow = valve.Row; gridElement.vertexPos = valve.PositionInRow; gridElement.isValve = true; Image img = go.GetComponent <Image>(); img.sprite = valveSprite; img.color = valve.IsOpen ? openValve : closedValve; RectTransform rect = go.GetComponent <RectTransform>(); rect.sizeDelta = img.sprite.rect.size; rect.anchorMin = rect.anchorMax = rect.pivot = new Vector2(0, 1); Vector2 offset = new Vector2(-img.sprite.rect.size.x / 2, img.sprite.rect.size.y / 2); rect.anchoredPosition = valve.PxCoords + offset; gridElementImages[valve.PxCoords] = img; } lblFanCount.text = string.Format(fanCountStrF, game.RunningFansCount, game.FanCount); } }