Initial Commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Meta.Conduit;
|
||||
|
||||
namespace Meta.WitAi
|
||||
{
|
||||
/// <summary>
|
||||
/// Triggers a method to be executed if it matches a voice command's intent
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public class MatchIntent : ConduitActionAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Triggers a method to be executed if it matches a voice command's intent
|
||||
/// </summary>
|
||||
/// <param name="intent">The name of the intent to match</param>
|
||||
/// <param name="minConfidence">The minimum confidence value (0-1) needed to match</param>
|
||||
/// <param name="maxConfidence">The maximum confidence value(0-1) needed to match</param>
|
||||
public MatchIntent(string intent, float minConfidence = DEFAULT_MIN_CONFIDENCE, float maxConfidence = DEFAULT_MAX_CONFIDENCE) : base(intent, minConfidence, maxConfidence, false)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f071cbc42a68405a81505dcf44f5f114
|
||||
timeCreated: 1646065974
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Meta.WitAi.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.WitAi
|
||||
{
|
||||
internal class RegisteredMatchIntent
|
||||
{
|
||||
public Type type;
|
||||
public MethodInfo method;
|
||||
public MatchIntent matchIntent;
|
||||
}
|
||||
|
||||
internal static class MatchIntentRegistry
|
||||
{
|
||||
private static DictionaryList<string, RegisteredMatchIntent> registeredMethods;
|
||||
|
||||
public static DictionaryList<string, RegisteredMatchIntent> RegisteredMethods
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == registeredMethods)
|
||||
{
|
||||
// Note, first run this will not return any values. Initialize
|
||||
// scans assemblies on a different thread. This is ok for voice
|
||||
// commands since they are generally executed in realtime after
|
||||
// initialization is complete. This is a perf optimization.
|
||||
//
|
||||
// Best practice is to call Initialize in Awake of any method
|
||||
// that will be using the resulting data.
|
||||
Initialize();
|
||||
}
|
||||
|
||||
return registeredMethods;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
if (null != registeredMethods) return;
|
||||
registeredMethods = new DictionaryList<string, RegisteredMatchIntent>();
|
||||
new Thread(RefreshAssemblies).Start();
|
||||
}
|
||||
|
||||
internal static void RefreshAssemblies()
|
||||
{
|
||||
if (Thread.CurrentThread.ThreadState == ThreadState.Aborted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO: We could potentially build this list at compile time and cache it
|
||||
// Work on a local dictionary to avoid thread complications
|
||||
var dictionary = new DictionaryList<string, RegisteredMatchIntent>();
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
try {
|
||||
foreach (Type t in assembly.GetTypes()) {
|
||||
try {
|
||||
foreach (var method in t.GetMethods()) {
|
||||
try {
|
||||
foreach (var attribute in method.GetCustomAttributes(typeof(MatchIntent))) {
|
||||
try {
|
||||
var mi = (MatchIntent)attribute;
|
||||
dictionary[mi.Intent].Add(new RegisteredMatchIntent() {
|
||||
type = t,
|
||||
method = method,
|
||||
matchIntent = mi
|
||||
});
|
||||
} catch (Exception e) {
|
||||
VLog.E(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
VLog.E(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
VLog.E(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
VLog.E(e);
|
||||
}
|
||||
}
|
||||
|
||||
registeredMethods = dictionary;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13db0e8ded83f5241a7cdd13a99dab62
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Meta.Conduit;
|
||||
|
||||
namespace Meta.WitAi
|
||||
{
|
||||
/// <summary>
|
||||
/// Triggers a method to be executed if it matches a voice command's intent
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public class ValidatePartialIntent : ConduitActionAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Triggers a method to be executed if it matches a voice command's intent
|
||||
/// </summary>
|
||||
/// <param name="intent">The name of the intent to match</param>
|
||||
/// <param name="minConfidence">The minimum confidence value (0-1) needed to match</param>
|
||||
/// <param name="maxConfidence">The maximum confidence value(0-1) needed to match</param>
|
||||
public ValidatePartialIntent(string intent, float minConfidence = DEFAULT_MIN_CONFIDENCE, float maxConfidence = DEFAULT_MAX_CONFIDENCE) : base(intent, minConfidence, maxConfidence, true)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ac92a21e82e90b4c93ff4605a6d4c8f
|
||||
timeCreated: 1646065974
|
||||
Reference in New Issue
Block a user