Files
plugin-library/Assets/07.RKTools/RunTime/RKVoiceCommand/IVoiceCommandSystem.cs
2025-05-19 15:42:24 +08:00

70 lines
2.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Stary.Evo;
namespace Stary.Evo.RKTools
{
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()
{
}
}
}