Example #1
0
        /// <summary>
        /// Load a saved level into the scene.  This clears the currently open scene.
        /// </summary>
        public static void LoadLevel(string levelJson)
        {
            if (pb_Scene.nullableInstance != null)
            {
                pb_Scene.instance.Clear();
            }

            pb_Scene scene = pb_Scene.instance;

            pb_SceneNode root_node = (pb_SceneNode)JsonConvert.DeserializeObject <pb_SceneNode>(levelJson, pb_Serialization.ConverterSettings);

            GameObject root = root_node.ToGameObject();

            Transform[] children = new Transform[root.transform.childCount];

            int i = 0;

            foreach (Transform t in root.transform)
            {
                children[i++] = t;
            }

            foreach (Transform t in children)
            {
                t.SetParent(scene.transform);
            }

            pb_ObjectUtility.Destroy(root);

            if (instance.onLevelLoaded != null)
            {
                instance.onLevelLoaded();
            }
        }
Example #2
0
        /// <summary>
        /// Save the current level.  Returns a JSON formatted string with the entire scene-graph serialized.
        /// </summary>
        public static string SaveLevel()
        {
            pb_SceneNode rootNode   = new pb_SceneNode(instance.gameObject);
            string       scenegraph = JsonConvert.SerializeObject(rootNode,
                                                                  Formatting.Indented,
                                                                  pb_Serialization.ConverterSettings);

            return(scenegraph);
        }