generated from max/template-unity-project
Compare commits
2 Commits
41df190afb
...
8b44c33813
Author | SHA1 | Date | |
---|---|---|---|
8b44c33813 | |||
ddf71ef7d7 |
@ -16,5 +16,18 @@ public static void HorizontalLine(Color color)
|
||||
}
|
||||
|
||||
public static void HorizontalLine() => HorizontalLine(horizontalLineColor);
|
||||
|
||||
public class FoldoutHeaderScope : System.IDisposable
|
||||
{
|
||||
public FoldoutHeaderScope(string label, ref bool foldout)
|
||||
{
|
||||
foldout = EditorGUILayout.BeginFoldoutHeaderGroup(foldout, label);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,8 +9,9 @@ public class ScenePartitionEditorWindow : EditorWindow
|
||||
private const int cellSize = 10;
|
||||
|
||||
private Vector2 scrollPos = Vector2.zero;
|
||||
private bool foldoutGroupEnabled = false;
|
||||
|
||||
[MenuItem("Max/ScenePartitionWindow")]
|
||||
[MenuItem("Window/ScenePartition")]
|
||||
public static void ShowExample()
|
||||
{
|
||||
ScenePartitionEditorWindow window = GetWindow<ScenePartitionEditorWindow>();
|
||||
@ -41,58 +42,63 @@ private void OnGUI()
|
||||
|
||||
private void DrawSceneDataCache()
|
||||
{
|
||||
using (EditorGUILayout.ScrollViewScope scope = new EditorGUILayout.ScrollViewScope(scrollPos))
|
||||
using (EditorGUIUtils.FoldoutHeaderScope foldoutGroup = new EditorGUIUtils.FoldoutHeaderScope("SceneDataCache", ref foldoutGroupEnabled))
|
||||
{
|
||||
scrollPos = scope.scrollPosition;
|
||||
if (!foldoutGroupEnabled) return;
|
||||
|
||||
using (new EditorGUI.DisabledGroupScope(true))
|
||||
using (EditorGUILayout.ScrollViewScope scope = new EditorGUILayout.ScrollViewScope(scrollPos))
|
||||
{
|
||||
ScenePartitionSS scenePartitionSS = ScenePartitionSS.instance;
|
||||
scrollPos = scope.scrollPosition;
|
||||
|
||||
foreach (KeyValuePair<ScenePartitionSO, ScenePartitionData> sceneData in scenePartitionSS.SceneDataCache)
|
||||
using (new EditorGUI.DisabledGroupScope(true))
|
||||
{
|
||||
if (sceneData.Key == null || sceneData.Value == null) continue;
|
||||
ScenePartitionSS scenePartitionSS = ScenePartitionSS.instance;
|
||||
|
||||
EditorGUILayout.LabelField($"{sceneData.Key.name}");
|
||||
|
||||
if (sceneData.Value.HasCreatedPartitions)
|
||||
foreach (KeyValuePair<ScenePartitionSO, ScenePartitionData> sceneData in scenePartitionSS.SceneDataCache)
|
||||
{
|
||||
EditorGUILayout.LabelField($"scenePartitions");
|
||||
if (sceneData.Key == null || sceneData.Value == null) continue;
|
||||
|
||||
foreach (KeyValuePair<ulong, ScenePartition> scenePartition in sceneData.Value.ScenePartitions)
|
||||
EditorGUILayout.LabelField($"{sceneData.Key.name}");
|
||||
|
||||
if (sceneData.Value.HasCreatedPartitions)
|
||||
{
|
||||
EditorGUILayout.LongField((long)scenePartition.Key);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.LabelField($"scenePartitions");
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (sceneData.Value.HasLoadedPartitions)
|
||||
{
|
||||
EditorGUILayout.LabelField($"loadedScenePartitions");
|
||||
|
||||
foreach (KeyValuePair<ulong, ScenePartition> scenePartition in sceneData.Value.LoadedScenePartitions)
|
||||
{
|
||||
EditorGUILayout.LongField((long)scenePartition.Value.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (sceneData.Value.SceneGrid != null)
|
||||
{
|
||||
EditorGUILayout.LabelField($"generatedSceneGrid");
|
||||
|
||||
foreach (KeyValuePair<int, GridList> item in sceneData.Value.SceneGrid.Grid)
|
||||
{
|
||||
EditorGUILayout.IntField("gridId", item.Key);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
foreach (ulong id in item.Value.list)
|
||||
foreach (KeyValuePair<ulong, ScenePartition> scenePartition in sceneData.Value.ScenePartitions)
|
||||
{
|
||||
EditorGUILayout.LongField((long)id);
|
||||
EditorGUILayout.LongField((long)scenePartition.Key);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (sceneData.Value.HasLoadedPartitions)
|
||||
{
|
||||
EditorGUILayout.LabelField($"loadedScenePartitions");
|
||||
|
||||
foreach (KeyValuePair<ulong, ScenePartition> scenePartition in sceneData.Value.LoadedScenePartitions)
|
||||
{
|
||||
EditorGUILayout.LongField((long)scenePartition.Value.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (sceneData.Value.SceneGrid != null)
|
||||
{
|
||||
EditorGUILayout.LabelField($"generatedSceneGrid");
|
||||
|
||||
foreach (KeyValuePair<int, GridList> item in sceneData.Value.SceneGrid.Grid)
|
||||
{
|
||||
EditorGUILayout.IntField("gridId", item.Key);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
foreach (ulong id in item.Value.list)
|
||||
{
|
||||
EditorGUILayout.LongField((long)id);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
Editor/ScenePartitionMenuEditor.cs
Normal file
29
Editor/ScenePartitionMenuEditor.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VertexColor.ScenePartition.Editor
|
||||
{
|
||||
public static class ScenePartitionMenuEditor
|
||||
{
|
||||
[MenuItem("GameObject/CopyFileId", false, 10000)]
|
||||
public static void CreateTextArea5()
|
||||
{
|
||||
GameObject go = Selection.activeGameObject;
|
||||
|
||||
if (go == null) return;
|
||||
|
||||
GlobalObjectId id = GlobalObjectId.GetGlobalObjectIdSlow(go);
|
||||
|
||||
if (id.targetPrefabId == 0) // 0 = no prefab.
|
||||
{
|
||||
EditorGUIUtility.systemCopyBuffer = id.targetObjectId.ToString();
|
||||
Debug.Log($"object id: {id.targetObjectId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUIUtility.systemCopyBuffer = id.targetPrefabId.ToString();
|
||||
Debug.Log($"object id: {id.targetPrefabId}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Editor/ScenePartitionMenuEditor.cs.meta
Normal file
11
Editor/ScenePartitionMenuEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab63a69b46a3ff4438723520d0656c93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -281,11 +281,11 @@ public void GenerateSceneGridData()
|
||||
|
||||
if (ids[i].targetPrefabId == 0) // 0 = no prefab.
|
||||
{
|
||||
Data.SceneGrid.Insert(ids[i].targetObjectId, rootGameObjects[i].transform.position);
|
||||
Data.SceneGrid.Insert(ids[i].targetObjectId, rootGameObjects[i].transform.position, ScenePartitionSceneViewEditor.cellSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
Data.SceneGrid.Insert(ids[i].targetPrefabId, rootGameObjects[i].transform.position);
|
||||
Data.SceneGrid.Insert(ids[i].targetPrefabId, rootGameObjects[i].transform.position, ScenePartitionSceneViewEditor.cellSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ public class ScenePartitionSOEditor : UnityEditor.Editor
|
||||
{
|
||||
private ulong id = 0;
|
||||
private int gridId = 0;
|
||||
private bool foldoutGroupEnabled = false;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
@ -20,7 +21,7 @@ public override void OnInspectorGUI()
|
||||
//EditorGUILayout.PropertyField(sceneAssetProperty);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUIUtils.HorizontalLine();
|
||||
|
||||
if (scenePartitionSO.SceneAsset == null)
|
||||
{
|
||||
@ -31,72 +32,88 @@ public override void OnInspectorGUI()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Load All"))
|
||||
{
|
||||
scenePartitionSO.LoadAll();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Reload"))
|
||||
{
|
||||
scenePartitionSO.Reload();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Save"))
|
||||
{
|
||||
scenePartitionSO.Save();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Unload"))
|
||||
{
|
||||
scenePartitionSO.Unload();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (GUILayout.Button("Open Scene Data Folder"))
|
||||
{
|
||||
EditorUtility.RevealInFinder(ScenePartitionUtils.GetDataPath(scenePartitionSO));
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUIUtils.HorizontalLine();
|
||||
|
||||
id = (ulong)EditorGUILayout.LongField("id", (long)id);
|
||||
|
||||
if (GUILayout.Button("Load Section"))
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
scenePartitionSO.LoadPartitions(new ulong[1] { id });
|
||||
if (GUILayout.Button("Load All", EditorStyles.miniButtonLeft))
|
||||
{
|
||||
scenePartitionSO.LoadAll();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Unload", EditorStyles.miniButtonRight))
|
||||
{
|
||||
scenePartitionSO.Unload();
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Save", EditorStyles.miniButtonLeft))
|
||||
{
|
||||
scenePartitionSO.Save();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Reload", "Discard changes and reload"), EditorStyles.miniButtonRight))
|
||||
{
|
||||
scenePartitionSO.Reload();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUIUtils.HorizontalLine();
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
id = (ulong)EditorGUILayout.LongField("id", (long)id);
|
||||
|
||||
if (GUILayout.Button("Load Id"))
|
||||
{
|
||||
scenePartitionSO.LoadPartitions(new ulong[1] { id });
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUIUtils.HorizontalLine();
|
||||
|
||||
ScenePartitionSceneViewEditor.cellSize = EditorGUILayout.IntSlider("cellSize", ScenePartitionSceneViewEditor.cellSize, 10, 1000);
|
||||
|
||||
if (GUILayout.Button("GenerateSceneGrid"))
|
||||
{
|
||||
scenePartitionSO.GenerateSceneGridData();
|
||||
}
|
||||
|
||||
gridId = EditorGUILayout.IntField("gridId", gridId);
|
||||
|
||||
if (GUILayout.Button("LoadSceneGrid"))
|
||||
{
|
||||
scenePartitionSO.LoadCell(gridId);
|
||||
}
|
||||
|
||||
if (scenePartitionSO.Data.SceneGrid != null)
|
||||
{
|
||||
EditorGUILayout.LabelField($"generatedSceneGrid");
|
||||
gridId = EditorGUILayout.IntField("gridId", gridId);
|
||||
|
||||
scenePartitionSO.Data.SceneGrid.cellSize = EditorGUILayout.IntSlider("cellSize", scenePartitionSO.Data.SceneGrid.cellSize, 10, 1000);
|
||||
|
||||
foreach (KeyValuePair<int, GridList> item in scenePartitionSO.Data.SceneGrid.Grid)
|
||||
if (GUILayout.Button("LoadSceneGrid"))
|
||||
{
|
||||
EditorGUILayout.LongField("gridId", item.Key);
|
||||
scenePartitionSO.LoadCell(gridId);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
using (EditorGUIUtils.FoldoutHeaderScope foldoutGroup = new EditorGUIUtils.FoldoutHeaderScope("gridData", ref foldoutGroupEnabled))
|
||||
{
|
||||
if (!foldoutGroupEnabled) return;
|
||||
|
||||
foreach (ulong id in item.Value.list)
|
||||
EditorGUILayout.LabelField($"generatedSceneGrid");
|
||||
|
||||
foreach (KeyValuePair<int, GridList> item in scenePartitionSO.Data.SceneGrid.Grid)
|
||||
{
|
||||
EditorGUILayout.LongField((long)id);
|
||||
}
|
||||
EditorGUILayout.LongField("gridId", item.Key);
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
foreach (ulong id in item.Value.list)
|
||||
{
|
||||
EditorGUILayout.LongField((long)id);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ namespace VertexColor.ScenePartition.Editor
|
||||
[InitializeOnLoad]
|
||||
public class ScenePartitionSceneViewEditor : UnityEditor.Editor
|
||||
{
|
||||
public static int cellSize = 100;
|
||||
|
||||
private static ScenePartitionSO scenePartitionSO = null;
|
||||
|
||||
static ScenePartitionSceneViewEditor()
|
||||
@ -18,7 +20,6 @@ private static void HandleDuringSceneGui(SceneView sceneView)
|
||||
if (Event.current.modifiers != EventModifiers.Control) return;
|
||||
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out scenePartitionSO)) return;
|
||||
|
||||
int cellSize = scenePartitionSO.Data.SceneGrid.cellSize;
|
||||
Vector3 gridPosition = CalculateGridPosition(Event.current.mousePosition);
|
||||
int gridId = SceneGrid.CalculateGridPosition(gridPosition, cellSize);
|
||||
|
||||
|
@ -5,15 +5,12 @@ namespace VertexColor.ScenePartition
|
||||
[System.Serializable]
|
||||
public class SceneGrid
|
||||
{
|
||||
[SerializeField]
|
||||
public int cellSize = 10;
|
||||
|
||||
[SerializeField]
|
||||
private SceneGridDictionary grid = new SceneGridDictionary();
|
||||
|
||||
public SceneGridDictionary Grid => grid;
|
||||
|
||||
public void Insert(ulong scenePartitionId, Vector3 point)
|
||||
public void Insert(ulong scenePartitionId, Vector3 point, int cellSize)
|
||||
{
|
||||
int gridId = CalculateGridPosition(point, cellSize);
|
||||
if (grid.TryGetValue(gridId, out GridList ids))
|
||||
|
Loading…
Reference in New Issue
Block a user