protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { UnrealScienceScripting.Cleanup(); base.OnClosing(e); }
private void MenuItem_Click(object sender, RoutedEventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "Unreal Science Scene files (*.usscene)|*.usscene"; d.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString(); if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK && d.FileName.Length > 0) { if (System.Windows.MessageBox.Show("Do you want to save the scene?", "Save?", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { SaveFileDialog save = new SaveFileDialog(); save.Filter = "Unreal Science Scene files (*.usscene)|*.usscene"; save.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString(); if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK && save.FileName.Length > 0) { SaveSceneTo(save.FileName); } } SavedFilename = d.FileName; UnrealScienceScripting.Cleanup(); UnrealScienceScripting.CleanUI(); UnrealScienceScripting.World.Entities.Clear(); Hierarchy.Items.Clear(); Read r = new Read(); Scripting.isPlaying = false; r.Deserialize(d.FileName); #region entities foreach (SceneEntity s in r.Scene.Entities) { Scripting.ScriptingManager.Parse(s.CreationCommand); Scripting.ScriptingManager.Parse(String.Format("move {0} {1} {2}", s.Transform.Position.X, s.Transform.Position.Y, s.Transform.Position.Z)); Scripting.ScriptingManager.Parse(String.Format("rotate {0} {1} {2}", s.Transform.Rotation.X, s.Transform.Rotation.Y, s.Transform.Rotation.Z)); Scripting.ScriptingManager.Parse(String.Format("scale {0} {1} {2}", s.Transform.Scale.X, s.Transform.Scale.Y, s.Transform.Scale.Z)); Scripting.ScriptingManager.Parse("setTexture " + s.Texture); Scripting.ScriptingManager.Parse(String.Format("setColor {0} {1} {2}", s.Color.X, s.Color.Y, s.Color.Z)); if (s.Animation.AnimationKeys.Count != 0) { foreach (AnimationKey key in s.Animation.AnimationKeys) { Vector3D v = new Vector3D(); if (key.KeyType == 1) { v = key.Destination.Position; } else if (key.KeyType == 2) { v = key.Destination.Rotation; } else if (key.KeyType == 3) { v = key.Destination.Scale; } string type = ""; if (key.KeyType == 1) { type = "position"; } else if (key.KeyType == 2) { type = "rotation"; } else if (key.KeyType == 3) { type = "scale"; } Scripting.AnimationManager.Parse(String.Format("setKey {0} {1} {2} {3} {4} {5}", type, key.StartOrder, key.Duration, v.X, v.Y, v.Z)); } } } #endregion #region create_UI foreach (UnrealScienceLibrary.UIElement element in r.Scene.Elements) { if (element is Text2D) { //Scripting.ScriptingManager.Parse("addText {0} {1} {2} {3} {4} {5}", // (element as Text2D).Text, ); Text2D t = element as Text2D; UnrealScienceScripting.AddText2D(t.Text, t.FontName, (int)t.Position.X, (int)t.Position.Y, (int)t.Scale.X, (int)t.Scale.Y, (int)t.FontSize); } } #endregion } }