ScenePartition/Editor/ScenePartitionToolbar.cs

130 lines
4.2 KiB
C#
Raw Permalink Normal View History

2023-07-27 23:52:53 +02:00
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";
2023-07-28 18:07:39 +02:00
public ScenePartitionToolbar() : base(Load.Id, Save.Id, Reload.Id, Unload.Id, GenerateGrid.Id) { }
2023-07-27 23:52:53 +02:00
[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();
}
}
2023-07-28 18:07:39 +02:00
[EditorToolbarElement(Id, typeof(SceneView))]
public class Reload : EditorToolbarButton, IAccessContainerWindow
{
public const string Id = "ScenePartition/Reload";
public EditorWindow containerWindow { get; set; }
public Reload()
{
text = "Reload";
icon = AssetDatabase.LoadAssetAtPath<Texture2D>($"{iconPath}/Reload.png");
tooltip = "Discard changes and reload scene";
clicked += OnClick;
}
void OnClick()
{
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out ScenePartitionSO scenePartitionSO)) return;
scenePartitionSO.Reload();
}
}
[EditorToolbarElement(Id, typeof(SceneView))]
public class Unload : EditorToolbarButton, IAccessContainerWindow
{
public const string Id = "ScenePartition/Unload";
public EditorWindow containerWindow { get; set; }
public Unload()
{
text = "Unload";
icon = AssetDatabase.LoadAssetAtPath<Texture2D>($"{iconPath}/Unload.png");
tooltip = "Unload the scene";
clicked += OnClick;
}
void OnClick()
{
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out ScenePartitionSO scenePartitionSO)) return;
scenePartitionSO.Unload();
}
}
2023-07-27 23:52:53 +02:00
[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();
}
}
}
}