示例#1
0
        // Update is called once per frame
        void Update()
        {
            // Timer
            if (GameType != GameType.Singleplayer && (State == GameState.PreparationPhase || State == GameState.Election))
            {
                UI.SidePanelFooter.UpdateButton();

                if (!LocalPlayerParty.IsReady)
                {
                    RemainingTime -= Time.deltaTime;
                    if (RemainingTime <= 0)
                    {
                        RemainingTime = 0f;
                        EndTurn();
                    }
                }
            }

            switch (State)
            {
            case GameState.PreparationPhase:
                // Mouse click
                if (Input.GetMouseButtonDown(0))
                {
                    bool uiClick = EventSystem.current.IsPointerOverGameObject();

                    if (!uiClick)
                    {
                        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                        RaycastHit hit;
                        if (Physics.Raycast(ray, out hit, 100))
                        {
                            Region mouseRegion = hit.transform.gameObject.GetComponent <Region>();
                            if (VisibleDistricts.ContainsKey(mouseRegion))
                            {
                                UI.SelectDistrict(VisibleDistricts[mouseRegion]);
                            }
                            else
                            {
                                UI.SelectDistrict(null);
                            }
                        }
                    }
                }
                break;

            case GameState.Election:
                ElectionAnimationHandler.Update();
                break;
            }
        }
        public void Init(UI_ElectionTactics UI, District d)
        {
            District       = d;
            NameText.text  = d.Name;
            SeatsText.text = d.Seats.ToString();
            if (d.CurrentWinnerParty != null)
            {
                PartyIcon.gameObject.SetActive(true);
                PartyIcon.color = d.CurrentWinnerParty.Color;
                float margin = d.GetLatestElectionResult().GetMargin(UI.Game.LocalPlayerParty);
                MarginText.text = (margin > 0 ? "+" : "") + margin.ToString("0.0") + " %";
            }
            else
            {
                PartyIcon.gameObject.SetActive(false);
                MarginText.text = "";
            }

            GetComponent <Button>().onClick.AddListener(() => { d.Region.SetAnimatedHighlight(false); UI.SelectDistrict(d); });
        }