64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
|
|
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();
|
||
|
|
}
|
||
|
|
}
|