Initialer Upload neues Unity-Projekt
This commit is contained in:
46
Assets/Convai/Scripts/Runtime/Utils/ConvaiAPIKeySetup.cs
Normal file
46
Assets/Convai/Scripts/Runtime/Utils/ConvaiAPIKeySetup.cs
Normal file
@ -0,0 +1,46 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor.EditorTools;
|
||||
#endif
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convai.Scripts.Runtime.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// ScriptableObject that stores Convai API Key.
|
||||
/// Allows the API key to be easily changed from the Unity editor and reduces risk of embedding keys directly into
|
||||
/// script.
|
||||
/// This object can be created from Unity Editor by going in top menu to Convai -> API Key
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "ConvaiAPIKey", menuName = "Convai/API Key")]
|
||||
public class ConvaiAPIKeySetup : ScriptableObject
|
||||
{
|
||||
[ReadOnly] public string APIKey;
|
||||
private static bool hasShownDialog = false;
|
||||
|
||||
public static bool GetAPIKey(out string apiKey)
|
||||
{
|
||||
ConvaiAPIKeySetup keySetup = Resources.Load<ConvaiAPIKeySetup>("ConvaiAPIKey");
|
||||
if (keySetup == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!hasShownDialog)
|
||||
{
|
||||
// display editor utility to show a dialog box saying no API Key found
|
||||
EditorUtility.DisplayDialog("Error", "Convai API Key not found. Please add your API Key by going to Convai -> Convai Setup", "OK");
|
||||
hasShownDialog = true;
|
||||
}
|
||||
#endif
|
||||
if (NotificationSystemHandler.Instance != null)
|
||||
{
|
||||
NotificationSystemHandler.Instance.NotificationRequest(NotificationType.APIKeyNotFound);
|
||||
}
|
||||
apiKey = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
apiKey = keySetup.APIKey;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3402f41fb2bc77540b1edc3e8db81bce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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.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