Exemplo n.º 1
0
    public void openJsonConfig()
    {
        addedSceneObjects = new List <Tuple <SceneObject, GameObject> >();

        string path = EditorUtility.OpenFilePanel("Load Json Config...", "Assets\\JsonConfigurations", "json");

        if (".json".Equals(Path.GetExtension(path)))
        {
            string             json         = File.ReadAllText(path);
            List <SceneObject> sceneObjects = SceneObject.FromJSON(json);

            //If the deserialization was successful: Delete all existing GameObjects / Facts
            GameState.Facts.Clear();
            foreach (string entry in SceneLoaderDictionary.sceneObjectsTagList)
            {
                GameObject[] objects = GameObject.FindGameObjectsWithTag(entry);
                foreach (GameObject obj in objects)
                {
                    Destroy(obj);
                }
            }

            for (int i = 0; i < sceneObjects.Count; i++)
            {
                SceneLoaderDictionary.loadSceneObjectDictionary[sceneObjects[i].GetType()].Invoke(sceneObjects[i]);
            }
        }
        else
        {
            Debug.Log("OpenJsonConfig: Selected file was not a json-file.");
        }
    }