Initialer Upload neues Unity-Projekt
This commit is contained in:
103
Assets/Oculus/Voice/Samples/Shapes/Scripts/ColorChanger.cs
Normal file
103
Assets/Oculus/Voice/Samples/Shapes/Scripts/ColorChanger.cs
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.Voice.Samples.Shapes
|
||||
{
|
||||
public class ColorChanger : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the color of the specified transform.
|
||||
/// </summary>
|
||||
/// <param name="trans"></param>
|
||||
/// <param name="color"></param>
|
||||
private void SetColor(Transform trans, Color color)
|
||||
{
|
||||
trans.GetComponent<Renderer>().material.color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Directly processes a command result getting the slots with WitResult utilities
|
||||
/// </summary>
|
||||
/// <param name="commandResult">Result data from Wit.ai activation to be processed</param>
|
||||
public void UpdateColor(WitResponseNode commandResult)
|
||||
{
|
||||
string[] colorNames = commandResult.GetAllEntityValues("color:color");
|
||||
string[] shapes = commandResult.GetAllEntityValues("shape:shape");
|
||||
UpdateColor(colorNames, shapes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the colors of a set of shape, or all colors split across the shapes
|
||||
/// </summary>
|
||||
/// <param name="colorNames">The names of the colors to be processed</param>
|
||||
/// <param name="shapes">The shape names or if empty all shapes</param>
|
||||
public void UpdateColor(string[] colorNames, string[] shapes)
|
||||
{
|
||||
if (shapes.Length != 0 && colorNames.Length != shapes.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (shapes.Length == 0 || shapes[0] == "color"){
|
||||
UpdateColorAllShapes(colorNames);
|
||||
return;
|
||||
}
|
||||
|
||||
for(var entity = 0; entity < colorNames.Length; entity++)
|
||||
{
|
||||
if (!ColorUtility.TryParseHtmlString(colorNames[entity], out var color)) return;
|
||||
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
Transform child = transform.GetChild(i);
|
||||
if (String.Equals(shapes[entity], child.name,
|
||||
StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
SetColor(child, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the colors of the shapes, with colours split across the shapes
|
||||
/// </summary>
|
||||
/// <param name="colorNames">The names of the colors to be processed</param>
|
||||
public void UpdateColorAllShapes(string[] colorNames)
|
||||
{
|
||||
var unspecifiedShape = 0;
|
||||
for(var entity = 0; entity < colorNames.Length; entity++)
|
||||
{
|
||||
if (!ColorUtility.TryParseHtmlString(colorNames[entity], out var color)) return;
|
||||
|
||||
var splitLimit = (transform.childCount/colorNames.Length) * (entity+1);
|
||||
while (unspecifiedShape < splitLimit)
|
||||
{
|
||||
SetColor(transform.GetChild(unspecifiedShape), color);
|
||||
unspecifiedShape++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5749c1c94c5bd5b4b8c551c68c28b40b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Meta.Voice.Samples.Shapes",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:4504b1a6e0fdcc3498c30b266e4a63bf",
|
||||
"GUID:1c28d8b71ced07540b7c271537363cc6",
|
||||
"GUID:e545cc0678493234a9368f4e470c29e8"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27caad3e4bdcbe6478324a9c4c83dd50
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.Voice.Samples.Shapes
|
||||
{
|
||||
public class ParallelTextActivator : MonoBehaviour
|
||||
{
|
||||
[Tooltip("The voice service to be used for all the requests")]
|
||||
[SerializeField] private VoiceService _voiceService;
|
||||
|
||||
[Tooltip("All the text requests to be called when 'Send' method is called")]
|
||||
[SerializeField] private string[] _requests;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Reset
|
||||
private string[] _activates = new string[] { "Set the", "Make the" };
|
||||
private string[] _shapes = new string[] { "cube", "sphere", "capsule", "cylinder", "pentagon" };
|
||||
private string[] _colors = new string[] { "red", "blue", "yellow", "green", "orange", "purple", "magenta", "cyan", "brown", "white", "black" };
|
||||
private void Reset()
|
||||
{
|
||||
int index = 0;
|
||||
_requests = new string[_activates.Length * _shapes.Length * _colors.Length];
|
||||
for (int a = 0; a < _activates.Length; a++)
|
||||
{
|
||||
for (int c = 0; c < _colors.Length; c++)
|
||||
{
|
||||
for (int s = 0; s < _shapes.Length; s++)
|
||||
{
|
||||
_requests[index] = $"{_activates[a]} {_shapes[s]} {_colors[c]}";
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public void SendParallelRequests()
|
||||
{
|
||||
foreach (var request in _requests)
|
||||
{
|
||||
_voiceService.Activate(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 254ab30675344a84eb67b7ac93629847
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Oculus.Voice;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Data.Configuration;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Meta.Voice.Samples.Shapes
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class ShapeSampleInstructions : MonoBehaviour
|
||||
{
|
||||
internal enum Step
|
||||
{
|
||||
SetupWit = 0,
|
||||
MissingServerToken,
|
||||
MissingClientToken,
|
||||
AddConfig,
|
||||
AddVoiceExperiences,
|
||||
SetConfig,
|
||||
Ready
|
||||
}
|
||||
|
||||
static readonly string[] steps = new string[]
|
||||
{
|
||||
"Create an application at https://wit.ai. You can import the \"shapes_demo - Wit.ai Config.zip\" in the Demo/Data directory to create it for you.\n\nConnect to the Wit.ai app by clicking Oculus>Voice SDK>Settings and copy the Server Access Token from the Wit.ai app's settings page.Next, create a new Wit configuration by clicking Create.",
|
||||
"Copy the Server Access Token from the Wit.ai app's settings page and paste it in field found in Oculus/Voice SDK/Settings.",
|
||||
"Wit configuration is missing a Client Access Token. Open the Wit configuration, expand Application Configuration, and click Refresh or paste a Client Access Token from your Wit.ai app settings page.",
|
||||
"Create a Wit configuration by clicking Assets/Create/Voice SDK/Configuration.",
|
||||
"The scene is missing the App Voice Experience component. Add it by clicking Assets/Create/Voice SDK/Add App Voice Experience to Scene.",
|
||||
"The App Voice Experience GameObject is missing its Wit configuration. Set the configuration to begin trying voice commands.",
|
||||
""
|
||||
};
|
||||
|
||||
[SerializeField] private Text instructionText;
|
||||
|
||||
private Step currentStep = Step.Ready;
|
||||
internal Step CurrentStep => currentStep;
|
||||
internal string CurrentStepText => steps[(int) currentStep];
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
UpdateStep();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
UpdateStep();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateStep();
|
||||
}
|
||||
|
||||
private void UpdateStep()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var appVoiceExperience = FindObjectOfType<AppVoiceExperience>();
|
||||
string[] guids = AssetDatabase.FindAssets("t:WitConfiguration");
|
||||
if (guids.Length == 0)
|
||||
{
|
||||
currentStep = Step.SetupWit;
|
||||
}
|
||||
else if (!appVoiceExperience)
|
||||
{
|
||||
currentStep = Step.AddVoiceExperiences;
|
||||
}
|
||||
else if (!appVoiceExperience.RuntimeConfiguration.witConfiguration)
|
||||
{
|
||||
currentStep = Step.SetConfig;
|
||||
appVoiceExperience.RuntimeConfiguration.witConfiguration =
|
||||
AssetDatabase.LoadAssetAtPath<WitConfiguration>(
|
||||
AssetDatabase.GUIDToAssetPath(guids[0]));
|
||||
}
|
||||
else if (!WitAuthUtility.IsServerTokenValid())
|
||||
{
|
||||
currentStep = Step.MissingServerToken;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(appVoiceExperience.RuntimeConfiguration?.witConfiguration?
|
||||
.GetClientAccessToken()))
|
||||
{
|
||||
currentStep = Step.MissingClientToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentStep = Step.Ready;
|
||||
}
|
||||
|
||||
|
||||
instructionText.text = steps[(int) currentStep];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(ShapeSampleInstructions))]
|
||||
public class InstructionManagerEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var instructions = (ShapeSampleInstructions) target;
|
||||
|
||||
if (instructions.CurrentStep == ShapeSampleInstructions.Step.Ready)
|
||||
{
|
||||
GUILayout.Label(
|
||||
"Everything is ready. Press play to test activation via the Activate button.");
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.TextArea(instructions.CurrentStepText);
|
||||
GUILayout.Space(32);
|
||||
|
||||
switch (instructions.CurrentStep)
|
||||
{
|
||||
case ShapeSampleInstructions.Step.SetupWit:
|
||||
SetupWitResources();
|
||||
break;
|
||||
case ShapeSampleInstructions.Step.MissingServerToken:
|
||||
MissingServerTokenResources();
|
||||
break;
|
||||
case ShapeSampleInstructions.Step.MissingClientToken:
|
||||
MissingClientTokenResources();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MissingClientTokenResources()
|
||||
{
|
||||
GUILayout.Label("Resources", EditorStyles.boldLabel);
|
||||
|
||||
if (GUILayout.Button("Select Wit Config"))
|
||||
{
|
||||
Selection.activeObject = (FindObjectOfType<AppVoiceExperience>()
|
||||
.RuntimeConfiguration.witConfiguration);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Wit.ai"))
|
||||
{
|
||||
Application.OpenURL("https://wit.ai/apps");
|
||||
}
|
||||
}
|
||||
|
||||
private void MissingServerTokenResources()
|
||||
{
|
||||
GUILayout.Label("Resources", EditorStyles.boldLabel);
|
||||
|
||||
if (GUILayout.Button("Open Wit.ai"))
|
||||
{
|
||||
Application.OpenURL("https://wit.ai/apps");
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupWitResources()
|
||||
{
|
||||
GUILayout.Label("Resources", EditorStyles.boldLabel);
|
||||
|
||||
if (GUILayout.Button("Open Wit.ai"))
|
||||
{
|
||||
Application.OpenURL("https://wit.ai/apps");
|
||||
}
|
||||
|
||||
GUILayout.Label("Wit.ai Sample Application File");
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Open In Explorer"))
|
||||
{
|
||||
EditorUtility.RevealInFinder("Assets/Oculus/Voice/Demo/Data/");
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Copy Path"))
|
||||
{
|
||||
GUIUtility.systemCopyBuffer = Application.dataPath + "/Oculus/Voice/Demo/Data";
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63642574fdd5cde45a20839fbffc18df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user