fixed the encounter window
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user