diff --git a/Docs/VS_Scratch_Mapping.md b/Docs/VS_Scratch_Mapping.md
index 2fdcd01..734efa6 100644
--- a/Docs/VS_Scratch_Mapping.md
+++ b/Docs/VS_Scratch_Mapping.md
@@ -62,12 +62,12 @@ Scratch ブロックと FUnity 独自 Visual Scripting Unit の対応関係で
| ○のクローンを作る | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.CreateCloneOfDisplayNameUnit | ○のクローンを作る | FUnity/Scratch/制御 | 指定俳優を複製。定義: Runtime/.../CloneUnits.cs |
| クローンされたとき | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.WhenIStartAsCloneUnit | クローンされたとき | Events/FUnity/Scratch/制御 | クローン生成時イベント。定義: Runtime/.../CloneUnits.cs |
| このクローンを削除する | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.DeleteThisCloneUnit | このクローンを削除する | FUnity/Scratch/制御 | クローンを破棄。定義: Runtime/.../CloneUnits.cs |
-| すべてを止める | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.StopAllUnit | Scratch/すべてを止める | FUnity/Scratch/制御 | ScriptThreadManager で全スレッド停止。定義: Runtime/.../StopControlUnits.cs |
-| このスクリプトを止める | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.StopThisScriptUnit | Scratch/このスクリプトを止める | FUnity/Scratch/制御 | 現在スレッドのみ停止。定義: Runtime/.../StopControlUnits.cs |
-| スプライトの他のスクリプトを止める | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.StopOtherScriptsInSpriteUnit | Scratch/スプライトの他のスクリプトを止める | FUnity/Scratch/制御 | 同俳優の他スレッド停止。定義: Runtime/.../StopControlUnits.cs |
+| すべてを止める | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.StopAllUnit | Scratch/すべてを止める | FUnity/Scratch/制御 | Scratch 用スレッドテーブル経由で全スレッド停止。定義: Runtime/.../StopControlUnits.cs |
+| このスクリプトを止める | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.StopThisScriptUnit | Scratch/このスクリプトを止める | FUnity/Scratch/制御 | 現在の Scratch スレッドのみ停止。定義: Runtime/.../StopControlUnits.cs |
+| スプライトの他のスクリプトを止める | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.StopOtherScriptsInSpriteUnit | Scratch/スプライトの他のスクリプトを止める | FUnity/Scratch/制御 | 同俳優の他 Scratch スレッド停止。定義: Runtime/.../StopControlUnits.cs |
| もし○なら | FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits.IfThenUnit | もし○なら | FUnity/Scratch/制御 | 条件成立時のみ本体を実行。定義: Runtime/.../ConditionUnits.cs |
-> **補足:** Scratch 系の停止ユニットは、`FUnityScriptThreadManager` に用意した Scratch 専用スレッドテーブルを利用してコルーチンを管理します。Step1 ではスレッド登録 API(`RegisterScratchThread` など)を追加しただけで、Unit からの呼び出しは今後のステップで接続します。現在は Guid ベースの `TryGetThreadContext` を明示的に使用し、停止対象のスレッド ID を確実に取得する実装に統一しています。
+> **補足:** Scratch 系の停止ユニットは、`FUnityScriptThreadManager` に用意した Scratch 専用スレッドテーブルを利用してコルーチンを管理します。`ScratchUnitUtil` に保存した string ベースの ActorId/ThreadId を参照し、`StopAllScratchThreads`・`StopScratchThread`・`StopOtherScratchThreadsOfActor` を呼び出して対象を制御します。
## イベント
| Scratch ブロック (日本語) | FUnity Unit クラス | UnitTitle | UnitCategory | 備考 |
diff --git a/Runtime/Integrations/VisualScripting/Units/ScratchUnits/StopControlUnits.cs b/Runtime/Integrations/VisualScripting/Units/ScratchUnits/StopControlUnits.cs
index 7265137..c92c946 100644
--- a/Runtime/Integrations/VisualScripting/Units/ScratchUnits/StopControlUnits.cs
+++ b/Runtime/Integrations/VisualScripting/Units/ScratchUnits/StopControlUnits.cs
@@ -1,6 +1,5 @@
using Unity.VisualScripting;
using FUnity.Runtime.Integrations.VisualScripting;
-using System;
namespace FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits
{
@@ -26,13 +25,19 @@ protected override void Definition()
}
///
- /// すべてのスレッドを停止し、後続フローには進めません。
+ /// Scratch 用に登録されたすべてのスレッドを停止し、後続フローには進めません。
///
/// 現在のフロー情報。
/// 常に null を返し、フローを終端させます。
private ControlOutput OnEnter(Flow flow)
{
- FUnityScriptThreadManager.Instance.StopAllThreads();
+ var manager = FUnityScriptThreadManager.Instance;
+ if (manager == null)
+ {
+ return null;
+ }
+
+ manager.StopAllScratchThreads();
return null;
}
}
@@ -59,15 +64,20 @@ protected override void Definition()
}
///
- /// 現在のフローが紐づくスレッドを停止します。
+ /// 現在のフローが紐づく Scratch スレッドを停止します。
///
/// 現在のフロー情報。
/// 常に null を返し、フローを終端させます。
private ControlOutput OnEnter(Flow flow)
{
- if (ScratchUnitUtil.TryGetThreadContext(flow, out _, out Guid threadId))
+ if (ScratchUnitUtil.TryGetThreadContext(flow, out string _, out string threadId) &&
+ !string.IsNullOrEmpty(threadId))
{
- FUnityScriptThreadManager.Instance.StopThread(threadId);
+ var manager = FUnityScriptThreadManager.Instance;
+ if (manager != null)
+ {
+ manager.StopScratchThread(threadId);
+ }
}
return null;
@@ -102,15 +112,20 @@ protected override void Definition()
}
///
- /// 同一俳優に属するスレッドのうち、自身以外を停止します。
+ /// 同一俳優に属する Scratch スレッドのうち、自身以外を停止します。
///
/// 現在のフロー情報。
/// 常に後続へ継続する ControlOutput を返します。
private ControlOutput OnEnter(Flow flow)
{
- if (ScratchUnitUtil.TryGetThreadContext(flow, out string actorId, out Guid threadId))
+ if (ScratchUnitUtil.TryGetThreadContext(flow, out string actorId, out string threadId) &&
+ !string.IsNullOrEmpty(actorId))
{
- FUnityScriptThreadManager.Instance.StopThreadsOfActorExcept(actorId, threadId);
+ var manager = FUnityScriptThreadManager.Instance;
+ if (manager != null)
+ {
+ manager.StopOtherScratchThreadsOfActor(actorId, threadId);
+ }
}
return m_Output;