// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System.IO; using FlaxEditor.GUI.ContextMenu; using FlaxEditor.SceneGraph.GUI; using FlaxEngine; namespace FlaxEditor.SceneGraph.Actors { /// /// Actor tree node for objects. /// /// [HideInEditor] public sealed class SceneNode : ActorNode { private bool _isEdited; /// /// Gets or sets a value indicating whether this scene is edited. /// public bool IsEdited { get => _isEdited; set { if (_isEdited != value) { _isEdited = value; _treeNode.UpdateText(); } } } /// /// Gets the scene. /// public Scene Scene => _actor as Scene; /// /// Initializes a new instance of the class. /// /// The scene. public SceneNode(Scene scene) : base(scene, new SceneTreeNode()) { } /// public override bool CanCreatePrefab => false; /// public override bool CanCopyPaste => false; /// public override bool CanDuplicate => false; /// public override bool CanDelete => false; /// public override bool CanDrag => false; /// public override SceneNode ParentScene => this; /// public override void OnContextMenu(ContextMenu contextMenu) { contextMenu.AddSeparator(); var path = Scene.Path; if (!string.IsNullOrEmpty(path) && File.Exists(path)) { var b = contextMenu.AddButton("Show in content window", OnSelect); b.Icon = Editor.Instance.Icons.Search12; b.TooltipText = "Finds and selects the scene asset int Content window."; } contextMenu.AddButton("Save scene", OnSave).LinkTooltip("Saves this scene.").Enabled = IsEdited && !Editor.IsPlayMode; contextMenu.AddButton("Unload scene", OnUnload).LinkTooltip("Unloads this scene.").Enabled = Editor.Instance.StateMachine.CurrentState.CanChangeScene; if (Level.ScenesCount > 1) contextMenu.AddButton("Unload all but this scene", OnUnloadAllButSelectedScene).LinkTooltip("Unloads all of the active scenes except for the selected scene.").Enabled = Editor.Instance.StateMachine.CurrentState.CanChangeScene; base.OnContextMenu(contextMenu); } private void OnSelect() { Editor.Instance.Windows.ContentWin.Select(Editor.Instance.ContentDatabase.Find(Scene.Path)); } private void OnSave() { Editor.Instance.Scene.SaveScene(this); } private void OnUnload() { Editor.Instance.Scene.CloseScene(Scene); } private void OnUnloadAllButSelectedScene() { Editor.Instance.Scene.CloseAllScenesExcept(Scene); } } }