public void LoadScene(DSceneAsset asset) { Scene scene = new Scene(); scene.Load(asset); scenes[scene.name] = scene; }
public void Load(DSceneAsset asset) { name = asset.scene; path.LoadNavMesh(asset.mesh); foreach (DEntity e in asset.entities.list) { if (e.forClone) { World.Instance.EntityData.TryAdd(e.name, e); } Entity entity = World.CreateEntity(e); if (entity != null) { AddEntity(entity); } } foreach (KeyValuePair <int, Sprite> kv in sprites) { kv.Value.Spawn(); } foreach (KeyValuePair <int, Item> kv in items) { kv.Value.Spawn(); } }
public void Load(DSceneAsset asset) { name = asset.scene; path.LoadNavMesh(asset.mesh); foreach (DEntity e in asset.entities.list) { if (e.forClone) { World.Instance.EntityData.TryAdd(e.name, e); } Entity entity = World.CreateEntity(e); if (entity != null) { AddEntity(entity); } } foreach (KeyValuePair <int, Sprite> kv in sprites) { kv.Value.Spawn(); } foreach (KeyValuePair <int, Item> kv in items) { kv.Value.Spawn(); } initPos["Level2"] = new V3(-1.54978f, -3.50585f, 28.5845f); initPos["Level1"] = new V3(23.95f, 1.578f, 64.29f); }
private static void NavMeshToAsset(DSceneAsset asset) { GameObject obj = CreateNavMeshObject(); Transform transform = obj.transform.Find("_NavMesh"); Vector3[] localVectors = transform.GetComponent <MeshFilter>().sharedMesh.vertices; int[] triangles = transform.GetComponent <MeshFilter>().sharedMesh.triangles; Vector3[] worldVectors = new Vector3[localVectors.Length]; for (int i = 0; i < localVectors.Length; i++) { Vector3 pos = transform.TransformPoint(localVectors[i]); worldVectors[i] = pos; } for (int i = 0; i < triangles.Length; i += 3) { DTngl element = new DTngl(); for (int j = 0; j < 3; j++) { element.p[j] = new V3(); element.p[j].x = worldVectors[triangles[i + j]].x; element.p[j].y = worldVectors[triangles[i + j]].y; element.p[j].z = worldVectors[triangles[i + j]].z; } asset.mesh.list.Add(element); } DestroyImmediate(obj); }
private static void Export() { DataPath = Application.dataPath + "/BEAssets/"; DSceneAsset asset = new DSceneAsset(); NavMeshToAsset(asset); EntitiesToAsset(asset); string filename = asset.scene + ".asset"; using (StreamWriter sw = new StreamWriter(DataPath + filename)) { XmlSerializer serializer = new XmlSerializer(typeof(DSceneAsset)); serializer.Serialize(sw, asset); Debug.Log("Export:" + asset.scene + ".asset"); } using (StreamWriter sw = new StreamWriter(DataPath + "backend.conf")) { BackendConf conf = new BackendConf(); conf.host = "0.0.0.0"; conf.port = 7777; conf.asset_path = DataPath; conf.scenes = new List <string>(); conf.scenes.Add("Level1.asset"); XmlSerializer serializer = new XmlSerializer(typeof(BackendConf)); serializer.Serialize(sw, conf); Debug.Log("Export:backend.conf"); } AssetDatabase.Refresh(); }
private void LoadAssets() { foreach (string sceneName in conf.scenes) {// foreach scene assets, TODO XmlSerializer serializer = new XmlSerializer(typeof(DSceneAsset)); StreamReader reader = new StreamReader(conf.asset_path + "/" + sceneName); DSceneAsset asset = (DSceneAsset)serializer.Deserialize(reader); World.Instance.LoadScene(asset); } }
private static void EntitiesToAsset(DSceneAsset asset) { // exprot all network entity asset.scene = SceneManager.GetActiveScene().name; NetworkEntity[] entities = GameObject.FindObjectsOfType <NetworkEntity>(); foreach (NetworkEntity entity in entities) { entity.BuildTree(); if (entity.parent == null) { asset.entities.list.Add(entity.ToDEntity()); } } }