ScenePartition/Editor/ScenePartitionMenuEditor.cs

54 lines
2.5 KiB
C#
Raw Normal View History

using UnityEditor;
using UnityEngine;
namespace VertexColor.ScenePartition.Editor
{
public static class ScenePartitionMenuEditor
{
[MenuItem("GameObject/ScenePartition/CopyObjectId", false, 10000)]
public static void CopyObjectId(MenuCommand menuCommand)
{
// Get context from menu command instead of selection because the menu command is executed for each selected object when executed from the hierarchy.
if (menuCommand.context is not GameObject go) return;
if (go == null) return;
if (go.scene == null) return;
ulong id = ScenePartitionUtils.GetTargetObjectId(go);
EditorGUIUtility.systemCopyBuffer = id.ToString();
Debug.Log($"Copied object id '{id}' from '{go}' to clipboard");
}
[MenuItem("GameObject/ScenePartition/AddToAlwaysLoad", false, 10000)]
public static void AddToAlwaysLoad(MenuCommand menuCommand)
{
// Get context from menu command instead of selection because the menu command is executed for each selected object when executed from the hierarchy.
if (menuCommand.context is not GameObject go) return;
if (go == null) return;
if (go.scene == null) return;
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out var scenePartitionSO)) return;
ulong id = ScenePartitionUtils.GetTargetObjectId(go);
if (scenePartitionSO.alwaysLoadIds.Contains(id)) return;
scenePartitionSO.alwaysLoadIds.Add(id);
Debug.Log($"Added '{go}' ({id}) to '{scenePartitionSO.name}' ({scenePartitionSO.SceneName})");
}
[MenuItem("GameObject/ScenePartition/RemoveFromAlwaysLoad", false, 10000)]
public static void RemoveFromAlwaysLoad(MenuCommand menuCommand)
{
// Get context from menu command instead of selection because the menu command is executed for each selected object when executed from the hierarchy.
if (menuCommand.context is not GameObject go) return;
if (go == null) return;
if (go.scene == null) return;
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out var scenePartitionSO)) return;
ulong id = ScenePartitionUtils.GetTargetObjectId(go);
scenePartitionSO.alwaysLoadIds.Remove(id);
Debug.Log($"Removed '{go}' ({id}) from '{scenePartitionSO.name}' ({scenePartitionSO.SceneName})");
}
}
}