Skip to content

Commit

Permalink
CORE-2563 add save/load ability. CORE-2424 Fixed app crash when quit. (
Browse files Browse the repository at this point in the history
…#49)

* CORE-2563 add save/load ability. CORE-2424 Fixed app crash when quit.

* cleanup doc
  • Loading branch information
Juniverse authored Mar 28, 2023
1 parent c2dcc37 commit e26f3a2
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 49 deletions.
11 changes: 11 additions & 0 deletions Assets/Editor/BuildCommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Inworld.AI/Plugins/InworldProto.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Assets/Inworld.AI/Plugins/InworldProto.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Inworld.AI/Prefabs/Entities/InworldController.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_AutoStart: 1
m_SaveData: 0
m_Data: {fileID: 0}
m_InworldPlayer: {fileID: 0}
m_Capture: {fileID: 6560745356186654253}
Expand All @@ -62,6 +63,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: eedce951bbc942d448b133a3376faec7, type: 3}
m_Name:
m_EditorClassIdentifier:
OnRecordingStart:
m_PersistentCalls:
m_Calls: []
OnRecordingEnd:
m_PersistentCalls:
m_Calls: []
m_AudioRate: 16000
m_BufferSeconds: 1
--- !u!114 &6840405142551539477
Expand All @@ -76,6 +83,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7d696a9c5a5562f4a9af19423ad21b35, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Updatable: 1
m_WSData: {fileID: 0}
m_InworldSceneData: {fileID: 0}
m_CharData: {fileID: 0}
Expand Down
8 changes: 8 additions & 0 deletions Assets/Inworld.AI/SampleData/Materials.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Assets/Inworld.AI/Scenes/SampleBasic.unity
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_AutoStart: 1
m_SaveData: 0
m_Data: {fileID: 11400000, guid: 4952df7b265f22a4b95b85966797af56, type: 2}
m_InworldPlayer: {fileID: 128697891}
m_Capture: {fileID: 359806125}
Expand Down Expand Up @@ -329,6 +330,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: eedce951bbc942d448b133a3376faec7, type: 3}
m_Name:
m_EditorClassIdentifier:
OnRecordingStart:
m_PersistentCalls:
m_Calls: []
OnRecordingEnd:
m_PersistentCalls:
m_Calls: []
m_AudioRate: 16000
m_BufferSeconds: 1
--- !u!114 &359806126
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ void Update()
// Exit Sample
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
#if UNITY_EDITOR
EditorApplication.isPlaying = false;
#endif
InworldController.Instance.StartTerminate();
}
// Hide and lock cursor when right mouse button pressed
if (Input.GetMouseButtonDown(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public GameObject DefaultAvatar
Interruptions = true,
Text = true,
Triggers = true,
Continuation = true,
TurnBasedStt = !m_Interruptible,
PhonemeInfo = true
};
Expand Down
109 changes: 69 additions & 40 deletions Assets/Inworld.AI/Scripts/Runtime/Entities/InworldClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Use of this source code is governed by the Inworld.ai Software Development Kit License Agreement
* that can be found in the LICENSE.md file or at https://www.inworld.ai/sdk-license
*************************************************************************************************/
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Inworld.Grpc;
Expand All @@ -12,7 +13,9 @@
using Inworld.Util;
using System;
using System.Collections.Concurrent;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using AudioChunk = Inworld.Packets.AudioChunk;
using ControlEvent = Inworld.Grpc.ControlEvent;
Expand Down Expand Up @@ -68,6 +71,7 @@ internal InworldClient()
internal bool IsInteracting { get; private set; }
internal bool HasInit => !m_InworldAuth.IsExpired;
internal string SessionID => m_InworldAuth?.SessionID ?? "";
internal string LastState { get; set; }
bool IsSessionInitialized => m_SessionKey.Length != 0;
Timestamp Now => Timestamp.FromDateTime(DateTime.UtcNow);
#endregion
Expand Down Expand Up @@ -101,18 +105,33 @@ internal void GetAppAuth()
}
internal async Task<LoadSceneResponse> LoadScene(string sceneName)
{

LoadSceneRequest lsRequest = new LoadSceneRequest
{
Name = sceneName,
Capabilities = InworldAI.Settings.Capabilities,
User = InworldAI.User.Request,
Client = InworldAI.User.Client
};
if (!string.IsNullOrEmpty(LastState))
{
lsRequest.SessionContinuation = new SessionContinuation
{
PreviousState = ByteString.FromBase64(LastState)
};
}
try
{
LoadSceneResponse response = await m_WorldEngineClient.LoadSceneAsync(lsRequest, m_Header);
// Yan: They somehow use {WorkSpace}:{sessionKey} as "sessionKey" now. Need to remove the first part.
m_SessionKey = response.Key.Split(':')[1];
if (response.PreviousState != null)
{
foreach (PreviousState.Types.StateHolder stateHolder in response.PreviousState.StateHolders)
{
InworldAI.Log($"Received Previous Packets: {stateHolder.Packets.Count}");
}
}
m_Header.Add("Authorization", $"Bearer {m_SessionKey}");
RuntimeEvent?.Invoke(RuntimeStatus.LoadSceneComplete, m_SessionKey);
return response;
Expand Down Expand Up @@ -240,46 +259,7 @@ internal async Task StartSession()
}
if (next)
{
GrpcPacket response = m_StreamingCall.ResponseStream.Current;
if (response.DataChunk != null)
{
switch (response.DataChunk.Type)
{
case DataChunk.Types.DataType.Audio:
connection.incomingAudioQueue.Enqueue(new AudioChunk(response));
break;
case DataChunk.Types.DataType.Animation:
connection.incomingAnimationQueue.Enqueue(new AnimationChunk(response));
break;
default:
InworldAI.LogError($"Unsupported incoming event: {response}");
break;
}
}
else if (response.Text != null)
{
connection.incomingInteractionsQueue.Enqueue(new TextEvent(response));
}
else if (response.Gesture != null)
{
connection.incomingInteractionsQueue.Enqueue(new GestureEvent(response));
}
else if (response.Control != null)
{
connection.incomingInteractionsQueue.Enqueue(new Packets.ControlEvent(response));
}
else if (response.Emotion != null)
{
connection.incomingInteractionsQueue.Enqueue(new EmotionEvent(response));
}
else if (response.Custom != null)
{
connection.incomingInteractionsQueue.Enqueue(new CustomEvent(response));
}
else
{
InworldAI.LogError($"Unsupported incoming event: {response}");
}
_ResolveGRPCPackets(m_StreamingCall.ResponseStream.Current);
}
else
{
Expand Down Expand Up @@ -321,6 +301,55 @@ internal async Task StartSession()
IsInteracting = false;
}
}
internal TextEvent ResolvePreviousPackets(GrpcPacket response) => response.Text != null ? new TextEvent(response) : null;

