예제 #1
0
    private void CopyMapDataToAttributes(string mapName, MapSerializable mapsData)
    {
        mapsSpotsInfo[mapName] = mapsData.Recover(out int rootIndex);

        // Get root
        List <SpotInfo> spotsInfo = mapsSpotsInfo[mapName];
        SpotInfo        rootInfo  = spotsInfo[rootIndex];

        mapsRoots[mapName] = rootInfo;
    }
예제 #2
0
    public MapSerializable[] LoadAllMaps(string[] mapNames)
    {
        MapSerializable[] mapsInfo = new MapSerializable[mapNames.Length];

        for (int i = 0; i < mapNames.Length; i++)
        {
            mapsInfo[i] = GenericLoad <MapSerializable>(mapNames[i]);
        }

        return(mapsInfo);
    }
예제 #3
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            /*physical = mapObject.GetComponent<PhysicalMap>();
             * physical.init(xSize, ySize);
             * HeightMapGenerator hgen = new HeightMapGenerator();
             * Heightmap heightmap = hgen.generateMap(xSize, ySize);
             * WaterMap watermap = new WaterMap(heightmap);
             * terrainmap = new TerrainMap(heightmap, watermap);
             * temperaturemap = new TemperatureMap(terrainmap, Random.Range(0, 11));
             * tr = new TemperatureRenderer(new LandmassMap(terrainmap), temperaturemap);
             * physical.draw(tr);*/
            physical = mapObject.GetComponent <PhysicalMap>();
            physical.init(xSize, ySize);
            MapSerializable mser      = MapSerializable.loadFromFile("testHM");
            Heightmap       heightmap = new Heightmap(xSize, ySize, 0.5f, mser.grid);
            WaterMap        watermap  = new WaterMap(heightmap);
            terrainmap     = new TerrainMap(heightmap, watermap);
            mser           = MapSerializable.loadFromFile("testTM");
            temperaturemap = new TemperatureMap(xSize, ySize, mser.grid, terrainmap);
            tr             = new TemperatureRenderer(new LandmassMap(terrainmap), temperaturemap);
            physical.draw(tr);
        }
        if (Input.GetMouseButtonDown(1))
        {
            if (state == 0)
            {
                RecursiveWindGenerator wgen = new RecursiveWindGenerator(temperaturemap);
                wm = new WindMap(xSize, ySize, terrainmap, temperaturemap, 3);

                WindSpeedRenderer     wsr = new WindSpeedRenderer(wm, new LandmassMap(terrainmap));
                WindDirectionRenderer wdr = new WindDirectionRenderer(wm, new LandmassMap(terrainmap));

                physical.draw(wsr);
                state++;
            }
            else if (state >= 1)
            {
                RecursiveWindGenerator wgen = new RecursiveWindGenerator(temperaturemap);
                wm = new WindMap(xSize, ySize, terrainmap, temperaturemap, state);

                WindSpeedRenderer     wsr = new WindSpeedRenderer(wm, new LandmassMap(terrainmap));
                WindDirectionRenderer wdr = new WindDirectionRenderer(wm, new LandmassMap(terrainmap));

                physical.draw(wdr);
                state++;
            }
        }
    }
예제 #4
0
    public void PrepareAllMapsForSaving()
    {
        string[] mapNames = GetMapNames();

        int mapsAmount = mapNames.Length;

        // Get All Maps Info
        MapSerializable[] mapsInfo = new MapSerializable[mapsAmount];
        for (int i = 0; i < mapsAmount; i++)
        {
            mapsInfo[i] = GetInfo(mapName: mapNames[i]);
        }

        saveFacade.PrepareMapsForSaving(mapNames, mapsInfo);
    }
예제 #5
0
    public static MapSerializable loadFromFile(string filename)
    {
        string     destination = datapath + filename + extension;
        FileStream fs;

        if (!File.Exists(destination))
        {
            Debug.LogError("map file not found");
        }
        fs = File.OpenRead(destination);
        BinaryFormatter bf = new BinaryFormatter();
        MapSerializable m  = (MapSerializable)bf.Deserialize(fs);

        fs.Close();
        return(m);
    }
