示例#1
0
    public void SaveFileWasLoaded(BuildingsOnMap[] saveFileBuildingsData, RoadsOnMap[] saveFileRoadsData)
    {
        // Removes existing buildings first
        RemoveAllBuildingsFromMap_Quietly();

        BaseBuildingsClass savedBuilding = null;
        Vector3            savedPosition = Vector3.zero;

        for (int i = 0; i < saveFileBuildingsData.Length; ++i)
        {
            savedPosition.x = saveFileBuildingsData[i].worldPosX;
            savedPosition.y = saveFileBuildingsData[i].worldPosY;
            savedBuilding   = Instantiate(BuildingDataBase.GetInstance().GetBaseBuildingGO(), savedPosition, Quaternion.identity).GetComponent <BaseBuildingsClass>();
            savedBuilding.SetNewBuildingType(BuildingDataBase.GetInstance().GetBuildingData((BuildingDataBase.BUILDINGS)saveFileBuildingsData[i].buildingType));
            PlaceBuildingToGrid(ref savedBuilding);
        }

        //do the same for the roads
        for (int i = 0; i < saveFileRoadsData.Length; ++i)
        {
            savedPosition.x = saveFileRoadsData[i].worldPosX;
            savedPosition.y = saveFileRoadsData[i].worldPosY;
            savedBuilding   = Instantiate(BuildingDataBase.GetInstance().GetBaseBuildingGO(), savedPosition, Quaternion.identity).GetComponent <BaseBuildingsClass>();
            savedBuilding.SetNewBuildingType(BuildingDataBase.GetInstance().GetBuildingData(BuildingDataBase.BUILDINGS.B_ROAD));

            //set to the correct road direction sprite
            RoadTypeList roadType = (RoadTypeList)saveFileRoadsData[i].roadType;
            savedBuilding.SetSprite(BuildingDataBase.GetInstance().GetRoadSprite(roadType));
            StoreLoadedRoads(savedBuilding, roadType);
        }
    }
    public void SetRoadSprite(Vector2Int key, RoadTypeList type)
    {
        BaseBuildingsClass road = m_RoadSpriteRendererMap[key];

        road.SetSprite(BuildingDataBase.GetInstance().GetRoadSprite(type));

        //change and store the road type
        int indexConverted = Convert2DToIntIndex(key);

        if (m_RoadMap.ContainsKey(indexConverted))
        {
            m_RoadMap[indexConverted] = type;
        }
    }
    public void ZeroRoadAround(Vector2Int key)
    {
        BaseBuildingsClass road = m_RoadSpriteRendererMap[key];

        road.SetSprite(BuildingDataBase.GetInstance().GetRoadSprite(RoadTypeList.NO_CONNECTION));
    }