示例#1
0
文件: pb_Scene.cs 项目: FAL2009/giles
        /// <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();
            }
        }
示例#2
0
文件: pb_Scene.cs 项目: FAL2009/giles
        /// <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);
        }