I am currently working on an interface editor, where I want to generate some code upon copy-pasting, duplicating and deleting. I got the copy-paste and duplicate working like this:
Event e = Event.current;
if (e.commandName == "Paste" || e.commandName == "Duplicate")
{
pasted = true;
}
else if (e.commandName == "Delete")
{
GameObject selected = Selection.activeGameObject;
Screen screen = selected.GetComponentInParent<Screen>();
if (screen != null)
screen.RequestRegeneration();
}
The weird thing is. The “Delete” never occurs. Why isn’t the e.commandName == “Delete” when deleting a gameObject?
More code:
[InitializeOnLoad]
public class CopyPasteHandler : UnityEditor.EditorWindow
{
private static bool pasted = false;
/// <summary>
/// Assigns our needed delegates
/// </summary>
static CopyPasteHandler()
{
EditorApplication.hierarchyWindowItemOnGUI += OnGUI;
SceneView.onSceneGUIDelegate += OnSceneView;
}
Event e = Event.current;
if (e.commandName == "Paste" || e.commandName == "Duplicate")
{
pasted = true;
}
else if (e.commandName == "Delete")
{
GameObject selected = Selection.activeGameObject;
Screen screen = selected.GetComponentInParent<Screen>();
if (screen != null)
screen.RequestRegeneration();
}
}