コード例 #1
0
ファイル: PopularSquads.cs プロジェクト: vitreuz/FlyCasual
        public static void ShowListOfArchetypesVariants()
        {
            GameObject prefab          = (GameObject)Resources.Load("Prefabs/SquadBuilder/SavedSquadronPanel", typeof(GameObject));
            GameObject archetypesPanel = GameObject.Find("UI/Panels").transform.Find("BrowsePopularSquadsVariantsPanel").Find("Scroll View/Viewport/Content").gameObject;

            RectTransform contentTransform = archetypesPanel.GetComponent <RectTransform>();

            foreach (Transform transform in contentTransform.transform)
            {
                GameObject.Destroy(transform.gameObject);
            }

            List <string> existingLists = new List <string>();

            foreach (var squadJson in VariantsData.list)
            {
                SquadList squadList = new SquadList(Players.PlayerNo.PlayerNone);

                JSONObject squadJsonFixed = new JSONObject(squadJson["json"].str);
                if (existingLists.Contains(squadJsonFixed.ToString()))
                {
                    continue;
                }
                existingLists.Add(squadJsonFixed.ToString());

                SquadBuilder.SetPlayerSquadFromImportedJson(squadJsonFixed, squadList, delegate { });

                GameObject SquadListRecord;

                SquadListRecord = MonoBehaviour.Instantiate(prefab, contentTransform);

                SquadListRecord.transform.Find("Name").GetComponent <Text>().text = "Example"; //squadList["name"].str;

                Text          descriptionText          = SquadListRecord.transform.Find("Description").GetComponent <Text>();
                RectTransform descriptionRectTransform = SquadListRecord.transform.Find("Description").GetComponent <RectTransform>();
                if (squadJson.HasField("json"))
                {
                    descriptionText.text = SquadBuilder.GetDescriptionOfSquadJson(squadJsonFixed).Replace("\\\"", "\"");
                }
                else
                {
                    descriptionText.text = "No description";
                }

                float descriptionPreferredHeight = descriptionText.preferredHeight;
                descriptionRectTransform.sizeDelta = new Vector2(descriptionRectTransform.sizeDelta.x, descriptionPreferredHeight);

                SquadListRecord.transform.Find("PointsValue").GetComponent <Text>().text = squadList.Points.ToString();

                SquadListRecord.GetComponent <RectTransform>().sizeDelta = new Vector2(
                    SquadListRecord.GetComponent <RectTransform>().sizeDelta.x,
                    15 + 70 + 10 + descriptionPreferredHeight + 10 + 55 + 10
                    );

                SquadListRecord.transform.Find("DeleteButton").gameObject.SetActive(false);
                SquadListRecord.transform.Find("LoadButton").GetComponent <Button>().onClick.AddListener(delegate { SquadBuilder.LoadSavedSquadAndReturn(squadJsonFixed); });
            }

            OrganizePanels(contentTransform, FREE_SPACE);
        }
コード例 #2
0
        public void ShowListOfSavedSquadrons(List <JSONObject> squadsJsonsList)
        {
            SetNoSavedSquadronsMessage(squadsJsonsList.Count == 0);

            float FREE_SPACE = 25;

            Transform contentTransform = GameObject.Find("UI/Panels/BrowseSavedSquadsPanel/Scroll View/Viewport/Content").transform;

            SquadBuilderView.DestroyChildren(contentTransform);

            GameObject prefab = (GameObject)Resources.Load("Prefabs/SquadBuilder/SavedSquadronPanel", typeof(GameObject));

            //RectTransform contentRectTransform = contentTransform.GetComponent<RectTransform>();
            //Vector3 currentPosition = new Vector3(0, -FREE_SPACE, contentTransform.localPosition.z);

            foreach (var squadList in squadsJsonsList)
            {
                GameObject SquadListRecord;

                SquadListRecord = MonoBehaviour.Instantiate(prefab, contentTransform);

                SquadListRecord.transform.Find("Name").GetComponent <Text>().text = squadList["name"].str;

                Text          descriptionText          = SquadListRecord.transform.Find("Description").GetComponent <Text>();
                RectTransform descriptionRectTransform = SquadListRecord.transform.Find("Description").GetComponent <RectTransform>();
                if (squadList.HasField("description"))
                {
                    descriptionText.text = squadList["description"].str.Replace("\\\"", "\"");
                }
                else
                {
                    descriptionText.text = "No description";
                }

                float descriptionPreferredHeight = descriptionText.preferredHeight;
                descriptionRectTransform.sizeDelta = new Vector2(descriptionRectTransform.sizeDelta.x, descriptionPreferredHeight);

                SquadListRecord.transform.Find("PointsValue").GetComponent <Text>().text = squadList["points"].i.ToString();

                SquadListRecord.GetComponent <RectTransform>().sizeDelta = new Vector2(
                    SquadListRecord.GetComponent <RectTransform>().sizeDelta.x,
                    15 + 70 + 10 + descriptionPreferredHeight + 10 + 55 + 10
                    );

                SquadListRecord.name = squadList["filename"].str;

                SquadListRecord.transform.Find("DeleteButton").GetComponent <Button>().onClick.AddListener(delegate { DeleteSavedSquadAndRefresh(SquadListRecord.name); });
                SquadListRecord.transform.Find("LoadButton").GetComponent <Button>().onClick.AddListener(delegate { LoadSavedSquadAndReturn(GetSavedSquadJson(SquadListRecord.name)); });
            }

            SquadBuilderView.OrganizePanels(contentTransform, FREE_SPACE);
        }