Make the puzzle chain editor work again
This commit is contained in:
@@ -27,18 +27,38 @@ public class PuzzleChainEditorWindow : EditorWindow
|
|||||||
private void LoadPuzzleSteps()
|
private void LoadPuzzleSteps()
|
||||||
{
|
{
|
||||||
puzzleSteps.Clear();
|
puzzleSteps.Clear();
|
||||||
string[] guids = AssetDatabase.FindAssets("t:PuzzleStepSO", new[] { "Assets/Data/Puzzles" });
|
// Find all PuzzleStepSO assets in the project
|
||||||
|
string[] guids = AssetDatabase.FindAssets("t:PuzzleStepSO");
|
||||||
foreach (var guid in guids)
|
foreach (var guid in guids)
|
||||||
{
|
{
|
||||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||||
|
// Only include those under Assets/Data/Puzzles (case-insensitive)
|
||||||
|
if (path.Replace('\\', '/').StartsWith("Assets/Data/Puzzles", System.StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
var step = AssetDatabase.LoadAssetAtPath<PuzzleStepSO>(path);
|
var step = AssetDatabase.LoadAssetAtPath<PuzzleStepSO>(path);
|
||||||
if (step != null)
|
if (step != null)
|
||||||
puzzleSteps.Add(step);
|
puzzleSteps.Add(step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Remove any nulls just in case
|
||||||
|
puzzleSteps.RemoveAll(s => s == null);
|
||||||
|
// Remove nulls from unlocks lists
|
||||||
|
foreach (var step in puzzleSteps)
|
||||||
|
{
|
||||||
|
if (step.unlocks != null)
|
||||||
|
step.unlocks.RemoveAll(u => u == null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ProcessPuzzleChains()
|
private void ProcessPuzzleChains()
|
||||||
{
|
{
|
||||||
|
// Defensive: ensure no nulls in puzzleSteps or unlocks
|
||||||
|
puzzleSteps.RemoveAll(s => s == null);
|
||||||
|
foreach (var step in puzzleSteps)
|
||||||
|
{
|
||||||
|
if (step.unlocks != null)
|
||||||
|
step.unlocks.RemoveAll(u => u == null);
|
||||||
|
}
|
||||||
dependencyGraph = PuzzleGraphUtility.BuildDependencyGraph(puzzleSteps);
|
dependencyGraph = PuzzleGraphUtility.BuildDependencyGraph(puzzleSteps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,9 +71,10 @@ public class PuzzleChainEditorWindow : EditorWindow
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
|
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
|
||||||
var initialSteps = PuzzleGraphUtility.FindInitialSteps(dependencyGraph);
|
var initialSteps = dependencyGraph != null ? PuzzleGraphUtility.FindInitialSteps(dependencyGraph) : new List<PuzzleStepSO>();
|
||||||
foreach (var step in initialSteps)
|
foreach (var step in initialSteps)
|
||||||
{
|
{
|
||||||
|
if (step == null) continue; // Defensive
|
||||||
EditorGUILayout.BeginVertical("box");
|
EditorGUILayout.BeginVertical("box");
|
||||||
EditorGUILayout.LabelField($"Step Path: {step.displayName} ({step.stepId})", EditorStyles.largeLabel);
|
EditorGUILayout.LabelField($"Step Path: {step.displayName} ({step.stepId})", EditorStyles.largeLabel);
|
||||||
GUILayout.Space(6);
|
GUILayout.Space(6);
|
||||||
@@ -66,6 +87,10 @@ public class PuzzleChainEditorWindow : EditorWindow
|
|||||||
|
|
||||||
private void DrawStepTree(PuzzleStepSO step, int indent)
|
private void DrawStepTree(PuzzleStepSO step, int indent)
|
||||||
{
|
{
|
||||||
|
if (step == null) {
|
||||||
|
EditorGUILayout.LabelField("[Missing Step]", EditorStyles.boldLabel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
GUILayout.Space(indent * INDENT_SIZE);
|
GUILayout.Space(indent * INDENT_SIZE);
|
||||||
EditorGUILayout.BeginVertical("box");
|
EditorGUILayout.BeginVertical("box");
|
||||||
@@ -74,15 +99,18 @@ public class PuzzleChainEditorWindow : EditorWindow
|
|||||||
GUILayout.Space(4);
|
GUILayout.Space(4);
|
||||||
if (GUILayout.Button("Open in Inspector", GUILayout.Width(150)))
|
if (GUILayout.Button("Open in Inspector", GUILayout.Width(150)))
|
||||||
{
|
{
|
||||||
Selection.activeObject = step; // Opens in Inspector
|
Selection.activeObject = step;
|
||||||
EditorGUIUtility.PingObject(step); // Highlights in Project
|
EditorGUIUtility.PingObject(step);
|
||||||
}
|
}
|
||||||
EditorGUILayout.EndVertical();
|
EditorGUILayout.EndVertical();
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
GUILayout.Space(6); // Spacer between steps
|
GUILayout.Space(6);
|
||||||
|
if (step.unlocks != null)
|
||||||
|
{
|
||||||
foreach (var unlock in step.unlocks)
|
foreach (var unlock in step.unlocks)
|
||||||
{
|
{
|
||||||
DrawStepTree(unlock, indent + 1);
|
DrawStepTree(unlock, indent + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user