Files
plugin-library/Assets/07.RKTools/RunTime/RKVoiceCommand/IVoiceCommandSystem.cs

70 lines
2.0 KiB
C#
Raw Normal View History

2025-04-11 10:03:08 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Stary.Evo;
2025-05-19 15:42:24 +08:00
namespace Stary.Evo.RKTools
2025-04-11 10:03:08 +08:00
{
2025-05-19 15:42:24 +08:00
public interface IVoiceCommandSystem : ISystem
2025-04-11 10:03:08 +08:00
{
2025-05-19 15:42:24 +08:00
public void AddVoiceCommand(string content, string spell, Action action);
public void DeleteVoiceCommand(string content);
public void ClearAllVoiceCommands();
2025-04-11 10:03:08 +08:00
}
2025-05-19 15:42:24 +08:00
public class VoiceCommandSystem : AbstractSystem, IVoiceCommandSystem
2025-04-11 10:03:08 +08:00
{
2025-05-19 15:42:24 +08:00
private VoiceCommandController _voiceController;
protected virtual string ControllerName
2025-04-11 10:03:08 +08:00
{
2025-05-19 15:42:24 +08:00
get { return "VoiceCommandController"; }
2025-04-11 10:03:08 +08:00
}
2025-05-19 15:42:24 +08:00
private void createVoiceCommandContriller()
2025-04-11 10:03:08 +08:00
{
2025-05-19 15:42:24 +08:00
GameObject VoiceControllerObject = GameObject.Find(ControllerName);
if (VoiceControllerObject == null)
{
VoiceControllerObject = new GameObject(ControllerName);
}
_voiceController = VoiceControllerObject.GetComponent<VoiceCommandController>();
if (_voiceController == null)
{
_voiceController = VoiceControllerObject.AddComponent<VoiceCommandController>();
}
2025-04-11 10:03:08 +08:00
}
2025-05-19 15:42:24 +08:00
public void AddVoiceCommand(string content, string spell, Action action)
{
if (_voiceController == null) createVoiceCommandContriller();
_voiceController.RegisteredVoiceCommand(content, spell, action);
}
2025-04-11 10:03:08 +08:00
2025-05-19 15:42:24 +08:00
public void DeleteVoiceCommand(string content)
2025-04-11 10:03:08 +08:00
{
2025-05-19 15:42:24 +08:00
if (_voiceController != null) _voiceController.DeleteVoiceCommand(content);
2025-04-11 10:03:08 +08:00
}
2025-05-19 15:42:24 +08:00
public void ClearAllVoiceCommands()
{
if (_voiceController != null)
{
_voiceController.ClearAllVoiceCommand();
GameObject.Destroy(_voiceController.gameObject);
}
}
public override void Dispose()
{
ClearAllVoiceCommands();
}
protected override void OnInit()
{
}
2025-04-11 10:03:08 +08:00
}
}