private void DoRemove() { // Remove script (it could be removed by sth else, just check it) if (_script) { if (_script.Actor) { Editor.Instance.Scene.MarkSceneEdited(_script.Scene); } Object.Destroy(ref _script); } }
private void DestroyMesh() { if (_segmentActor) { Object.Destroy(_segmentActor); _segmentActor = null; } if (_chunkMesh) { Object.Destroy(_chunkMesh); _chunkMesh = null; } }
private void CancelRendering() { if (!_isRendering) { return; } var editor = Editor.Instance; // End rendering Editor.Log("Ending scene animation rendering"); FlaxEngine.Scripting.Update -= Tick; Time.SetFixedDeltaTime(false, 0.0f); Time.GamePaused = _wasGamePaused; if (_player) { _player.Stop(); _player.Parent = null; Object.Destroy(ref _player); } _window.Editor.StateMachine.CurrentState.UpdateFPS(); for (int i = 0; i < _stagingTextures.Length; i++) { _stagingTextures[i].Texture.ReleaseGPU(); Object.Destroy(ref _stagingTextures[i].Texture); } if (_progress != null) { _progress.End(); editor.ProgressReporting.UnregisterHandler(_progress); } if (_editorState != null) { editor.StateMachine.GoToState(editor.StateMachine.EditingSceneState); editor.StateMachine.RemoveState(_editorState); } // Update UI var gameWin = editor.Windows.GameWin; gameWin.Viewport.CustomResolution = null; gameWin.Viewport.BackgroundColor = Color.Transparent; gameWin.Viewport.KeepAspectRatio = false; gameWin.Viewport.Task.PostRender -= OnPostRender; _gameWindow = null; _isRendering = false; _presenter.Panel.Enabled = true; _presenter.BuildLayoutOnUpdate(); }
public void SetModel(SkinnedModel model) { PreviewActor.SkinnedModel = model; PreviewActor.AnimationGraph = null; Object.Destroy(ref _animGraph); if (!model) { return; } // Use virtual animation graph to playback the animation _animGraph = FlaxEngine.Content.CreateVirtualAsset <AnimationGraph>(); _animGraph.InitAsAnimation(model, _window.Asset); PreviewActor.AnimationGraph = _animGraph; }
/// <summary> /// Creates the new scene file. The default scene contains set of simple actors. /// </summary> /// <param name="path">The path.</param> public void CreateSceneFile(string path) { // Create a sample scene var scene = Scene.New(); var sky = Sky.New(); var sun = DirectionalLight.New(); var floor = ModelActor.New(); // scene.AddChild(sky); scene.AddChild(sun); scene.AddChild(floor); // sky.Name = "Sky"; sky.LocalPosition = new Vector3(40, 150, 0); sky.SunLight = sun; sky.StaticFlags = StaticFlags.FullyStatic; // sun.Name = "Sun"; sun.LocalPosition = new Vector3(40, 160, 0); sun.LocalEulerAngles = new Vector3(45, 0, 0); sun.StaticFlags = StaticFlags.FullyStatic; // floor.Name = "Floor"; floor.Scale = new Vector3(4, 0.5f, 4); floor.Model = FlaxEngine.Content.LoadAsync <Model>(StringUtils.CombinePaths(Globals.EditorFolder, "Primitives/Cube.flax")); if (floor.Model) { floor.Model.WaitForLoaded(); floor.Entries[0].Material = FlaxEngine.Content.LoadAsync <MaterialBase>(StringUtils.CombinePaths(Globals.EngineFolder, "WhiteMaterial.flax")); } floor.StaticFlags = StaticFlags.FullyStatic; // Serialize var bytes = SceneManager.SaveSceneToBytes(scene); // Cleanup Object.Destroy(scene); if (bytes == null || bytes.Length == 0) { throw new Exception("Failed to serialize scene."); } // Write to file using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) fileStream.Write(bytes, 0, bytes.Length); }
/// <inheritdoc /> public override void Create(string outputPath, object arg) { var actor = arg as Actor; if (actor == null) { // Create default prefab root object actor = EmptyActor.New(); actor.Name = "Root"; // Cleanup it after usage Object.Destroy(actor, 20.0f); } Editor.CreatePrefab(outputPath, actor, true); }
private void DoRemove() { // Remove script (it could be removed by sth else, just check it) var script = Object.Find <Script>(ref _scriptId); if (!script) { Editor.LogWarning("Missing script."); return; } if (script.Actor) { Editor.Instance.Scene.MarkSceneEdited(script.Scene); } Object.Destroy(ref script); }
/// <inheritdoc /> public override void Create(string outputPath, object arg) { if (!(arg is Actor actor)) { // Create default prefab root object actor = new EmptyActor { Name = "Root" }; // Cleanup it after usage Object.Destroy(actor, 20.0f); } PrefabManager.CreatePrefab(actor, outputPath, true); }
/// <summary> /// Releases object resources. /// </summary> public void Dispose() { FlaxEngine.Scripting.Update -= OnUpdate; _queue.Clear(); _queue = null; Object.Destroy(ref _task); Object.Destroy(ref _output); if (_atlases != null) { foreach (var atlas in _atlases) { Object.Destroy(atlas.Texture); } _atlases.Clear(); _atlases = null; } }
private void OnClickMissingRemove(ContextMenuButton button) { var index = (int)button.ParentContextMenu.Tag; // TODO: support undo var actors = ParentEditor.Values; for (int i = 0; i < actors.Count; i++) { var actor = (Actor)actors[i]; var script = actor.GetScript(index); if (script) { script.Parent = null; Object.Destroy(script); } Editor.Instance.Scene.MarkSceneEdited(actor.Scene); } }
/// <inheritdoc /> public override void OnExit() { _task?.Dispose(); lock (_requests) { // Clear data while (_requests.Count > 0) { RemoveRequest(_requests[0]); } _cache.Clear(); } _guiRoot.Dispose(); Object.Destroy(ref _task); Object.Destroy(ref _output); }
/// <inheritdoc /> public override void OnExit() { if (_task != null) { _task.Enabled = false; } lock (_requests) { // Clear data while (_requests.Count > 0) { RemoveRequest(_requests[0]); } _cache.Clear(); } _guiRoot.Dispose(); _task?.Dispose(); Object.Destroy(ref _output); }
public override void Deinitialize() { Editor.UI.StatusBar.SizeChanged -= ResizeLabel; Editor.Undo.ActionDone -= OnActionDone; Scripting.Update -= SendPlayerPosition; Editor.StateMachine.StateChanged -= FlaxEditorStateChanged; var editorRenderTask = Editor.Instance?.Windows?.EditWin?.Viewport?.RenderTask; if (editorRenderTask != null) { editorRenderTask.CollectDrawCalls -= DrawUsers; } Object.Destroy(ref CameraModel); Object.Destroy(ref CameraMaterial); Session?.Close(); Session = null; _collaborateButton.Dispose(); _labelConnected.Dispose(); base.Deinitialize(); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { Profiler.BeginEvent("LocalizationSettingsEditor.Initialize"); var settings = (LocalizationSettings)Values[0]; var tablesLength = settings.LocalizedStringTables?.Length ?? 0; var tables = new List <LocalizedStringTable>(tablesLength); for (int i = 0; i < tablesLength; i++) { var table = settings.LocalizedStringTables[i]; if (table && !table.WaitForLoaded()) { tables.Add(table); } } var locales = tables.GroupBy(x => x.Locale); var tableEntries = new Dictionary <LocalizedStringTable, Dictionary <string, string[]> >(); var allKeys = new HashSet <string>(); foreach (var e in locales) { foreach (var table in e) { var entries = table.Entries; tableEntries[table] = entries; allKeys.AddRange(entries.Keys); } } { var group = layout.Group("Preview"); // Current language and culture preview management group.Object("Current Language", new CustomValueContainer(new ScriptType(typeof(CultureInfo)), Localization.CurrentLanguage, (instance, index) => Localization.CurrentLanguage, (instance, index, value) => Localization.CurrentLanguage = value as CultureInfo), null, "Current UI display language for the game preview."); group.Object("Current Culture", new CustomValueContainer(new ScriptType(typeof(CultureInfo)), Localization.CurrentCulture, (instance, index) => Localization.CurrentCulture, (instance, index, value) => Localization.CurrentCulture = value as CultureInfo), null, "Current values formatting culture for the game preview."); } { var group = layout.Group("Locales"); // Show all existing locales _theMostTranslatedCulture = null; _theMostTranslatedCultureCount = -1; foreach (var e in locales) { var culture = new CultureInfo(e.Key); var prop = group.AddPropertyItem(CultureInfoEditor.GetName(culture), culture.NativeName); int count = e.Sum(x => tableEntries[x].Count); int validCount = e.Sum(x => tableEntries[x].Values.Count(y => y != null && y.Length != 0 && !string.IsNullOrEmpty(y[0]))); if (count > _theMostTranslatedCultureCount) { _theMostTranslatedCulture = culture; _theMostTranslatedCultureCount = count; } prop.Label(string.Format("Progress: {0}% ({1}/{2})", allKeys.Count > 0 ? (int)(((float)validCount / allKeys.Count * 100.0f)) : 0, validCount, allKeys.Count)); prop.Label("Tables:"); foreach (var table in e) { var namePath = table.Path; if (namePath.StartsWith(Globals.ProjectFolder)) { namePath = namePath.Substring(Globals.ProjectFolder.Length + 1); } var tableLabel = prop.ClickableLabel(namePath).CustomControl; tableLabel.TextColorHighlighted = Color.Wheat; tableLabel.DoubleClick += delegate { Editor.Instance.Windows.ContentWin.Select(table); }; } group.Space(10); } // Update add button var update = group.Button("Update").Button; update.TooltipText = "Refreshes the dashboard statistics"; update.Height = 16.0f; update.Clicked += RebuildLayout; // New locale add button var addLocale = group.Button("Add Locale...").Button; addLocale.TooltipText = "Shows a locale picker and creates new localization for it with not translated string tables"; addLocale.Height = 16.0f; addLocale.ButtonClicked += delegate(Button button) { var menu = CultureInfoEditor.CreatePicker(null, culture => { var displayName = CultureInfoEditor.GetName(culture); if (locales.Any(x => x.Key == culture.Name)) { MessageBox.Show($"Culture '{displayName}' is already added."); return; } Profiler.BeginEvent("LocalizationSettingsEditor.AddLocale"); Editor.Log($"Adding culture '{displayName}' to localization settings"); var newTables = settings.LocalizedStringTables?.ToList() ?? new List <LocalizedStringTable>(); if (_theMostTranslatedCulture != null) { // Duplicate localization for culture with the highest amount of keys var g = locales.First(x => x.Key == _theMostTranslatedCulture.Name); foreach (var e in g) { var path = e.Path; var filename = Path.GetFileNameWithoutExtension(path); if (filename.EndsWith(_theMostTranslatedCulture.Name)) { filename = filename.Substring(0, filename.Length - _theMostTranslatedCulture.Name.Length); } path = Path.Combine(Path.GetDirectoryName(path), filename + culture.Name + ".json"); var table = FlaxEngine.Content.CreateVirtualAsset <LocalizedStringTable>(); table.Locale = culture.Name; var entries = new Dictionary <string, string[]>(); foreach (var ee in tableEntries[e]) { var vv = (string[])ee.Value.Clone(); for (var i = 0; i < vv.Length; i++) { vv[i] = string.Empty; } entries.Add(ee.Key, vv); } table.Entries = entries; if (!table.Save(path)) { Object.Destroy(table); newTables.Add(FlaxEngine.Content.LoadAsync <LocalizedStringTable>(path)); } } } else { // No localization so initialize with empty table var path = Path.Combine(Path.Combine(Path.GetDirectoryName(GameSettings.Load().Localization.Path), "Localization", culture.Name + ".json")); var table = FlaxEngine.Content.CreateVirtualAsset <LocalizedStringTable>(); table.Locale = culture.Name; if (!table.Save(path)) { Object.Destroy(table); newTables.Add(FlaxEngine.Content.LoadAsync <LocalizedStringTable>(path)); } } settings.LocalizedStringTables = newTables.ToArray(); Presenter.OnModified(); RebuildLayout(); Profiler.EndEvent(); }); menu.Show(button, new Vector2(0, button.Height)); }; // Export button var exportLocalization = group.Button("Export...").Button; exportLocalization.TooltipText = "Exports the localization strings into .pot file for translation"; exportLocalization.Height = 16.0f; exportLocalization.Clicked += () => Export(tableEntries, allKeys); // Find localized strings in code button var findStringsCode = group.Button("Find localized strings in code").Button; findStringsCode.TooltipText = "Searches for localized string usage in inside a project source files"; findStringsCode.Height = 16.0f; findStringsCode.Clicked += delegate { var newKeys = new Dictionary <string, string>(); Profiler.BeginEvent("LocalizationSettingsEditor.FindLocalizedStringsInSource"); // C# var files = Directory.GetFiles(Globals.ProjectSourceFolder, "*.cs", SearchOption.AllDirectories); var filesCount = files.Length; foreach (var file in files) { FindNewKeysCSharp(file, newKeys, allKeys); } // C++ files = Directory.GetFiles(Globals.ProjectSourceFolder, "*.cpp", SearchOption.AllDirectories); filesCount += files.Length; foreach (var file in files) { FindNewKeysCpp(file, newKeys, allKeys); } files = Directory.GetFiles(Globals.ProjectSourceFolder, "*.h", SearchOption.AllDirectories); filesCount += files.Length; foreach (var file in files) { FindNewKeysCpp(file, newKeys, allKeys); } AddNewKeys(newKeys, filesCount, locales, tableEntries); Profiler.EndEvent(); }; // Find localized strings in content button var findStringsContent = group.Button("Find localized strings in content").Button; findStringsContent.TooltipText = "Searches for localized string usage in inside a project content files (scenes, prefabs)"; findStringsContent.Height = 16.0f; findStringsContent.Clicked += delegate { var newKeys = new Dictionary <string, string>(); Profiler.BeginEvent("LocalizationSettingsEditor.FindLocalizedStringsInContent"); // Scenes var files = Directory.GetFiles(Globals.ProjectContentFolder, "*.scene", SearchOption.AllDirectories); var filesCount = files.Length; foreach (var file in files) { FindNewKeysJson(file, newKeys, allKeys); } // Prefabs files = Directory.GetFiles(Globals.ProjectContentFolder, "*.prefab", SearchOption.AllDirectories); filesCount += files.Length; foreach (var file in files) { FindNewKeysJson(file, newKeys, allKeys); } AddNewKeys(newKeys, filesCount, locales, tableEntries); Profiler.EndEvent(); }; } { // Raw asset data editing var group = layout.Group("Data"); base.Initialize(group); } Profiler.EndEvent(); }
private void DoRemove() { // Remove script Editor.Instance.Scene.MarkSceneEdited(_script.Actor.Scene); Object.Destroy(ref _script); }
/// <summary> /// Creates the new scene file. The default scene contains set of simple actors. /// </summary> /// <param name="path">The path.</param> public void CreateSceneFile(string path) { // Create a sample scene var scene = new Scene { StaticFlags = StaticFlags.FullyStatic }; // var sun = scene.AddChild <DirectionalLight>(); sun.Name = "Sun"; sun.LocalPosition = new Vector3(40, 160, 0); sun.LocalEulerAngles = new Vector3(45, 0, 0); sun.StaticFlags = StaticFlags.FullyStatic; // var sky = scene.AddChild <Sky>(); sky.Name = "Sky"; sky.LocalPosition = new Vector3(40, 150, 0); sky.SunLight = sun; sky.StaticFlags = StaticFlags.FullyStatic; // var skyLight = scene.AddChild <SkyLight>(); skyLight.Mode = SkyLight.Modes.CustomTexture; skyLight.Brightness = 2.5f; skyLight.CustomTexture = FlaxEngine.Content.LoadAsyncInternal <CubeTexture>(EditorAssets.DefaultSkyCubeTexture); skyLight.StaticFlags = StaticFlags.FullyStatic; // var floor = scene.AddChild <StaticModel>(); floor.Name = "Floor"; floor.Scale = new Vector3(4, 0.5f, 4); floor.Model = FlaxEngine.Content.LoadAsync <Model>(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Primitives/Cube.flax")); if (floor.Model) { floor.Model.WaitForLoaded(); floor.SetMaterial(0, FlaxEngine.Content.LoadAsync <MaterialBase>(StringUtils.CombinePaths(Globals.EngineContentFolder, "Engine/WhiteMaterial.flax"))); } floor.StaticFlags = StaticFlags.FullyStatic; // var cam = scene.AddChild <Camera>(); cam.Name = "Camera"; cam.Position = new Vector3(0, 150, -300); // Serialize var bytes = Level.SaveSceneToBytes(scene); // Cleanup Object.Destroy(ref scene); if (bytes == null || bytes.Length == 0) { throw new Exception("Failed to serialize scene."); } // Write to file using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) fileStream.Write(bytes, 0, bytes.Length); }
public void Close() { Editor.Instance.Windows.EditWin.Viewport.Task.CustomPostFx.Remove(_customOutliner); Object.Destroy(Material); }
/// <inheritdoc /> public override void OnDestroy() { Object.Destroy(ref _animGraph); base.OnDestroy(); }