Beispiel #1
0
        // Создание списка строений
        private void DoCreateBuildings()
        {
            Transform LBuildingSlot;
            MonoUIObjectBuildingBuy LBuilding;

            FBuildings = new List <MonoUIObjectBuildingBuy>();
            // На каждый тип строения по зданию
            foreach (BuildingType LBuildingType in Enum.GetValues(typeof(BuildingType)))
            {
                if (LBuildingType > BuildingType.Modules)
                {
                    continue;
                }
                // Сперва слот строения
                LBuildingSlot = PrefabManager.CreateBuildingBuySlot(FTransform, Vector3.zero).transform;
                LBuildingSlot.SetParent(FTransform, false);
                // И в него само строение
                LBuilding = LBuildingSlot.GetComponent <MonoUIObjectBuildingBuy>();
                LBuilding.InitData(FPosition, LBuildingType);
                // Добавим в список строений
                FBuildings.Add(LBuilding);
            }
            UpdateTech();
        }
        // Создание экземпляра строения
        void DoBuildingsCreate(int ACount, bool AChange, bool AEnabled)
        {
            Transform            LBuildingSlot;
            MonoUIObjectBuilding LBuilding;

            // Заготовка создается один раз
            if (FBuildings.Count == 0)
            {
                for (int LIndex = 0; LIndex < C_SLOT_COUNT_BIG; LIndex++)
                {
                    LBuildingSlot = PrefabManager.CreateBuildingSlot(FTransform, Vector3.zero).transform;
                    LBuildingSlot.SetParent(FTransform, false);
                    LBuilding = LBuildingSlot.GetComponent <MonoUIObjectBuilding>();
                    LBuilding.InitData(LIndex, PanelTech);
                    FBuildings.Add(LBuilding);
                }
            }
            // Далее нужно включить нужные слоты
            int LCount;
            int LActiveCount;

            // В больших 2 пустых, в маленьких 1 пустой, в остальных слотов нет
            if (FPlanet.PlanetMode == PlanetMode.Big)
            {
                LCount       = C_SLOT_COUNT_BIG;
                LActiveCount = LCount - 2;
            }
            else
            if (FPlanet.PlanetMode == PlanetMode.Normal)
            {
                LCount       = C_SLOT_COUNT_SMALL;
                LActiveCount = LCount - 1;
            }
            else
            {
                LCount       = 0;
                LActiveCount = 0;
            }
            // Теперь переберем все слоты, включим нужные и зададим им координаты
            Vector3 LPosition;

            for (int LIndex = 0; LIndex < C_SLOT_COUNT_BIG; LIndex++)
            {
                bool LNonBuild = (LIndex >= LActiveCount);
                // Меняем только те здания, которые показываются, скрытые не чистим
                if (LIndex < LCount)
                {
                    if ((FPlanet.PlanetMode == PlanetMode.Normal) && (LIndex < C_SLOT_COUNT_SMALL))
                    {
                        LPosition = FCoordBy7[LIndex];
                    }
                    else
                    {
                        LPosition = FCoordBy10[LIndex];
                    }
                    // Меняем состояние для кнопок всех строений
                    FBuildings[LIndex].UpdateButtons(AEnabled && !LNonBuild);
                    // При смене планеты меняем фон
                    if (AChange)
                    {
                        FBuildings[LIndex].UpdateBuildingData(BuildingType.Empty, 0, 0);
                        FBuildings[LIndex].UpdatePlace(LPosition, SpriteManager.BuildingPlace(FPlanet.PlanetType, !LNonBuild));
                    }
                }
                // Скрытые скрываем
                FBuildings[LIndex].gameObject.SetActive(LIndex < LCount);
            }
        }