ScenePartition/Editor/ScenePartitionToolbar.cs
2023-07-27 23:52:53 +02:00

84 lines
2.7 KiB
C#

using UnityEditor;
using UnityEditor.Overlays;
using UnityEditor.Toolbars;
using UnityEngine;
namespace VertexColor.ScenePartition.Editor
{
[Overlay(typeof(SceneView), "ScenePartition")]
public class ScenePartitionToolbar : ToolbarOverlay
{
private const string iconPath = "Packages/com.vertexcolor.scenepartition/Editor/Icons";
public ScenePartitionToolbar() : base(Load.Id, Save.Id, GenerateGrid.Id) { }
[EditorToolbarElement(Id, typeof(SceneView))]
public class Load : EditorToolbarButton, IAccessContainerWindow
{
public const string Id = "ScenePartition/Load";
public EditorWindow containerWindow { get; set; }
public Load()
{
text = "Load";
icon = AssetDatabase.LoadAssetAtPath<Texture2D>($"{iconPath}/Load.png");
tooltip = "Load the entire scene";
clicked += OnClick;
}
void OnClick()
{
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out ScenePartitionSO scenePartitionSO)) return;
scenePartitionSO.LoadAll();
}
}
[EditorToolbarElement(Id, typeof(SceneView))]
public class Save : EditorToolbarButton, IAccessContainerWindow
{
public const string Id = "ScenePartition/Save";
public EditorWindow containerWindow { get; set; }
public Save()
{
text = "Save";
icon = AssetDatabase.LoadAssetAtPath<Texture2D>($"{iconPath}/Save.png");
tooltip = "Save scene";
clicked += OnClick;
}
void OnClick()
{
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out ScenePartitionSO scenePartitionSO)) return;
scenePartitionSO.Save();
}
}
[EditorToolbarElement(Id, typeof(SceneView))]
public class GenerateGrid : EditorToolbarButton, IAccessContainerWindow
{
public const string Id = "ScenePartition/GenerateGrid";
public EditorWindow containerWindow { get; set; }
public GenerateGrid()
{
text = "GenerateGrid";
icon = AssetDatabase.LoadAssetAtPath<Texture2D>($"{iconPath}/GenerateGrid.png");
tooltip = "Generate scene grid";
clicked += OnClick;
}
void OnClick()
{
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out ScenePartitionSO scenePartitionSO)) return;
scenePartitionSO.GenerateSceneGridData();
}
}
}
}