示例#1
0
        public void Setup()
        {
            IGameboard             gameboard       = new Gameboard();
            GameboardConfiguration gameboardConfig = Resources.Load <GameboardConfiguration>("Gameboard Configuration");

            gameboard.Initialise(gameboardConfig);
            ServiceLocator.Instance.ProvideService <IGameboard>(gameboard);

            this.configService = new BuildingConfigurationService();
            ServiceLocator.Instance.ProvideService <IBuildingConfigurationService>(this.configService);

            ServiceLocator.Instance.ProvideService <IBuildingVisualFactory>(new DummyBuildingVisualFactory());

            this.buildingService = new BuildingService();
            ServiceLocator.Instance.ProvideService <IBuildingService>(this.buildingService);

            BuildingLibrary library = this.GetFakeBuildingLibrary();

            library.buildingConfigurations = new BuildingConfiguration[]
            {
                this.GetFakeBuildingConfiguration("Common_1", BuildingType.COMMON, 5, new Vector2Int(1, 1)),
                this.GetFakeBuildingConfiguration("Common_2", BuildingType.COMMON, -1, new Vector2Int(1, 1)),
                this.GetFakeBuildingConfiguration("Unique_1", BuildingType.UNIQUE, 1, new Vector2Int(2, 2)),
            };

            this.configService.UpdateConfiguration(library);
        }
示例#2
0
    void GetBuildings(BuildingCategory category)
    {
        Buildings = BuildingLibrary.GetBuildingsForCategory(category);

        max = (int)Math.Ceiling(Buildings.Count / 6f);



        GenerateBuildingButtons();
    }
示例#3
0
        public void Setup()
        {
            this.buildingLibrary = Resources.Load <BuildingLibrary>(BuildingLibrary.RESOURCE_LOCATION);

            this.buildingConfigurations = new List <BuildingConfiguration>();
            string[] buildingConfigGUIDs = AssetDatabase.FindAssets("t:BuildingConfiguration", new string[] { "Assets/Configuration/Buildings" });
            foreach (var buildingConfigGUID in buildingConfigGUIDs)
            {
                this.buildingConfigurations.Add(AssetDatabase.LoadAssetAtPath <BuildingConfiguration>(AssetDatabase.GUIDToAssetPath(buildingConfigGUID)));
            }
        }
示例#4
0
    // Use this for initialization
    void Start()
    {
        btn1.onClick.AddListener(() => { activeTool = Tool.Shovel; txt.text = "Shovel"; });
        btn2.onClick.AddListener(() => { activeTool = Tool.Move; txt.text = "Move"; });
        btn3.onClick.AddListener(() => { activeTool = Tool.Delete; txt.text = "Destroy"; });

        space      = new Space(6, 6);
        blueprints = new BlueprintLibrary();
        buildings  = new BuildingLibrary();
        materials  = new MaterialLibrary();
        toolTip    = GameObject.FindGameObjectWithTag("ToolTip").GetComponent <TooltipScript>();
    }
示例#5
0
        void InitialiseServices()
        {
            IBuildingConfigurationService buildingConfigurationService = ServiceLocator.Instance.GetService <IBuildingConfigurationService>();
            BuildingLibrary library = Resources.Load <BuildingLibrary>(BuildingLibrary.RESOURCE_LOCATION);

            buildingConfigurationService.UpdateConfiguration(library);

            IGameboard             gameboard       = ServiceLocator.Instance.GetService <IGameboard>();
            GameboardConfiguration gameboardConfig = Resources.Load <GameboardConfiguration>(GameboardConfiguration.RESOURCE_LOCATION);

            gameboard.Initialise(gameboardConfig);

            IBuildingService buildingService = ServiceLocator.Instance.GetService <IBuildingService>();

            buildingService.Load();
        }
示例#6
0
        public void Setup()
        {
            this.wasRaisingExceptions = UnityEngine.Assertions.Assert.raiseExceptions;
            UnityEngine.Assertions.Assert.raiseExceptions = false;

            this.configService = new BuildingConfigurationService();

            BuildingLibrary library = this.GetFakeBuildingLibrary();

            library.buildingConfigurations = new BuildingConfiguration[]
            {
                this.GetFakeBuildingConfiguration("Common_1", BuildingType.COMMON, 5),
                this.GetFakeBuildingConfiguration("Common_2", BuildingType.COMMON, 4),
                this.GetFakeBuildingConfiguration("Unique_1", BuildingType.UNIQUE, 1),
                this.GetFakeBuildingConfiguration("Unique_2", BuildingType.UNIQUE, 1),
            };

            this.configService.UpdateConfiguration(library);
        }
示例#7
0
    public void StartTool(Type tileEnt, int buildingIndex, int gridID)
    {
        _tileEnt = tileEnt;
        BuildingMap map = BuildingLibrary.GetBuildingsForCategory(Infrastructure.Grid.Entities.Buildings.BuildingCategory.All).Where(x => x.BuildingType.IsEquivalentTo(tileEnt)).First();

        model = map.Model;
        cost  = map.Cost;

        if (_tileEnt != null)
        {
            active = true;
        }

        this.gridID        = gridID;
        this.buildingIndex = buildingIndex;

        OpenMenu();
        ghostEnt = CreateGhostBuilding();
    }
示例#8
0
        public void Setup()
        {
            this.buildingSaveService = new BuildingSaveService();

            this.configService = new BuildingConfigurationService();
            ServiceLocator.Instance.ProvideService <IBuildingConfigurationService>(this.configService);

            ServiceLocator.Instance.ProvideService <IBuildingVisualFactory>(new DummyBuildingVisualFactory());

            BuildingLibrary library = this.GetFakeBuildingLibrary();

            library.buildingConfigurations = new BuildingConfiguration[]
            {
                this.GetFakeBuildingConfiguration("Common_1", BuildingType.COMMON, 5),
                this.GetFakeBuildingConfiguration("Common_2", BuildingType.COMMON, 4),
                this.GetFakeBuildingConfiguration("Unique_1", BuildingType.UNIQUE, 1),
                this.GetFakeBuildingConfiguration("Unique_2", BuildingType.UNIQUE, 1),
            };

            this.configService.UpdateConfiguration(library);
        }
示例#9
0
 public void Initialize()
 {
     BuildingLibrary.Initialize(Settings);
 }
示例#10
0
    /// <summary>
    /// Load grid data and restore their contents.
    /// </summary>
    public void LoadDataFromSave()
    {
        if (gridInfo.Count == 0)
        {
            return;
        }

        List <BuildingMap> buildingMap = BuildingLibrary.GetBuildingsForCategory(BuildingCategory.All);

        //Loop and restore each grid entity for each grid.
        for (int i = 0; i < gridInfo.Count; i++)
        {
            Game.CurrentSession.City.CreateGrid(gridInfo[i].width, gridInfo[i].height, gridInfo[i].worldPos);
            GridSystem grid = Game.CurrentSession.City.GetGrid(i);

            for (int j = 0; j < gridInfo[i].gridEntities.Count; j++)
            {
                int x     = gridInfo[i].gridEntities[j].x;
                int y     = gridInfo[i].gridEntities[j].y;
                int index = gridInfo[i].gridEntities[j].z;

                //Manually handle the road typing.
                Type entityType;
                if (index == -1)
                {
                    entityType = typeof(Road);
                }
                else
                {
                    entityType = buildingMap[index].BuildingType;
                }

                TileEntity tileEnt = Activator.CreateInstance(entityType) as TileEntity;

                grid.AddTileEntityToTile(x, y, tileEnt);
            }

            //Restore residents AFTER grid entities have been restored.
            foreach (ResidentData resInfo in gridInfo[i].residentData)
            {
                Resident newResident = null; //Silly vs
                try
                {
                    newResident = new Resident(resInfo);
                    Game.CurrentSession.City.Residents.Add(newResident);
                    Residential res = (Residential)Game.CurrentSession.City.GetGrid(resInfo.HomeGridID).GetTile(resInfo.HomePosition)?.Entity;
                    if (res != null)
                    {
                        res.AddResident(newResident);
                    }
                    else
                    {
                        Game.CurrentSession.City.ProcessHomelessResident(newResident);
                    }

                    foreach (Job j in ((Commercial)Game.CurrentSession.City.GetGrid(resInfo.JobGridID).GetTile(resInfo.JobPosition).Entity).Jobs)
                    {
                        if (!j.Taken)
                        {
                            newResident.SetJob(j);
                            break;
                        }
                    }
                    if (newResident.Job == null)
                    {
                        //Coult not give this resident a job? leave it unemployed.
                        Game.CurrentSession.City.UnemployedResidents.Add(newResident);
                    }
                }
                catch (Exception)
                {
                    //Abandon loading this resident.
                    //Try to remove it if we added it earlier.
                    if (newResident != null)
                    {
                        if (Game.CurrentSession.City.Residents.Contains(newResident))
                        {
                            Game.CurrentSession.City.Residents.Remove(newResident);
                        }
                    }
                    //Increase demand to offset the lost resident.
                    Game.CurrentSession.Settings.ResidentialDemand++;
                }
            }
        }
    }