Exemplo n.º 1
0
        public void OpenLaws()
        {
            if (aiPlayer == null)
            {
                aiPlayer = PlayerManager.LocalPlayer.OrNull()?.GetComponent <AiPlayer>();
            }

            if (aiPlayer == null)
            {
                Logger.LogError("Failed to find AiPlayer for player");
                return;
            }

            aiLawsTab.SetActive(true);
            aiLawsTabDummyLaw.SetActive(false);

            //Clear old laws
            foreach (Transform child in aiLawsTabContents)
            {
                //Dont destroy dummy
                if (child.gameObject.activeSelf == false)
                {
                    continue;
                }

                GameObject.Destroy(child.gameObject);
            }

            // 0 laws first, freeform last
            var laws = aiPlayer.GetLaws();

            amountOfLawsText.text = $"You have <color=orange>{laws.Count}</color> law{(laws.Count == 1 ? "" : "s")}\nYou Must Follow Them";

            foreach (var law in laws)
            {
                var newChild = Instantiate(aiLawsTabDummyLaw, aiLawsTabContents);
                newChild.GetComponent <TMP_Text>().text = law;
                newChild.SetActive(true);
            }
        }