Skip to content

Instantly share code, notes, and snippets.

@karl-zylinski
Created October 12, 2022 12:57
Show Gist options
  • Save karl-zylinski/b9061bc5da0f747f3e717c571077d8e8 to your computer and use it in GitHub Desktop.
Save karl-zylinski/b9061bc5da0f747f3e717c571077d8e8 to your computer and use it in GitHub Desktop.
[EditorTool("Tile Placer Tool", typeof(TileData))]
class TilePlacerTool : EditorTool
{
private GUIContent m_iconContent;
void OnEnable()
{
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Textures/Editor/TileEditorIcon.png");
// Icon for tools toolbar
m_iconContent = new GUIContent()
{
image = icon,
text = "Tile Placer",
tooltip = "Tile Placer"
};
}
public override GUIContent toolbarIcon
{
get { return m_iconContent; }
}
public override void OnActivated()
{
base.OnActivated();
SceneView.duringSceneGui += OnSceneGUI;
}
public override void OnWillBeDeactivated()
{
base.OnWillBeDeactivated();
SceneView.duringSceneGui -= OnSceneGUI;
}
[Shortcut("Activate Tile Placer Tool", typeof(SceneView), KeyCode.P)]
static void TilePlacerToolShortcut()
{
ToolManager.SetActiveTool<TilePlacerTool>();
}
private void OnSceneGUI(SceneView sceneView)
{
// Draw in Scene View
}
}
[Overlay(typeof(SceneView), "Tile Placer Overlay")]
public class TilePlacerToolOverlay : IMGUIOverlay, ITransientOverlay
{
public bool visible
{
get
{
return ToolManager.activeToolType == typeof(TilePlacerTool);
}
}
public override void OnGUI()
{
// Draw overlay that is only visible when the TilePlacerTool is active.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment