diff --git a/Runtime/Conversation.cs b/Runtime/Conversation.cs index 6fb4c79..c4c8e81 100644 --- a/Runtime/Conversation.cs +++ b/Runtime/Conversation.cs @@ -32,10 +32,17 @@ public class Conversation : MonoBehaviour public static readonly Dictionary Conversations = new(); private static readonly Dictionary Variables = new(); private static Delegates.Subscriber _subscriber; + private List> _aoHandles; public static void AddSpeaker(TopiSpeaker speaker) => Speakers[speaker.name] = speaker; public static void RemoveSpeaker(TopiSpeaker speaker) => Speakers.Remove(speaker.name); public static readonly State State = new(); + + private void Awake() + { + _aoHandles = new List>(); + } + private IEnumerator Start() { if (file == null) @@ -185,6 +192,7 @@ public static void ValueChanged(string name, ref TopiValue value) private IEnumerator LoadAddressableTopiValues() { + while (Dialogue?.Library == null) yield return null; var ao = Addressables.LoadResourceLocationsAsync(new List {"Topiary", "Evt"}, Addressables.MergeMode.Intersection); yield return ao; @@ -195,29 +203,46 @@ private IEnumerator LoadAddressableTopiValues() if (!_data.ExternsSet.Contains(key)) continue; var aoEvt = Addressables.LoadAssetAsync(key); yield return aoEvt; - - var topiName = aoEvt.Result switch + + string topiName = null; + switch (aoEvt.Result) { - EvtTopiBool b => b.Name, - EvtTopiFloat f => f.Name, - EvtTopiInt i => i.Name, - EvtTopiString s => s.Name, - _ => null - }; + case EvtTopiBool b: + topiName = b.Name; + Dialogue.Set(topiName, b.Value); + break; + case EvtTopiFloat f: + topiName = f.Name; + Dialogue.Set(topiName, f.Value); + break; + case EvtTopiInt i: + topiName = i.Name; + Dialogue.Set(topiName, i.Value); + break; + case EvtTopiString s: + topiName = s.Name; + Dialogue.Set(topiName, s.Value); + break; + } + if (topiName == null) { Addressables.Release(aoEvt); continue; } + Variables[topiName] = aoEvt.Result; + Dialogue.Subscribe(topiName); + _aoHandles.Add(aoEvt); } } private void UnloadAddressableTopiValues() { - foreach (var kvp in Variables) + foreach (var kvp in Variables) Dialogue.Unsubscribe(kvp.Key); + foreach (var handle in _aoHandles) { - Addressables.Release(kvp.Value); + if (handle.IsValid()) Addressables.Release(handle); } } } diff --git a/Topiary.CSharp.dll b/Topiary.CSharp.dll index d640743..51f3e86 100644 Binary files a/Topiary.CSharp.dll and b/Topiary.CSharp.dll differ diff --git a/Topiary.CSharp.pdb b/Topiary.CSharp.pdb index 3daee2f..3dd93be 100644 Binary files a/Topiary.CSharp.pdb and b/Topiary.CSharp.pdb differ diff --git a/package.json b/package.json index c095d4c..e01b19e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.peartreegames.topiaryunity", - "version": "0.12.0", + "version": "0.13.1", "displayName": "Topiary.Unity", "description": "Topiary Dialogue Runner for Unity", "unity": "2022.3",