fixed the encounter window

This commit is contained in:
Sebastian Bularca
2026-04-19 18:34:05 +02:00
parent ac9306154b
commit 2b48af8d3e
5 changed files with 398 additions and 54 deletions

View File

@@ -42,5 +42,34 @@ namespace Jovian.EncounterSystem {
return pool[UnityEngine.Random.Range(0, pool.Count)];
}
#if UNITY_EDITOR
// Unity's inspector "+" duplicates the previous list element, including nested internalId
// GUIDs. Regenerate any duplicates so every encounter carries a unique internalId.
private void OnValidate() {
if(encounters == null) {
return;
}
var seen = new HashSet<string>();
var changed = false;
foreach(var encounter in encounters) {
if(encounter?.EncounterDefinition == null) {
continue;
}
var id = encounter.EncounterDefinition.internalId;
if(string.IsNullOrEmpty(id) || !seen.Add(id)) {
encounter.EncounterDefinition.internalId = Guid.NewGuid().ToString();
seen.Add(encounter.EncounterDefinition.internalId);
changed = true;
}
}
if(changed) {
UnityEditor.EditorUtility.SetDirty(this);
}
}
#endif
}
}