设置SharedVariable与GlobalVariable:
上面的SharedV是SharedVariable,变量范围是当前行为树;
下面的GlobalV是GlobalVariable,变量范围是所有的行为树。
SharedVariable与普通变量的区别:
SharedVariable可以引用上面设置的变量,省去了拖拽的操作,如果同一个物体被多个节点引用,则可以将该物体设置为SharedVariable
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; } }
自定义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
原文地址:http://blog.csdn.net/lyh916/article/details/45477147