Make the puzzle chain editor work again
This commit is contained in:
@@ -27,18 +27,38 @@ public class PuzzleChainEditorWindow : EditorWindow
|
||||
private void LoadPuzzleSteps()
|
||||
{
|
||||
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)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var step = AssetDatabase.LoadAssetAtPath<PuzzleStepSO>(path);
|
||||
if (step != null)
|
||||
puzzleSteps.Add(step);
|
||||
// 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);
|
||||
if (step != null)
|
||||
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()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -51,9 +71,10 @@ public class PuzzleChainEditorWindow : EditorWindow
|
||||
return;
|
||||
}
|
||||
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
|
||||
var initialSteps = PuzzleGraphUtility.FindInitialSteps(dependencyGraph);
|
||||
var initialSteps = dependencyGraph != null ? PuzzleGraphUtility.FindInitialSteps(dependencyGraph) : new List<PuzzleStepSO>();
|
||||
foreach (var step in initialSteps)
|
||||
{
|
||||
if (step == null) continue; // Defensive
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
EditorGUILayout.LabelField($"Step Path: {step.displayName} ({step.stepId})", EditorStyles.largeLabel);
|
||||
GUILayout.Space(6);
|
||||
@@ -66,6 +87,10 @@ public class PuzzleChainEditorWindow : EditorWindow
|
||||
|
||||
private void DrawStepTree(PuzzleStepSO step, int indent)
|
||||
{
|
||||
if (step == null) {
|
||||
EditorGUILayout.LabelField("[Missing Step]", EditorStyles.boldLabel);
|
||||
return;
|
||||
}
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(indent * INDENT_SIZE);
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
@@ -74,15 +99,18 @@ public class PuzzleChainEditorWindow : EditorWindow
|
||||
GUILayout.Space(4);
|
||||
if (GUILayout.Button("Open in Inspector", GUILayout.Width(150)))
|
||||
{
|
||||
Selection.activeObject = step; // Opens in Inspector
|
||||
EditorGUIUtility.PingObject(step); // Highlights in Project
|
||||
Selection.activeObject = step;
|
||||
EditorGUIUtility.PingObject(step);
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUILayout.Space(6); // Spacer between steps
|
||||
foreach (var unlock in step.unlocks)
|
||||
GUILayout.Space(6);
|
||||
if (step.unlocks != null)
|
||||
{
|
||||
DrawStepTree(unlock, indent + 1);
|
||||
foreach (var unlock in step.unlocks)
|
||||
{
|
||||
DrawStepTree(unlock, indent + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user