Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Docs/VS_Scratch_Mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | 備考 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Unity.VisualScripting;
using FUnity.Runtime.Integrations.VisualScripting;
using System;

namespace FUnity.Runtime.Integrations.VisualScripting.Units.ScratchUnits
{
Expand All @@ -26,13 +25,19 @@ protected override void Definition()
}

/// <summary>
/// すべてのスレッドを停止し、後続フローには進めません。
/// Scratch 用に登録されたすべてのスレッドを停止し、後続フローには進めません。
/// </summary>
/// <param name="flow">現在のフロー情報。</param>
/// <returns>常に null を返し、フローを終端させます。</returns>
private ControlOutput OnEnter(Flow flow)
{
FUnityScriptThreadManager.Instance.StopAllThreads();
var manager = FUnityScriptThreadManager.Instance;
if (manager == null)
{
return null;
}

manager.StopAllScratchThreads();
return null;
}
}
Expand All @@ -59,15 +64,20 @@ protected override void Definition()
}

/// <summary>
/// 現在のフローが紐づくスレッドを停止します
/// 現在のフローが紐づく Scratch スレッドを停止します
/// </summary>
/// <param name="flow">現在のフロー情報。</param>
/// <returns>常に null を返し、フローを終端させます。</returns>
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;
Expand Down Expand Up @@ -102,15 +112,20 @@ protected override void Definition()
}

/// <summary>
/// 同一俳優に属するスレッドのうち、自身以外を停止します。
/// 同一俳優に属する Scratch スレッドのうち、自身以外を停止します。
/// </summary>
/// <param name="flow">現在のフロー情報。</param>
/// <returns>常に後続へ継続する ControlOutput を返します。</returns>
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;
Expand Down