Skip to content

Instantly share code, notes, and snippets.

@JoseMiguelPizarro
Created August 31, 2019 13:12
Show Gist options
  • Save JoseMiguelPizarro/bdf354ebba9be29b2478d6555d2f42dc to your computer and use it in GitHub Desktop.
Save JoseMiguelPizarro/bdf354ebba9be29b2478d6555d2f42dc to your computer and use it in GitHub Desktop.
with resize tool
[CustomEditor(typeof(LevelMesh))]
public class LevelMeshEditor : Editor
{
private int toolBarWidth = 60;
private int selectedTool;
private GUIContent selectButton;
private GUIContent resizeButton;
private string selectButtonIconPath = "Assets/Resources/Icons/select.png";
private string resizeButtonIconPath = "Assets/Resources/Icons/resize.png";
private GUIContent[] toolsButton;
private void OnEnable()
{
Texture2D selectButtonIcon = AssetDatabase.LoadAssetAtPath<Texture2D>(selectButtonIconPath);
Texture2D resizeButtonicon = AssetDatabase.LoadAssetAtPath<Texture2D>(resizeButtonIconPath);
selectButton = new GUIContent(selectButtonIcon);
resizeButton = new GUIContent(resizeButtonicon);
toolsButton = new GUIContent[] { selectButton, resizeButton };
}
private void OnSceneGUI()
{
DrawToolBar(SceneView.lastActiveSceneView);
DoAction();
}
public void DrawToolBar(SceneView view)
{
Rect rect = new Rect(0, 0, toolBarWidth, view.position.height);
GUILayout.BeginArea(rect, EditorStyles.textArea);
selectedTool = GUILayout.SelectionGrid(selectedTool, toolsButton, 1, EditorStyles.toolbarButton, GUILayout.Width(50), GUILayout.Height(50));
GUILayout.EndArea();
}
private void DoAction()
{
switch (selectedTool)
{
case 0:
Select();
break;
case 1:
Resize();
break;
default:
break;
}
}
private void Select() { Debug.Log("I'm selecting something ;)"); }
private void Resize() { Debug.Log("I'm resizing something ;)"); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment