[Unity插件]Behavior Designer:SharedVariable与GlobalVariable

设置SharedVariable与GlobalVariable:

[Unity插件]Behavior Designer:SharedVariable与GlobalVariable_第1张图片

上面的SharedV是SharedVariable,变量范围是当前行为树;

下面的GlobalV是GlobalVariable,变量范围是所有的行为树。


Shared变量与普通变量的区别:

Shared变量是对普通变量的进一步封装。Shared变量可以引用Variables面板上面设置的变量(即SharedVariable),同时也可以引用GlobalVariable面板上面设置的变量(即GlobalVariable)。如果同一个物体被多个节点引用,则可以将该物体设置为SharedVariable或者GlobalVariable。

using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityGameObject
{
    [TaskCategory("Basic/GameObject")]
    [TaskDescription("测试SharedGameObject")]
    public class Task1 : Conditional
    {
        public SharedGameObject sharedGameObject;      
        public GameObject a;
        public SharedProperty sharedProperty;
    }
}
[Unity插件]Behavior Designer:SharedVariable与GlobalVariable_第2张图片

[Unity插件]Behavior Designer:SharedVariable与GlobalVariable_第3张图片


自定义SharedVariable类型:

using UnityEngine;

public class Property : MonoBehaviour {

    public int nowHp = 100;
    public int maxHp = 100;

}

using UnityEngine;
using System.Collections;

namespace BehaviorDesigner.Runtime
{
    [System.Serializable]
    public class SharedProperty : SharedVariable
    {
        public Property Value { get { return mValue; } set { mValue = value; } }
        [SerializeField]
        private Property mValue;

        public override object GetValue() { return mValue; }
        public override void SetValue(object value) { mValue = (Property)value; }

        public override string ToString() { return (mValue == null ? "null" : mValue.name); }
        public static implicit operator SharedProperty(Property value) { var sharedVariable = new SharedProperty(); sharedVariable.SetValue(value); return sharedVariable; }
    }
}
[Unity插件]Behavior Designer:SharedVariable与GlobalVariable_第4张图片
[Unity插件]Behavior Designer:SharedVariable与GlobalVariable_第5张图片



你可能感兴趣的:(Designer,behavior)