56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
|
|
public static class FixSystemYarnCommand
|
|
{
|
|
[YarnCommand("switch_fix_system_to")]
|
|
public static IEnumerator SwitchFixSystemTo(string targetStateStr, string extraArg = "")
|
|
{
|
|
// 字符串转枚举
|
|
if (!Enum.TryParse<FixState>(targetStateStr, out var targetState))
|
|
{
|
|
Debug.Log($"{targetStateStr}不在FixState枚举中");
|
|
yield break;
|
|
}
|
|
|
|
yield return FixSystemCenter.StateMachine.SwitchState(targetState, extraArg);
|
|
}
|
|
|
|
#region 维修系统管理器命令
|
|
|
|
/// <summary>
|
|
/// 切换到指定的维修系统(按类型名称)
|
|
/// 用法: <<repair_switch_system "BlockPuzzleSystem">>
|
|
/// </summary>
|
|
[YarnCommand("repair_switch_system")]
|
|
public static IEnumerator RepairSwitchSystem(string systemTypeName)
|
|
{
|
|
Type systemType = systemTypeName switch
|
|
{
|
|
"BodyModuleSystem" => typeof(BodyModuleSystem),
|
|
"BlockPuzzleSystem" => typeof(BlockPuzzleSystem),
|
|
_ => null
|
|
};
|
|
|
|
if (systemType == null)
|
|
{
|
|
Debug.LogError($"[Yarn] 未知的系统类型: {systemTypeName}");
|
|
yield break;
|
|
}
|
|
|
|
RepairSystemManager.Instance.SwitchSystem(systemType);
|
|
|
|
// 等待切换动画
|
|
yield return new WaitForSeconds(RepairSystemManager.Instance.GetComponent<RepairSystemManager>()
|
|
?.GetType().GetField("switchDuration", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
|
|
?.GetValue(RepairSystemManager.Instance) is float duration ? duration : 0.5f);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |