using UnityEditor; using UnityEngine; namespace Editor { public static class AddStickyNoteContextMenu { [MenuItem("GameObject/Add Sticky Note", false, 10)] // Menu item at top, with priority 10 private static void AddStickyNote(MenuCommand menuCommand) { // Ensure a GameObject is selected if (Selection.activeGameObject == null) { Debug.LogWarning("No GameObject selected to add Sticky Note."); return; } GameObject selectedGameObject = Selection.activeGameObject; // Check if StickyNote component already exists if (selectedGameObject.GetComponent() != null) { Debug.LogWarning($"StickyNote component already exists on '{selectedGameObject.name}'."); return; } // Add the StickyNote component StickyNote stickyNote = selectedGameObject.AddComponent(); Undo.RegisterCreatedObjectUndo(stickyNote, "Add Sticky Note"); Debug.Log($"StickyNote added to '{selectedGameObject.name}'."); } // Validate the menu item. // It will only be enabled if a GameObject is selected and it doesn't already have a StickyNote component. [MenuItem("GameObject/Add Sticky Note", true)] private static bool ValidateAddStickyNote() { if (Selection.activeGameObject == null) { return false; } return Selection.activeGameObject.GetComponent() == null; } } }