MonoBehaviourを継承したクラスのFlexibleField

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を確認の上、それでも使い方がわからない場合にご質問ください。欲しい機能の記載がドキュメントにない場合は機能が元から存在しない可能性が高いので要望フォーラムへ。

Post a reply

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: MonoBehaviourを継承したクラスのFlexibleField

Re: MonoBehaviourを継承したクラスのFlexibleField

by caitsithware » 2018/06/20 14:25

ご質問ありがとうございます。

FlexibleFieldについては、Serializable属性をつけた非Unityオブジェクトクラスを扱うためのクラスとなっています。
そのため、MonoBehaviourの継承クラスへの使用は想定しておりませんでした。
(Contant値を扱うために内部的にnew T()しており、今回TがMonoBehaviourだったためUnityが警告を出した、ということになります)

自作コンポーネントへの参照方法ですが、FlexibleComponentとSlotTypeAttributeを使用することで可能です。

【TestStateBehaviourScript.cs】

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Arbor;

[AddComponentMenu("")]
public class TestStateBehaviourScript : StateBehaviour {
    [SlotType(typeof(Test))]
    public FlexibleComponent test;

}
スクリプトリファレンス : FlexibleComponent
スクリプトリファレンス : SlotTypeAttribute

このあたりの詳細がドキュメントになかったので修正いたします。

MonoBehaviourを継承したクラスのFlexibleField

by kudou » 2018/06/20 13:58

unity 2018.1.0 f2
Arbor3.1.2

MonoBehaviourを継承したクラスのFlexibleFieldを使用すると警告が出力されます。
こういった使い方は問題ありますでしょうか?

You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()
Test:.ctor()
System.Activator:CreateInstance()
Arbor.FlexibleField`1:.ctor() (at Assets/Plugins/Arbor/Internal/Scripts/FlexibleField.cs:42)
FlexibleTest:.ctor()

手順
①下記のコードを作成
②ArborFSMをもつGameObjectを作成
③ステートを作成してTestStateBehaviourScriptの挙動を追加する
④UnityEditorを再生する

【TestVariable.cs】

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Arbor;

[System.Serializable]
public class Test : MonoBehaviour
{
	// Declare Serialize Fields
}

[System.Serializable]
public class FlexibleTest : FlexibleField<Test>
{
}
【TestStateBehaviourScript.cs】

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Arbor;

[AddComponentMenu("")]
public class TestStateBehaviourScript : StateBehaviour {

    public FlexibleTest test;

}

Top