Exemplo n.º 1
0
 public PartsInformation()
 {
     ID = 0;
     Place = 0;
     PartsName = "";
     PartsDiscription = "";
     PrefabName = "";
 }
Exemplo n.º 2
0
        private void ListUpParts(PartsPlace selectedPlace)
        {
            foreach (RectTransform item in PartsButtonsPanel.GetComponentInChildren<RectTransform>())
            {
                Destroy(item.gameObject);
            }
            ListedParts = new List<string>();
            PartsList = new List<PartsInformation> ();
            PartsButtonList = new List<RectTransform>();

            foreach(var item in GameStatus.PlayerSettings.PartsSettingList)
            {
                PartsInformation info = PlayerParts.GetInformation(item.ID);
                var pp = info.Place;
                if(pp == selectedPlace)
                {
                    PartsList.Add(info);
                }
            }
            PartsList.Sort((a, b) => a.ID - b.ID);

            GameObject buttonPrefab = Resources.Load<GameObject>("Prefabs/UIPrefabs/PartsButton");

            float buttonHeight = PartsButtonsPanel.rect.height / 10.0f;

            for (var i = 0; i < PartsList.Count; i++)
            {
                var item = PartsList[i];
                GameObject g = Instantiate(buttonPrefab) as GameObject;
                g.transform.SetParent(PartsButtonsPanel);
                int j = i;
                Button b = g.GetComponent<Button>();
                b.onClick.AddListener(delegate() { this.SelectedPartsChanged(j); });
                g.transform.FindChild("Text").GetComponent<Text>().text = item.PartsName;
                RectTransform brt = g.GetComponent<RectTransform>();
                if (ListedParts.Count < 10)
                {
                    brt.sizeDelta = new Vector2(0, 0);
                    brt.localPosition = new Vector3(0, buttonHeight * 10, 0);
                    brt.anchorMin = new Vector2(0, -(i + 1) / 10.0f + 1);
                    brt.anchorMax = new Vector2(1, -(i + 0) / 10.0f + 1);
                }
                else
                {
                    brt.sizeDelta = new Vector2(0, buttonHeight - 3);
                    brt.localPosition = new Vector3(0, -buttonHeight * (i - ListedParts.Count + 1), 0);
                }
                PartsButtonList.Add(brt);
            }
            Debug.Log("SelectedPlace : " + SelectedPlace + ", range : " + PartsList.Count);
            if (GameStatus.EquipedPartsList[(int)SelectedPlace] == PartsID.None) GameStatus.EquipedPartsList[(int)SelectedPlace] = PartsList[0].ID;
            for(var i = 0;i < PartsButtonList.Count;i++)
            {
                var item = PartsButtonList[i];
                if((GameStatus.EquipedPartsList[(int)SelectedPlace] == PartsList[i].ID))
                {
                    item.GetComponent<Image>().color = new Color(0, 255, 0);
                }
            }
        }