public void SetBehaviourTreeAsset(BehaviourTreeAsset asset)
        {
            if (asset == tree)
            {
                return;
            }
            if (tmpAsset != null)
            {
                BehaviourTreeAsset.DestroyAsset(tmpAsset, true);
                tmpAsset = null;
            }
            tree = asset;
            var bind = runner == null || asset == null ? null : runner.GetBinder(asset);

            if (bind != null)
            {
                runner = bind.Runner;
            }
            runtimeBinder = bind;
            if (tree != null)
            {
                tmpAsset = tree.Clone();
            }
            if (updateTreeAsset != null)
            {
                updateTreeAsset();
            }
        }
 public void Dispose()
 {
     if (tmpAsset != null)
     {
         BehaviourTreeAsset.DestroyAsset(tmpAsset, true);
         tmpAsset = null;
     }
     runner = null;
     tree   = null;
     EditorApplication.playModeStateChanged -= OnPlayModeChanged;
 }
        public void SetBehaviourTreeRunner(BehaviourTreeRunner runner)
        {
            if (runner == null)
            {
                this.runner        = null;
                this.runtimeBinder = null;
                return;
            }
            if (this.runner == null)
            {
                this.runner = null;
            }
            var asset = runner == null ? tree : runner.SourceAsset;

            if (asset == null)
            {
                asset = tree;
            }
            var bind = runner == null ? null : runner.GetBinder(asset);

            if (asset == tree && this.runner == runner && runtimeBinder == bind)
            {
                return;
            }
            this.runner   = runner;
            this.tree     = asset;
            runtimeBinder = bind;
            if (tmpAsset != null)
            {
                BehaviourTreeAsset.DestroyAsset(tmpAsset, true);
                tmpAsset = null;
            }
            if (tree != null)
            {
                if (tree != null)
                {
                    tmpAsset = tree.Clone();
                }
                if (updateTreeAsset != null)
                {
                    updateTreeAsset();
                }
            }
        }
 private void OnPlayModeChanged(PlayModeStateChange stat)
 {
     if (stat == PlayModeStateChange.EnteredPlayMode || stat == PlayModeStateChange.EnteredEditMode)
     {
         if (runner == null)
         {
             runner = null;
         }
         if (tree == null)
         {
             tree = null;
         }
         if (tmpAsset != null)
         {
             BehaviourTreeAsset.DestroyAsset(tmpAsset, true);
             tmpAsset = null;
         }
         if (tree == null)
         {
             if (SetSelectedAsset())
             {
                 return;
             }
         }
         else
         {
             var go    = Selection.activeGameObject;
             var tmpru = go == null ? null : go.GetComponent <BehaviourTreeRunner>();
             if (tmpru != null && tmpru.SourceAsset == tree)
             {
                 runner = tmpru;
             }
         }
         runtimeBinder = runner == null ? null : runner.ActiveBinder;
         if (updateTreeAsset != null)
         {
             updateTreeAsset();
         }
     }
 }
 public void SetBehaviourBinder(AssetBinder binder)
 {
     if (binder == null || runtimeBinder == binder)
     {
         return;
     }
     if (tmpAsset != null)
     {
         BehaviourTreeAsset.DestroyAsset(tmpAsset, true);
         tmpAsset = null;
     }
     runner        = binder.Runner;
     tree          = binder.Source;
     runtimeBinder = binder;
     if (tree != null)
     {
         tmpAsset = tree.Clone();
     }
     if (updateTreeAsset != null)
     {
         updateTreeAsset();
     }
 }