码迷,mamicode.com
首页 > 编程语言 > 详细

[Unity插件]Behavior Designer:SharedVariable与GlobalVariable

时间:2015-05-04 12:03:30      阅读:643      评论:0      收藏:0      [点我收藏+]

标签:behavior designer

设置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

标签:behavior designer

原文地址:http://blog.csdn.net/lyh916/article/details/45477147

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!