private void DisplayExport() { Label("Export"); NameExport = TextField(NameExport); if (AddButton("Export")) { // export all ship part in xml // key was invalid _pandaBuild.SortLocation(); XmlRW.Export(_pandaBuild.ShipPartEntities, NameExport, _pandaSettings.Camera, _pandaBuild.ShipParent, _pandaSettings.ShootingsSpawn, _pandaSettings.SpeedFxSpawn); } if (AddButton("Load")) { LoadFile(); } }
private void LoadFile() { _pandaBuild.Clean(); // load part from file Dictionary <int, Tool.ShipPart> shipParts = new Dictionary <int, Tool.ShipPart>(); // check if we must spawn camera, ship parent _pandaSettings.SpawnIfNecessary(); _pandaBuild.SpawnIfNecessary(); XmlRW.Load(NameExport, ref shipParts, _pandaSettings.Camera, _pandaBuild.ShipParent, _pandaSettings.ShootingsSpawn, _pandaSettings.SpeedFxSpawn); // refresh nb shooting spawn NbShootingPoint = _pandaSettings.ShootingsSpawn.Count; // refresh nb speed fx NbFxSpeed = _pandaSettings.SpeedFxSpawn.Count; _pandaBuild.CreateParts(ref shipParts); }
public static void Load(string shipName, ref Dictionary <int, ShipPart> shipParts, Transform cameraParent, Transform shipParent, List <Transform> shootingsSpawn, List <Transform> speedFxSpawn) { // list of scriptable List <ScriptableCube> scriptableCubeList = new List <ScriptableCube>(); // find all scriptable cube string[] scriptables = AssetDatabase.FindAssets("Pa_"); foreach (string scriptable in scriptables) { string path = AssetDatabase.GUIDToAssetPath(scriptable); scriptableCubeList.Add(AssetDatabase.LoadAssetAtPath(path, typeof(ScriptableCube)) as ScriptableCube); } shipParts.Clear(); XDocument xmlDoc = XDocument.Load(Application.dataPath + "/Export/" + shipName + ".xml"); foreach (var xmlParts in xmlDoc.Root.Elements("Part")) { // key of this part int key = Int32.Parse(xmlParts.Element("Key").Attribute("Id").Value); // find the right scriptable cube foreach (ScriptableCube param in scriptableCubeList) { if (param.GetUniqueId() == key) { shipParts.Add(key, new ShipPart(param)); } } // check ship param if (!shipParts.ContainsKey(key)) { Debug.LogError("Cube type : " + key + " was unknown."); continue; } // add all point Vector3 pos = Vector3.zero; foreach (var elem in xmlParts.Element("Map").Elements("Data")) { pos = XmlRW.StringToVector3(elem.Attribute("value").Value); shipParts[key].Add(new UnitPos(pos.x, pos.y, pos.z)); } } var xmlCamera = xmlDoc.Root.Element("Camera"); cameraParent.localPosition = new Vector3(float.Parse(xmlCamera.Element("Position").Attribute("x").Value), float.Parse(xmlCamera.Element("Position").Attribute("y").Value), float.Parse(xmlCamera.Element("Position").Attribute("z").Value)); cameraParent.forward = new Vector3(float.Parse(xmlCamera.Element("Forward").Attribute("x").Value), float.Parse(xmlCamera.Element("Forward").Attribute("y").Value), float.Parse(xmlCamera.Element("Forward").Attribute("z").Value)); var xmlPivot = xmlDoc.Root.Element("Pivot"); shipParent.position = new Vector3(float.Parse(xmlPivot.Element("Position").Attribute("x").Value), float.Parse(xmlPivot.Element("Position").Attribute("y").Value), float.Parse(xmlPivot.Element("Position").Attribute("z").Value)); // load position of shootings spawn LoadList(ref shootingsSpawn, "Shooting", ref xmlDoc, Builder.FactoryType.Gameplay, (int)BuilderGameplay.Type.BulletSpawner); // speed fx LoadList(ref speedFxSpawn, "SpeedFx", ref xmlDoc, Builder.FactoryType.Fx, (int)BuilderFx.Type.Speed); }