protected override EmitterList Read(ContentReader input, EmitterList existingInstance) { if (existingInstance != null) { return(existingInstance); } EmitterSaveList esl = ObjectReader.ReadObject <EmitterSaveList>(input); esl.Name = input.AssetName; return(esl.ToEmitterList("")); //// read how many emitters there are //int count = input.ReadInt32(); //existingInstance = new EmitterList(); //for (int i = 0; i < count; i++) //{ // Emitter emitter = new Emitter(); // existingInstance.Add(emitter); // emitter.X = input.ReadSingle(); // emitter.Y = input.ReadSingle(); // emitter.Z = input.ReadSingle(); // emitter.ScaleX = input.ReadSingle(); // emitter.ScaleY = input.ReadSingle(); // emitter.ScaleZ = input.ReadSingle(); // emitter.AreaEmission = // FlatRedBall.Graphics.GraphicalEnumerations.TranslateAreaEmissionType( // input.ReadString() ); // emitter.EmissionSettings = input.ReadObject<EmissionSettings>(); // input.ReadString(); // ParentSpriteName // emitter.Name = input.ReadString(); // emitter.ParticleBlueprint = input.ReadObject<Sprite>(); // emitter.RemovalEvent = FlatRedBall.Graphics.Particle.Emitter.TranslateRemovalEvent(input.ReadString()); // emitter.SecondFrequency = input.ReadSingle(); // emitter.NumberPerEmission = input.ReadInt32(); // emitter.TimedEmission = input.ReadBoolean(); // emitter.RelativeX = input.ReadSingle(); // emitter.RelativeY = input.ReadSingle(); // emitter.RelativeZ = input.ReadSingle(); // emitter.ParentVelocityChangesEmissionVelocity = input.ReadBoolean(); // input.ReadBoolean(); // AssetsRelativeToFile // emitter.SecondsLasting = input.ReadSingle(); //} //return existingInstance; }
public void LoadEmitters(string fileName) { #region Clear all Emitters in memory while (AppState.Self.Emitters.Count != 0) { SpriteManager.RemoveEmitter(AppState.Self.Emitters[0]); } AppState.Self.CurrentEmitter = null; #endregion #region Load the Emitters and add them to the SpriteManager EmitterSaveList emitterSaveList = EmitterSaveList.FromFile(fileName); AppState.Self.Emitters = emitterSaveList.ToEmitterList(AppState.Self.PermanentContentManager); foreach (Emitter emitter in AppState.Self.Emitters) { SpriteManager.AddEmitter(emitter); ShapeManager.AddPolygon(emitter.EmissionBoundary); } CurrentEmixFileName = FileManager.RemoveExtension(fileName); #endregion bool haveAttachments = false; #if FRB_MDX FlatRedBallServices.Owner.Text = "ParticleEditor - Currently editing " + CurrentEmixFileName; #else FlatRedBallServices.Game.Window.Title = "ParticleEditor - Currently editing " + CurrentEmixFileName; #endif for (int i = 0; i < AppState.Self.Emitters.Count; i++) { if (emitterSaveList.emitters[i].ParentSpriteName != null) { // see if the emitter exists in the gameData.emitterArray and set the attachments. If not, then // we need to set haveAttachments to true, indicating there are attachments to .scn Sprites Emitter e = AppState.Self.Emitters.FindWithNameContaining(emitterSaveList.emitters[i].ParentSpriteName); if (e != null) { AppState.Self.Emitters[i].AttachTo(e, false); } else { haveAttachments = true; } } } // TODO: Handle when the ParticleEditor can't find attachments. if (haveAttachments) { EditorData.lastLoadedFile = emitterSaveList; if (EditorData.Scene == null || EditorData.Scene.Sprites.Count == 0) { MultiButtonMessageBox mbmb = GuiManager.AddMultiButtonMessageBox(); mbmb.Name = ".emi attachments found"; mbmb.Text = fileName + " has one or more attachments. There are no " + "Sprites loaded. What would you like to do with the attachment information?"; mbmb.ScaleX = 15; mbmb.AddButton("Forget all attachment information.", new GuiMessage(FileMenuWindow.ForgetAttachmentInfo)); mbmb.AddButton("Remember attachment information, I will load a .scnx file later.", new GuiMessage(FileMenuWindow.RememberAttachmentInfo)); mbmb.AddButton("Manually search for .scnx file now.", new GuiMessage(FileMenuWindow.LoadScnxButtonClick)); mbmb.AddButton("Automatically search for .scnx with Sprites matching attachments.", new GuiMessage(FileMenuWindow.AutoSearchScn)); } else { FileMenuWindow.AttemptEmitterAttachment(""); } } string settingsFileName = FileManager.RemoveExtension(fileName) + ".ess"; bool doesSettingsFileExist = System.IO.File.Exists(settingsFileName); if (doesSettingsFileExist) { EmitterEditorSettingsSave settings = EmitterEditorSettingsSave.Load(settingsFileName); settings.Camera.SetCamera(Camera.Main); if (settings.Camera.OrthogonalHeight < 0) { Camera.Main.UsePixelCoordinates(); } else { Camera.Main.FixAspectRatioYConstant(); } } }