Skip to content

Instantly share code, notes, and snippets.

@dogfuntom
Last active April 20, 2017 00:43
Show Gist options
  • Save dogfuntom/dc0df6890cad47ec3429 to your computer and use it in GitHub Desktop.
Save dogfuntom/dc0df6890cad47ec3429 to your computer and use it in GitHub Desktop.
[uGUI Button context menu] Helps to avoid typing the same thing twice when using uGUI Buttons #Unity #Unity3d #uGUI
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
internal static class ContextMenuItems
{
[MenuItem("CONTEXT/Button/Copy name to Text")]
private static void CopyNameToText(MenuCommand menuCommand)
{
CopyImpl(menuCommand, true);
}
[MenuItem("CONTEXT/Button/Copy Text to name")]
private static void CopyTextToName(MenuCommand menuCommand)
{
CopyImpl(menuCommand, false);
}
private static void CopyImpl(MenuCommand menuCommand, bool downward)
{
var button = (Component)menuCommand.context;
var text = button.GetComponentInChildren<Text>();
if (downward)
text.text = button.name;
else
button.name = text.text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment