diff --git a/package/Editor/SceneTools/SceneContextMenuActions/SceneContextMenuActions.cs b/package/Editor/SceneTools/SceneContextMenuActions/SceneContextMenuActions.cs index 0be8997..2a78bfa 100644 --- a/package/Editor/SceneTools/SceneContextMenuActions/SceneContextMenuActions.cs +++ b/package/Editor/SceneTools/SceneContextMenuActions/SceneContextMenuActions.cs @@ -5,6 +5,12 @@ namespace Scenario.Editor { + /// + /// This class provides custom context menu actions for the Unity editor's Scene view. + /// When a user right-clicks (with Ctrl key pressed) on a selected GameObject in the Scene view, + /// a context menu appears, offering various layer manipulation options such as moving, + /// cloning, deleting, flipping, and setting background images. + /// public class SceneContextMenuActions { [InitializeOnLoadMethod] @@ -13,6 +19,10 @@ private static void Initialize() SceneView.duringSceneGui += OnSceneGUI; } + /// + /// Handles the Scene GUI events. Detects right-click with Ctrl key pressed and shows the context menu if a GameObject is selected. + /// + /// The current SceneView. private static void OnSceneGUI(SceneView sceneView) { Event current = Event.current; @@ -27,6 +37,9 @@ private static void OnSceneGUI(SceneView sceneView) } } + /// + /// Displays the custom context menu with various layer manipulation options. + /// private static void ShowContextMenu() { GenericMenu menu = new GenericMenu(); @@ -44,6 +57,9 @@ private static void ShowContextMenu() menu.ShowAsContext(); } + /// + /// Moves the selected layer up in the hierarchy. + /// private static void MoveLayerUp() { GameObject selectedLayer = Selection.activeGameObject; @@ -51,13 +67,23 @@ private static void MoveLayerUp() selectedLayer.transform.SetSiblingIndex(siblingIndex + 1); } + /// + /// Moves the selected layer down in the hierarchy. + /// Ensures the new sibling index is within valid bounds to avoid errors. + /// private static void MoveLayerDown() { GameObject selectedLayer = Selection.activeGameObject; int siblingIndex = selectedLayer.transform.GetSiblingIndex(); - selectedLayer.transform.SetSiblingIndex(siblingIndex - 1); + if (siblingIndex > 0) + { + selectedLayer.transform.SetSiblingIndex(siblingIndex - 1); + } } + /// + /// Clones the selected layer. + /// private static void CloneLayer() { GameObject selectedLayer = Selection.activeGameObject; @@ -65,12 +91,18 @@ private static void CloneLayer() clonedLayer.name = selectedLayer.name + " (Clone)"; } + /// + /// Deletes the selected layer. + /// private static void DeleteLayer() { GameObject selectedLayer = Selection.activeGameObject; UnityEngine.Object.DestroyImmediate(selectedLayer); } + /// + /// Flips the selected layer horizontally. + /// private static void FlipHorizontal() { GameObject selectedLayer = Selection.activeGameObject; @@ -81,6 +113,9 @@ private static void FlipHorizontal() } } + /// + /// Flips the selected layer vertically. + /// private static void FlipVertical() { GameObject selectedLayer = Selection.activeGameObject; @@ -91,6 +126,9 @@ private static void FlipVertical() } } + /// + /// Removes the background of the selected layer's sprite by sending it to an external API. + /// private static void RemoveBackground() { GameObject selectedLayer = Selection.activeGameObject; @@ -132,6 +170,9 @@ private static void RemoveBackground() } } + /// + /// Sets the selected layer as the background by moving it to the first position in the hierarchy. + /// private static void SetAsBackground() { GameObject selectedLayer = Selection.activeGameObject;