Commit 1
This commit is contained in:
45
Assets/Editor/AddStickyNoteContextMenu.cs
Normal file
45
Assets/Editor/AddStickyNoteContextMenu.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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<StickyNote>() != null)
|
||||
{
|
||||
Debug.LogWarning($"StickyNote component already exists on '{selectedGameObject.name}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the StickyNote component
|
||||
StickyNote stickyNote = selectedGameObject.AddComponent<StickyNote>();
|
||||
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<StickyNote>() == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user