Enum型の出力スロットを作成する方法

Here is the forum to do the questions about how to use to Arbor developer.
Attention point:
  • We can not answer your questions about your project specific issues.
  • We can not answer your questions on Unity's specification issues.
  • Please check Arbor Documentation and ask a question if you still don't know how to use it. If the desired function is not described in the document, it is highly possible that the function does not exist from the beginning, so go to the request forum.

ここは、Arbor開発者へ使い方に関する質問を行うフォーラムです。
注意点:
  • ユーザー様のプロジェクトの仕様上の問題や設計に対する質問には答えられません。
  • Unityの仕様上の問題に対する質問には答えられません。
  • Arbor Documentationを確認の上、それでも使い方がわからない場合にご質問ください。欲しい機能の記載がドキュメントにない場合は機能が元から存在しない可能性が高いので要望フォーラムへ。

Forum rules
Here is the forum to do the questions about how to use to Arbor developer.
Attention point:
  • We can not answer your questions about your project specific issues.
  • We can not answer your questions on Unity's specification issues.
  • Please check Arbor Documentation and ask a question if you still don't know how to use it. If the desired function is not described in the document, it is highly possible that the function does not exist from the beginning, so go to the request forum.

ここは、Arbor開発者へ使い方に関する質問を行うフォーラムです。
注意点:
  • ユーザー様のプロジェクトの仕様上の問題や設計に対する質問には答えられません。
  • Unityの仕様上の問題に対する質問には答えられません。
  • Arbor Documentationを確認の上、それでも使い方がわからない場合にご質問ください。欲しい機能の記載がドキュメントにない場合は機能が元から存在しない可能性が高いので要望フォーラムへ。
matchy
Posts: 5
Joined: 2020/02/24 08:04

Enum型の出力スロットを作成する方法

Post by matchy »

Enum型の出力スロットを作成するには、どの出力スロットクラスを使用すればよろしいでしょうか?
User avatar
caitsithware
管理人
Posts: 493
Joined: 2015/08/17 12:41

Re: Enum型の出力スロットを作成する方法

Post by caitsithware »

enum型のスロットですね。
enum型と言っても型の種類が多数あるため、特定のenum型専用の出力スロットは用意しておりません。

スクリプトから任意のenum型スロットを使用するには以下の2つの方法があります。

1. スロットの自作

OutputSlot<T>やInputSlot<T>を継承して、任意の型のスロットを作成する方法です。

参考コードは以下の通りです(最低限の記述であるため、あくまで参考程度に)

Code: Select all

using Arbor;

public enum MyEnum
{
    A,
    B,
}

[System.Serializable]
public class OutputSlotMyEnum : OutputSlot<MyEnum> {}

[System.Serializable]
public class InputSlotMyEnum : InputSlot<MyEnum> {}
フィールドの宣言側は、作成したOutputSlotMyEnumなどを使用して下さい。
※注:Unityの仕様により、フィールドに直接「public OutputSlot<MyEnum> output;」といった宣言はできません。

参考リンク

OutputSlot<T>
InputSlot<T>


2. 汎用スロットを使用

型に制限がないOutputSlotAnyやInputSlotAnyを使用する方法です。
また、型を制限するSlotTypeAttribute属性などで、任意の型のみに制限もできます。

参考コードは以下の通りです(最低限の記述であるため、あくまで参考程度に)

Code: Select all

using Arbor;

public class MyBehaviour : StateBehaviour {
    [SlotType(typeof(MyEnum))]
    public OutputSlotAny output;
    
    [SlotType(typeof(MyEnum))]
    public InputSlotAny input;
    
    // 以下略
}
OutputSlotAny,InputSlotAnyはobject型での受け渡しとなるため、間違った型を渡してしまうと実行時の不具合の原因となります。
その点注意して利用してください。

参考リンク

OutputSlotAny
InputSlotAny
SlotTypeAttribute
matchy
Posts: 5
Joined: 2020/02/24 08:04

Re: Enum型の出力スロットを作成する方法

Post by matchy »

ご回答いただいた方法でEnum型の出力スロットを作成することができました。
ご対応、ありがとうございました。
User avatar
caitsithware
管理人
Posts: 493
Joined: 2015/08/17 12:41

Re: Enum型の出力スロットを作成する方法

Post by caitsithware »

作成できたとのことで良かったです。

もしよろしければ、評価やレビューもお願いいたします。
Arbor 3: FSM & BT Graph Editor
Post Reply