예제 #6
0
    public static void LoadMap(byte[] datas)
    {
        //Read binary file
        SerializedScene serializedScene;

        using (MemoryStream ms = new MemoryStream(datas))
        {
            BinaryFormatter bf = new BinaryFormatter();
            serializedScene = bf.Deserialize(ms) as SerializedScene;
            ms.Close();
        }

        MapSerializable map = serializedScene.GetMap();

        //Create map
        GameObject mapGo = map.GetGameObject();

        mapGo.AddComponent <MapController>();

        //Create tiles
        foreach (MapTile tile in map.GetTiles())
        {
            GameObject tileGo = tile.GetGameObject();
            tileGo.transform.parent = mapGo.transform;
            //Mesh renderer
            MeshRenderer meshRenderer = tileGo.AddComponent <MeshRenderer>();
            meshRenderer.material = Resources.Load(tile.GetMaterialName(), typeof(Material)) as Material;
            Texture2D texture = new Texture2D(0, 0, TextureFormat.RGB24, true);
            texture.LoadImage(tile.GetTextureData());
            texture.wrapMode = TextureWrapMode.Clamp;
            meshRenderer.material.mainTexture = texture;
            //Mesh filter
            MeshFilter meshFilter = tileGo.AddComponent <MeshFilter>();
            meshFilter.mesh = tile.GetMesh();
            //Mesh collider
            tileGo.AddComponent <BoxCollider>();

            //File.WriteAllBytes("Deserialized/" + tileGo.name, tile.GetTextureData());
            //Create tile elements
            foreach (TileElement tileElement in tile.GetElements())
            {
                GameObject tileElementGo = tileElement.GetGameObject();
                tileElementGo.SetActive(false);
                tileElementGo.transform.parent = tileGo.transform;
                meshRenderer = tileElementGo.AddComponent <MeshRenderer>();
                Material tileElementMaterial = Resources.Load <Material>("Materials/" + tileElement.GetMaterialName());
                meshRenderer.material = tileElementMaterial;

                meshRenderer.material.color = tileElement.GetMaterialColor();
                meshFilter      = tileElementGo.AddComponent <MeshFilter>();
                meshFilter.mesh = tileElement.GetMesh();

                tileElementGo.SetActive(true);
                //Text mesh
                if (tileElement.GetText() != null)
                {
                    CreateTextMesh(tileElementGo, tileElement.GetText());
                }

                //Scale elements
                tileElementGo.transform.localScale = new Vector3(tileElementGo.transform.localScale.x, tileElementGo.transform.localScale.y, tileElementGo.transform.localScale.z);

                SelectableElementController selectableElementController = tileElementGo.AddComponent <SelectableElementController>();
                selectableElementController.SetAlterable(false);
                selectableElementController.SetBuilding(true);
            }
        }

        //Create additional elements
        GameObject additionalElementContainer = GameObject.Find("AdditionalElements");

        foreach (TileElement element in serializedScene.GetAdditionalElements())
        {
            GameObject tileElementGo = element.GetGameObject();
            tileElementGo.transform.SetParent(additionalElementContainer.transform, false);;
            //Mesh renderer
            MeshRenderer meshRenderer = tileElementGo.AddComponent <MeshRenderer>();
            meshRenderer.material       = Resources.Load(element.GetMaterialName(), typeof(Material)) as Material;
            meshRenderer.material.color = element.GetMaterialColor();
            //Mesh filter
            MeshFilter meshFilter = tileElementGo.AddComponent <MeshFilter>();
            meshFilter.mesh = element.GetMesh();
            //Controller
            SelectableElementController selectableElementController = tileElementGo.AddComponent <SelectableElementController>();
            selectableElementController.SetAlterable(element.IsAlterable());
            selectableElementController.SetBuilding(false);
            // Mesh Collider
            tileElementGo.AddComponent <BoxCollider>();
            //Text mesh
            if (element.GetText() != null)
            {
                CreateTextMesh(tileElementGo, element.GetText());
            }
        }
    }
예제 #7
0
    public static void SaveMap()
    {
        string dataPath = Application.streamingAssetsPath;

        //Serialize map
        GameObject      map             = GameObject.Find("Map");
        MapSerializable mapSerializable = new MapSerializable(map);

        foreach (Transform tileTransform in map.transform)
        {
            if (tileTransform.gameObject != map)
            {
                //Tile
                GameObject tileGO = tileTransform.gameObject;
                MapTile    tile   = new MapTile(tileGO);
                foreach (Transform tileElementTransform in tileGO.transform)
                {
                    //Tile Element
                    if (tileElementTransform.gameObject != tileGO)
                    {
                        String text = tileElementTransform.GetComponentInChildren <TextMesh>() != null?tileElementTransform.GetComponentInChildren <TextMesh>().text : null;

                        TileElement tileElement = new TileElement(tileElementTransform.gameObject, "MapBuilding", text);
                        tileElement.SetAlterable(false);
                        tile.AddElement(tileElement);
                    }
                }
                mapSerializable.AddTile(tile);
            }
        }
        int             i = 1;
        SerializedScene serializedScene = new SerializedScene();

        serializedScene.SetMap(mapSerializable);

        //Serialize Additional Elements
        GameObject additionalElementContainer = GameObject.Find("AdditionalElements");

        foreach (Transform elementTransform in additionalElementContainer.transform)
        {
            if (elementTransform.gameObject != additionalElementContainer && elementTransform.GetComponentInChildren <MeshFilter>() != null && elementTransform.gameObject.activeInHierarchy)
            {
                TileElement tileElement;


                String text = elementTransform.GetComponentInChildren <TextMesh>() != null?elementTransform.GetComponentInChildren <TextMesh>().text : null;

                //ElementMenuController ElementMenuController = GameObject.Find("ElementMenuCanvas").GetComponent<ElementMenuController>();
                //if (chidlrenGO.GetComponent<MeshRenderer>().material.color != null && chidlrenGO.Equals(ElementMenuController.GetSelectedElement()))
                //    tileElement = new TileElement(chidlrenGO, "AdditionalElement", ElementMenuController.GetSelectedElement().GetComponent<MeshRenderer>().material.color, text);

                //else
                tileElement = new TileElement(elementTransform.gameObject, "AdditionalElement", text);

                tileElement.SetAlterable(elementTransform.GetComponent <SelectableElementController>().IsAlterable());
                serializedScene.AddAdditionalElement(tileElement);
                ++i;
            }
        }

        BinaryFormatter bf = new BinaryFormatter();
        //Save a file
        String filePath = dataPath + "/map-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss.fff") + ".bytes";
        //String filePath = "./Assets" + Scenes.GetParamForString("titleProject") + "/map-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss.fff") + ".bytes";

        FileStream stream = new FileStream(filePath, FileMode.Create);

        bf.Serialize(stream, serializedScene);

        Debug.Log("Serialization Done.");
        stream.Close();

        //Save a BLOB
        //byte[] savedDatas;
        //using (MemoryStream ms = new MemoryStream())
        //{
        //    bf.Serialize(ms, serializedScene);
        //    savedDatas = ms.ToArray();
        //    ms.Close();
        //}
        //Save BDD and Update binary file
        //DataService.UpdateProposalSaveFile(savedDatas);
        //Scenes.GetSelectedProposal().File = savedDatas;
    }
예제 #8
0
 public void SetMap(MapSerializable map)
 {
     this.map = map;
 }