2023-07-09 23:00:23 +02:00
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace VertexColor.ScenePartition.Editor
|
|
|
|
{
|
|
|
|
public static class ScenePartitionMenuEditor
|
|
|
|
{
|
2023-07-27 18:23:03 +02:00
|
|
|
[MenuItem("GameObject/ScenePartition/CopyObjectId", false, 10000)]
|
|
|
|
public static void CopyObjectId(MenuCommand menuCommand)
|
2023-07-09 23:00:23 +02:00
|
|
|
{
|
2023-07-27 18:23:03 +02:00
|
|
|
// 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");
|
|
|
|
}
|
2023-07-09 23:00:23 +02:00
|
|
|
|
2023-07-27 18:23:03 +02:00
|
|
|
[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;
|
2023-07-09 23:00:23 +02:00
|
|
|
if (go == null) return;
|
2023-07-27 18:23:03 +02:00
|
|
|
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);
|
2023-07-09 23:00:23 +02:00
|
|
|
|
2023-07-27 18:23:03 +02:00
|
|
|
scenePartitionSO.alwaysLoadIds.Remove(id);
|
|
|
|
Debug.Log($"Removed '{go}' ({id}) from '{scenePartitionSO.name}' ({scenePartitionSO.SceneName})");
|
2023-07-09 23:00:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|