Initial Commit

This commit is contained in:
2025-07-04 20:33:06 +03:00
commit 8f09347ae0
9219 changed files with 2447903 additions and 0 deletions
@@ -0,0 +1,29 @@
/*
* 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 UnityEditor;
namespace Meta.WitAi.CallbackHandlers
{
[CustomEditor(typeof(SimpleIntentHandler))]
public class SimpleIntentHandlerEditor : WitIntentMatcherEditor
{
protected override void OnEnable()
{
base.OnEnable();
_fieldGUI.onAdditionalGuiLayout = OnInspectorAdditionalGUI;
}
private void OnInspectorAdditionalGUI()
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Output", EditorStyles.boldLabel);
var eventProperty = serializedObject.FindProperty("onIntentTriggered");
EditorGUILayout.PropertyField(eventProperty);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10996c842bbaede43a73adef9cddba5a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,52 @@
/*
* 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.Linq;
using System.Reflection;
using Meta.WitAi.Data.Info;
using UnityEditor;
using UnityEngine;
namespace Meta.WitAi.CallbackHandlers
{
[CustomEditor(typeof(SimpleStringEntityHandler))]
public class SimpleStringEntityHandlerEditor : WitIntentMatcherEditor
{
// Entity values
private string[] _entityNames;
private int _entityIndex;
// Set app info
protected override void SetAppInfo(WitAppInfo appInfo)
{
base.SetAppInfo(appInfo);
if (appInfo.entities != null)
{
_entityNames = appInfo.entities.Select(i => i.name).ToArray();
_entityIndex = Array.IndexOf(_entityNames, ((SimpleStringEntityHandler)_matcher).entity);
}
}
// Custom GUI
protected override bool OnInspectorCustomGUI(FieldInfo fieldInfo)
{
base.OnInspectorCustomGUI(fieldInfo);
// Custom layout
if (string.Equals(fieldInfo.Name, "entity"))
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Entity", EditorStyles.boldLabel);
WitEditorUI.LayoutSerializedObjectPopup(serializedObject, "entity",
_entityNames, ref _entityIndex);
return true;
}
// Layout intent triggered
return false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a303e99a01d07d54e9659f3b46adbe25
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,248 @@
/*
* 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.Collections.Generic;
using Meta.WitAi.Data;
using UnityEditor;
using UnityEngine;
namespace Meta.WitAi.CallbackHandlers
{
public class ValuePathMatcherPropertyDrawer : PropertyDrawer
{
private string currentEditPath;
class Properties
{
public const string witValueRef = "witValueReference";
public const string path = "path";
public const string contentRequired = "contentRequired";
public const string matchMethod = "matchMethod";
public const string comparisonMethod = "comparisonMethod";
public const string matchValue = "matchValue";
public const string floatingPointComparisonTolerance =
"floatingPointComparisonTolerance";
}
private Dictionary<string, bool> foldouts =
new Dictionary<string, bool>();
private string GetPropertyPath(SerializedProperty property)
{
var valueRefProp = property.FindPropertyRelative(Properties.witValueRef);
if (valueRefProp.objectReferenceValue)
{
return ((WitValue) valueRefProp.objectReferenceValue).path;
}
return property.FindPropertyRelative(Properties.path).stringValue;
}
private bool IsEditingProperty(SerializedProperty property)
{
var path = GetPropertyPath(property);
return path == currentEditPath || string.IsNullOrEmpty(path);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
float height = 0;
// Path
height += EditorGUIUtility.singleLineHeight;
if (IsExpanded(property))
{
// Content Required
height += EditorGUIUtility.singleLineHeight;
// Match Method
height += EditorGUIUtility.singleLineHeight;
if (ComparisonMethodsVisible(property))
{
// Comparison Method
height += EditorGUIUtility.singleLineHeight;
}
if (ComparisonValueVisible(property))
{
// Comparison Value
height += EditorGUIUtility.singleLineHeight;
}
if (FloatingToleranceVisible(property))
{
// Floating Point Tolerance
height += EditorGUIUtility.singleLineHeight;
}
height += 4;
}
return height;
}
private bool IsExpanded(SerializedProperty property)
{
return foldouts.TryGetValue(GetPropertyPath(property), out bool value) && value;
}
private bool Foldout(Rect rect, SerializedProperty property)
{
var path = GetPropertyPath(property);
if (!foldouts.TryGetValue(path, out var value))
{
foldouts[path] = false;
}
foldouts[path] = EditorGUI.Foldout(rect, value, "");
return foldouts[path];
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var rect = new Rect(position)
{
height = EditorGUIUtility.singleLineHeight
};
var path = property.FindPropertyRelative(Properties.path);
var valueRefProp = property.FindPropertyRelative(Properties.witValueRef);
var editIconWidth = 24;
var pathRect = new Rect(rect);
pathRect.width -= editIconWidth;
var pathValue = GetPropertyPath(property);
if (IsEditingProperty(property))
{
if (!valueRefProp.objectReferenceValue)
{
pathRect.width -= WitStyles.IconButtonSize;
var value = EditorGUI.TextField(pathRect, path.stringValue);
if (value != path.stringValue)
{
path.stringValue = value;
}
pathRect.width += WitStyles.IconButtonSize;
var pickerRect = new Rect(pathRect)
{
x = pathRect.x + pathRect.width - 20,
width = 20
};
if (GUI.Button(pickerRect, WitStyles.ObjectPickerIcon, "Label"))
{
var id = EditorGUIUtility.GetControlID(FocusType.Passive) + 100;
EditorGUIUtility.ShowObjectPicker<WitValue>(
(WitValue) valueRefProp.objectReferenceValue, false, "", id);
}
}
else
{
EditorGUI.PropertyField(pathRect, valueRefProp, new GUIContent());
}
if (Event.current.commandName == "ObjectSelectorClosed")
{
valueRefProp.objectReferenceValue = EditorGUIUtility.GetObjectPickerObject();
}
pathValue = GetPropertyPath(property);
if (pathValue != currentEditPath && null != currentEditPath)
{
foldouts[currentEditPath] = false;
currentEditPath = GetPropertyPath(property);
foldouts[currentEditPath] = true;
}
}
else
{
if (valueRefProp.objectReferenceValue)
{
EditorGUI.LabelField(pathRect, valueRefProp.objectReferenceValue.name);
}
else
{
EditorGUI.LabelField(pathRect, path.stringValue);
}
}
var editRect = new Rect(rect)
{
x = pathRect.x + pathRect.width + 8
};
if (Foldout(rect, property))
{
if (GUI.Button(editRect, WitStyles.EditIcon, "Label"))
{
if (currentEditPath == pathValue)
{
currentEditPath = null;
}
else
{
currentEditPath = pathValue;
}
}
rect.x += WitStyles.IconButtonSize;
rect.width -= WitStyles.IconButtonSize;
rect.y += rect.height;
EditorGUI.PropertyField(rect, property.FindPropertyRelative(Properties.contentRequired));
rect.y += rect.height;
EditorGUI.PropertyField(rect, property.FindPropertyRelative(Properties.matchMethod));
if (ComparisonMethodsVisible(property))
{
rect.y += rect.height;
EditorGUI.PropertyField(rect,
property.FindPropertyRelative(Properties.comparisonMethod));
}
if (ComparisonValueVisible(property))
{
rect.y += rect.height;
EditorGUI.PropertyField(rect,
property.FindPropertyRelative(Properties.matchValue));
}
if (FloatingToleranceVisible(property))
{
rect.y += rect.height;
EditorGUI.PropertyField(rect,
property.FindPropertyRelative(Properties.floatingPointComparisonTolerance));
}
}
}
private bool ComparisonMethodsVisible(SerializedProperty property)
{
var matchedMethodProperty = property.FindPropertyRelative(Properties.matchMethod);
return matchedMethodProperty.enumValueIndex > (int) MatchMethod.RegularExpression;
}
private bool ComparisonValueVisible(SerializedProperty property)
{
var matchedMethodProperty = property.FindPropertyRelative(Properties.matchMethod);
return matchedMethodProperty.enumValueIndex > 0;
}
private bool FloatingToleranceVisible(SerializedProperty property)
{
var matchedMethodProperty = property.FindPropertyRelative(Properties.matchMethod);
var comparisonMethodProperty =
property.FindPropertyRelative(Properties.comparisonMethod);
var comparisonMethod = comparisonMethodProperty.enumValueIndex;
return matchedMethodProperty.enumValueIndex >= (int) MatchMethod.FloatComparison &&
(comparisonMethod == (int) ComparisonMethod.Equals || comparisonMethod == (int) ComparisonMethod.NotEquals);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 70c91e08d884bfe4a99b40d2706b15d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,90 @@
/*
* 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.Linq;
using System.Reflection;
using Meta.WitAi.Data.Info;
using Meta.WitAi.Windows;
using UnityEditor;
using UnityEngine;
namespace Meta.WitAi.CallbackHandlers
{
public class WitIntentMatcherEditor : Editor
{
// The matcher
protected WitIntentMatcher _matcher;
// Custom field gui
protected FieldGUI _fieldGUI;
// Intents & current intent
private string[] _intentNames;
private int _intentIndex;
// On enable, setup gui
protected virtual void OnEnable()
{
_matcher = target as WitIntentMatcher;
// Setup field gui
if (_fieldGUI == null)
{
_fieldGUI = new FieldGUI();
_fieldGUI.onCustomGuiLayout = OnInspectorCustomGUI;
}
}
// Inspector gui
public override void OnInspectorGUI()
{
if (!_matcher.Voice)
{
GUILayout.Label("VoiceService component is not present in the scene. Add voice service to scene to get intent suggestions.",
EditorStyles.helpBox);
}
// Intent suggestions
if (_matcher && _matcher.Voice && null == _intentNames)
{
if (_matcher.Voice is IWitRuntimeConfigProvider provider
&& null != provider.RuntimeConfiguration
&& provider.RuntimeConfiguration.witConfiguration)
{
SetAppInfo(provider.RuntimeConfiguration.witConfiguration.GetApplicationInfo());
}
}
// Layout fields
_fieldGUI.OnGuiLayout(serializedObject);
}
// Set app info
protected virtual void SetAppInfo(WitAppInfo appInfo)
{
if (appInfo.intents != null)
{
_intentNames = appInfo.intents.Select(i => i.name).ToArray();
_intentIndex = Array.IndexOf(_intentNames, _matcher.intent);
}
}
// Custom GUI
protected virtual bool OnInspectorCustomGUI(FieldInfo fieldInfo)
{
// Custom layout
if (string.Equals(fieldInfo.Name, "intent"))
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Validation Settings", EditorStyles.boldLabel);
WitEditorUI.LayoutSerializedObjectPopup(serializedObject, "intent",
_intentNames, ref _intentIndex);
return true;
}
// Layout intent triggered
return false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ef9650649f4f6740a0b7d5b6b4e5dd2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: