Exemplo n.º 1
0
    void  FillStructureList()
    {
        BuildingScreen buildingScreen = gameStates[1].UIPanel.GetComponent <BuildingScreen>();
        RectTransform  rect           = buildingScreen.listContent.GetComponent <RectTransform>();
        Transform      listTransform  = buildingScreen.listContent.transform;

        for (int i = 0; i < listTransform.childCount; i++)
        {
            GameObject gameObject = listTransform.GetChild(i).gameObject;
            ObjectPoolManager.Destroy(gameObject);
        }

        List <GameObject> visibleButtons = new List <GameObject>();

        for (int i = 0; i < Structures.Length; i++)
        {
            Structure              structure        = Structures[i].GetComponent <Structure>();
            string                 refName          = ObjectPoolManager.GetRefName(structure.gameObject);
            GameObject             buttonGameObject = ObjectPoolManager.Instantiate(buildingScreen.SampleStructureButton);
            StructureButtonCounter buttonCounter    = buttonGameObject.GetComponent <StructureButtonCounter>();
            int count = structure.structureCount - ObjectPoolManager.getActiveCountsByName(refName);

            if (count > 0 || structure.structureCount == -1)
            {
                buttonCounter.SetCountText(count);
                buttonCounter.refStructureName = refName;
                buttonCounter.maxCount         = structure.structureCount;
                Button buttonComponent = buttonGameObject.GetComponent <Button>();
                buttonGameObject.transform.SetParent(buildingScreen.listContent.transform);
                buttonGameObject.transform.localScale = new Vector3(1, 1, 1);
                int index = i;
                buttonComponent.onClick.RemoveAllListeners();
                buttonComponent.onClick.AddListener(() => StartStructurePlacement(buttonGameObject, index));
                buttonComponent.image.overrideSprite = structure.buttonSprite;
                visibleButtons.Add(buttonGameObject);
            }
            else
            {
                ObjectPoolManager.Destroy(buttonGameObject);
            }
        }



        float fullwidth = 55 * visibleButtons.Count;

        rect.sizeDelta = new Vector2(fullwidth, rect.sizeDelta.y);
        for (int i = 0; i < visibleButtons.Count; i++)
        {
            GameObject buttonGameObject = visibleButtons[i];
            float      nextWidth        = 27.5f + (55 * i);
            buttonGameObject.transform.localPosition = new Vector3(nextWidth, -27.5f, 0);
        }
    }
Exemplo n.º 2
0
 private void ResetStructureButtons()
 {
     if (gameStates[1].UIPanel != null)
     {
         BuildingScreen buildingScreen = gameStates[1].UIPanel.GetComponent <BuildingScreen>();
         int            childCount     = buildingScreen.listContent.transform.childCount;
         GameObject     _tempGameObject;
         for (int i = 0; i < childCount; i++)
         {
             _tempGameObject = buildingScreen.listContent.transform.GetChild(i).gameObject;
             StructureButtonCounter butonCounter = _tempGameObject.GetComponent <StructureButtonCounter>();
             string refName      = butonCounter.refStructureName;
             int    currentCount = butonCounter.maxCount - ObjectPoolManager.getActiveCountsByName(refName);
             butonCounter.SetCountText(currentCount);
         }
     }
 }