예제 #1
0
        public void Deserialize(SerializedScene obj)
        {
            ID     = obj.id;
            nextID = ID + 1;

            Title       = obj.title;
            Notes       = obj.notes;
            Description = obj.description;
            X           = obj.x;
            Y           = obj.y;

            string val;
            Clue   clue = new Clue();

            for (int i = 0; i < obj.clues.Length; i++)
            {
                val = obj.clues[i];
                if (val.StartsWith("#"))
                {
                    clue.Color = val;
                }
                else
                {
                    clue.Text = val;
                    clues.Add(clue);
                    clue = new Clue();
                }
            }
        }
예제 #2
0
        public void SaveScene(string path)
        {
            try
            {
                var serScene = new SerializedScene()
                {
                    Materials      = _editorScene.Materials.ToArray(),
                    GameObjects    = _editorScene.GetGameObjects(),
                    RenderSettings = _editorScene.RenderSettings
                };

                Serializer.Serialize(path, serScene);
            }
            catch (Exception ex)
            {
                Debug.Log(ex.Message);
            }
        }
예제 #3
0
        public SerializedScene Serialized()
        {
            List <string> clues = new List <string>();

            foreach (Clue clue in this.clues)
            {
                clues.Add(clue.Color);
                clues.Add(clue.Text);
            }

            SerializedScene serScene = new SerializedScene {
                id          = ID,
                title       = Title,
                notes       = Notes,
                description = Description,
                x           = X,
                y           = Y,
                clues       = clues.ToArray()
            };

            return(serScene);
        }
예제 #4
0
        public bool SaveScene(string path)
        {
            var result = true;

            try
            {
                var serScene = new SerializedScene()
                {
                    Materials      = _scene.GetUsedMaterials(),
                    SceneObjects   = _scene.GetUsedSceneObjects(),
                    RenderSettings = _scene.RenderSettings
                };

                Serializr.Serialize(path, serScene);
            }
            catch (Exception ex)
            {
                result = false;
                Debug.Log(ex.Message);
            }

            return(result);
        }
예제 #5
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;
    }