示例#1
0
        public override void UbmUpdate(float deltaTime)
        {
            // valve rotation sound for Pipes
            if (pipes.State == GameState.Running)
            {
                bool playTurningSound = false;
                foreach (Valve valve in pipes.Valves())
                {
                    PipeSystem pipeSystem = valve.PipeSystem;
                    if (pipeSystem.RunningFansCount >= pipeSystem.FanCount)
                    {
                        continue;
                    }
                    if (Ets.Room.Physical.IsValveRotating(valve.Row, valve.PositionInRow))
                    {
                        playTurningSound = true;
                        break;
                    }
                }

                bool playing = audio.IsSoundPlaying(11);
                if (playTurningSound && !playing)
                {
                    audio.PlaySound(11, true, TurningValveVolume);
                    //print ("activate valve turning sound");
                }
                else if (!playTurningSound && playing)
                {
                    audio.StopSound(11);
                    //print ("deactivate valve turning sound");
                }
            }
        }
示例#2
0
        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);
            }
        }