07Rokid语音命令
This commit is contained in:
64
Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs
Normal file
64
Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Stary.Evo;
|
||||
|
||||
public interface IVoiceCommandSystem : ISystem
|
||||
{
|
||||
public void AddVoiceCommand(string content,string spell, Action action);
|
||||
public void DeleteVoiceCommand(string content);
|
||||
public void ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem
|
||||
{
|
||||
private VoiceCommandController _voiceController;
|
||||
protected virtual string ControllerName
|
||||
{
|
||||
get { return "VoiceCommandController"; }
|
||||
}
|
||||
|
||||
private void createVoiceCommandContriller()
|
||||
{
|
||||
GameObject VoiceControllerObject = GameObject.Find(ControllerName);
|
||||
if (VoiceControllerObject == null)
|
||||
{
|
||||
VoiceControllerObject = new GameObject(ControllerName);
|
||||
}
|
||||
_voiceController = VoiceControllerObject.GetComponent<VoiceCommandController>();
|
||||
if (_voiceController == null)
|
||||
{
|
||||
_voiceController = VoiceControllerObject.AddComponent<VoiceCommandController>();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddVoiceCommand(string content,string spell, Action action)
|
||||
{
|
||||
if (_voiceController == null) createVoiceCommandContriller();
|
||||
_voiceController.RegisteredVoiceCommand(content, spell, action);
|
||||
}
|
||||
|
||||
public void DeleteVoiceCommand(string content)
|
||||
{
|
||||
if(_voiceController!=null) _voiceController.DeleteVoiceCommand(content);
|
||||
}
|
||||
|
||||
public void ClearAllVoiceCommands()
|
||||
{
|
||||
if (_voiceController != null)
|
||||
{
|
||||
_voiceController.ClearAllVoiceCommand();
|
||||
GameObject.Destroy(_voiceController.gameObject);
|
||||
}
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user