initial upload
This commit is contained in:
33
Assets/Convai/Scripts/Runtime/Utils/ConvaiAPIKeySetup.cs
Normal file
33
Assets/Convai/Scripts/Runtime/Utils/ConvaiAPIKeySetup.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Convai.Scripts.Runtime.Addons;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConvaiAPIKeySetup : ScriptableObject
|
||||
{
|
||||
private const string RESOURCE_PATH = "ConvaiAPIKey";
|
||||
private static ConvaiAPIKeySetup _instance;
|
||||
public string APIKey;
|
||||
|
||||
public static event Action OnAPIKeyNotFound;
|
||||
|
||||
public static bool GetAPIKey(out string apiKey)
|
||||
{
|
||||
if (_instance == null) _instance = Resources.Load<ConvaiAPIKeySetup>(RESOURCE_PATH);
|
||||
|
||||
if (_instance == null || string.IsNullOrEmpty(_instance.APIKey))
|
||||
{
|
||||
NotifyAPIKeyNotFound();
|
||||
apiKey = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
apiKey = _instance.APIKey;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void NotifyAPIKeyNotFound()
|
||||
{
|
||||
if (NotificationSystemHandler.Instance != null) NotificationSystemHandler.Instance.NotificationRequest(NotificationType.APIKeyNotFound);
|
||||
OnAPIKeyNotFound?.Invoke();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3402f41fb2bc77540b1edc3e8db81bce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Convai/Scripts/Runtime/Utils/ConvaiLanguageCheck.cs
Normal file
23
Assets/Convai/Scripts/Runtime/Utils/ConvaiLanguageCheck.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace Convai.Scripts.Runtime.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility for language features
|
||||
/// </summary>
|
||||
public abstract class ConvaiLanguageCheck
|
||||
{
|
||||
private const char MIN_ARABIC_RANGE = '\u0600';
|
||||
private const char MAX_ARABIC_RANGE = '\u06FF';
|
||||
|
||||
/// <summary>
|
||||
/// To check if the text is in a Right-to-Left(RTL) Language
|
||||
/// </summary>
|
||||
/// <param name="text">The text for RTL Check.</param>
|
||||
/// <returns>Bool denoting the text is RTL or not</returns>
|
||||
public static bool IsRTL(string text)
|
||||
{
|
||||
return text.Any(c => c is >= MIN_ARABIC_RANGE and <= MAX_ARABIC_RANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26484ff268a04721b855ad72cfdb868b
|
||||
timeCreated: 1717586932
|
||||
40
Assets/Convai/Scripts/Runtime/Utils/MainThreadDispatcher.cs
Normal file
40
Assets/Convai/Scripts/Runtime/Utils/MainThreadDispatcher.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convai.Scripts.Runtime.Utils
|
||||
{
|
||||
public class MainThreadDispatcher : MonoBehaviour
|
||||
{
|
||||
private readonly Queue<Action> _actions = new();
|
||||
|
||||
public static MainThreadDispatcher Instance { get; private set; }
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
lock (_actions)
|
||||
{
|
||||
while (_actions.Count > 0)
|
||||
{
|
||||
Action actionToInvoke = _actions.Dequeue();
|
||||
actionToInvoke?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateInstance()
|
||||
{
|
||||
Instance = new GameObject("MainThreadDispatcher").AddComponent<MainThreadDispatcher>();
|
||||
DontDestroyOnLoad(Instance.gameObject);
|
||||
}
|
||||
|
||||
public void RunOnMainThread(Action action)
|
||||
{
|
||||
lock (_actions)
|
||||
{
|
||||
_actions.Enqueue(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b162b45e89a36d4ba0b404191517ebb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user