// load single prefab file private void LoadPrefab(string _filepath) { XmlDocument doc = new XmlDocument(); doc.Load(_filepath); XmlNode nodePrefab = doc.SelectSingleNode("Prefab"); // load gameobjects and build relationships /*Dictionary<string, GameObject> tempList = new Dictionary<string, GameObject>();*/ // LoadFromNode List <GameObject> gameObjects = new List <GameObject>(); Serialable.BeginSupportingDelayBinding(); foreach (XmlNode nodeGameObject in nodePrefab.ChildNodes) { GameObject newGameObject = GameObject.DoUnserial(nodeGameObject) as GameObject; gameObjects.Add(newGameObject); /*GameObject newGameObject = GameObject.LoadFromNode(nodeGameObject, null);*/ /*tempList.Add(newGameObject.GUID, newGameObject);*/ } Serialable.EndSupportingDelayBinding(); // add root to prefabeList foreach (GameObject gameObject in gameObjects) { if (gameObject.Parent == null) { AddItem(gameObject.Name, gameObject); } } }
public static GameObjectList LoadFromNode(XmlNode node, Scene scene) { GameObjectList gameObjectList = new GameObjectList(); Serialable.BeginSupportingDelayBinding(); foreach (XmlNode gameObject in node.ChildNodes) { GameObject newGameObject = (GameObject)(Serialable.DoUnserial(gameObject)); gameObjectList.AddGameObject(newGameObject); } Serialable.EndSupportingDelayBinding(); return(gameObjectList); }
/** * @brief load bttree from file **/ public static BTTree Load(string _filepath) { XmlDocument doc = new XmlDocument(); doc.Load(_filepath); BTTree newBTTree = new BTTree(); XmlNode nodeBTTree = doc.SelectSingleNode("BTTree"); XmlNode nodeRoot = nodeBTTree.SelectSingleNode("Root"); XmlNode nodeRealRoot = nodeRoot.FirstChild; Serialable.BeginSupportingDelayBinding(); newBTTree.m_root = Serialable.DoUnserial(nodeRealRoot) as BTNode; Serialable.EndSupportingDelayBinding(true); return(newBTTree); }
/** * @brief Load models under the directory * * @param _modelDirectory the directory containing .model files * @param _project CatProject * * @result the CatModelList * */ public static CatModelList LoadModels(string _modelDirectory, CatProject _project) { // create CatModelList modelList = new CatModelList(); // search for .material files under _materialDirectory if (!Directory.Exists(_modelDirectory)) { return(modelList); } string[] files = Directory.GetFiles(_modelDirectory, "*.model"); foreach (string file in files) { XmlDocument doc = new XmlDocument(); doc.Load(file); XmlNode nodeModel = doc.SelectSingleNode( typeof(CatModel).ToString()); Serialable.BeginSupportingDelayBinding(); CatModel catsModel = CatModel.DoUnserial(nodeModel) as CatModel; Serialable.EndSupportingDelayBinding(); modelList.AddModel(catsModel); } return(modelList); }
/** * @brief create a scene from an XML file * * @param node the XML node * @param game the game engine * * @result scene * */ public static Scene LoadScene(string _filename) // node is the current node { XmlDocument doc = new XmlDocument(); doc.Load(_filename); XmlNode node = doc.SelectSingleNode("Scene"); Scene newScene = new Scene(); // working list newScene._renderList = new RenderList(); //newScene._colliderList = new ColliderList(); newScene.m_physicsSystem = new PhysicsSystem(); newScene.m_shadowSystem = new ShadowSystem(Mgr <CatProject> .Singleton); newScene._renderList.SetShadowRender(newScene.m_shadowSystem); newScene._uiRenderer = new UIRenderer(); newScene.m_physicsSystem.Initialize(); if (Mgr <GameEngine> .Singleton._gameEngineMode == GameEngine.GameEngineMode.MapEditor) { newScene._debugDrawableList = new DebugDrawableList(); newScene._debugDrawableList.AddItem(newScene); newScene._selectableList = new RepeatableList <ISelectable>(); } // bind to current scene //Mgr<Scene>.Singleton = newScene; // init scene basic list // load and construct scene here XmlNode basic = node.SelectSingleNode("SceneBasic"); XmlElement sceneBasic = (XmlElement)basic; newScene.setYAngle(float.Parse(sceneBasic.GetAttribute("viewAngle"))); String playerGameObjectName = sceneBasic.GetAttribute("playerGameObjectName"); XmlElement XBound = (XmlElement)sceneBasic.SelectSingleNode("XBound"); newScene._XBound = new Vector2(float.Parse(XBound.GetAttribute("min")), float.Parse(XBound.GetAttribute("max"))); XmlElement YBound = (XmlElement)sceneBasic.SelectSingleNode("YBound"); newScene._YBound = new Vector2(float.Parse(YBound.GetAttribute("min")), float.Parse(YBound.GetAttribute("max"))); XmlElement ZBound = (XmlElement)sceneBasic.SelectSingleNode("ZBound"); newScene._ZBound = new Vector2(float.Parse(ZBound.GetAttribute("min")), float.Parse(ZBound.GetAttribute("max"))); // camera XmlNode nodeCamera = node.SelectSingleNode(typeof(Camera).ToString()); Serialable.BeginSupportingDelayBinding(); Camera camera = Serialable.DoUnserial((XmlElement)nodeCamera) as Camera; Serialable.EndSupportingDelayBinding(); //Mgr<Camera>.Singleton = camera; newScene.m_camera = camera; newScene.m_camera.UpdateView(); newScene.m_camera.UpdateProjection(); // postprocess manager XmlNode nodePostProcessManager = node.SelectSingleNode(typeof(PostProcessManager).ToString()); Serialable.BeginSupportingDelayBinding(); newScene.m_postProcessManager = Serialable.DoUnserial((XmlElement)nodePostProcessManager) as PostProcessManager; Serialable.EndSupportingDelayBinding(); // gameObjects XmlNode gameObjects = node.SelectSingleNode("GameObjects"); newScene._gameObjectList = GameObjectList.LoadFromNode(gameObjects, newScene); PostLoadScene(newScene); return(newScene); }