void _ResolveGRPCPackets(GrpcPacket response)
{
m_CurrentConnection ??= new Connection();
if (response.DataChunk != null)
{
switch (response.DataChunk.Type)
{
case DataChunk.Types.DataType.Audio:
m_CurrentConnection.incomingAudioQueue.Enqueue(new AudioChunk(response));
break;
case DataChunk.Types.DataType.Animation:
m_CurrentConnection.incomingAnimationQueue.Enqueue(new AnimationChunk(response));
break;
case DataChunk.Types.DataType.State:
StateChunk stateChunk = new StateChunk(response);
LastState = stateChunk.Chunk.ToBase64();
break;
default:
InworldAI.LogError($"Unsupported incoming event: {response}");
break;
}
}
else if (response.Text != null)
{
m_CurrentConnection.incomingInteractionsQueue.Enqueue(new TextEvent(response));
}
else if (response.Gesture != null)
{
m_CurrentConnection.incomingInteractionsQueue.Enqueue(new GestureEvent(response));
}
else if (response.Control != null)
{
m_CurrentConnection.incomingInteractionsQueue.Enqueue(new Packets.ControlEvent(response));
}
else if (response.Emotion != null)
{
m_CurrentConnection.incomingInteractionsQueue.Enqueue(new EmotionEvent(response));
}
else if (response.Custom != null)
{
m_CurrentConnection.incomingInteractionsQueue.Enqueue(new CustomEvent(response));
}
else
{
InworldAI.LogError($"Unsupported incoming event: {response}");
}
}
internal async Task EndSession()
{
if (IsInteracting)
Expand Down
Loading

0 comments on commit e26f3a2

Please sign in to comment.