Skip to content

Commit

Permalink
Bump 0.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bgk- committed Jun 2, 2024
1 parent 2f75b18 commit f1d4902
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
45 changes: 35 additions & 10 deletions Runtime/Conversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ public class Conversation : MonoBehaviour
public static readonly Dictionary<IntPtr, Conversation> Conversations = new();
private static readonly Dictionary<string, EvtVariable> Variables = new();
private static Delegates.Subscriber _subscriber;
private List<AsyncOperationHandle<EvtVariable>> _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<AsyncOperationHandle<EvtVariable>>();
}

private IEnumerator Start()
{
if (file == null)
Expand Down Expand Up @@ -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<string> {"Topiary", "Evt"},
Addressables.MergeMode.Intersection);
yield return ao;
Expand All @@ -195,29 +203,46 @@ private IEnumerator LoadAddressableTopiValues()
if (!_data.ExternsSet.Contains(key)) continue;
var aoEvt = Addressables.LoadAssetAsync<EvtVariable>(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);
}
}
}
Expand Down
Binary file modified Topiary.CSharp.dll
Binary file not shown.
Binary file modified Topiary.CSharp.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit f1d4902

Please sign in to comment.