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(); } }
private AssetBinder(AssetBinder parent) { mRunner = parent.mRunner; mAssetDeep = parent.mAssetDeep + 1; mLooper = new BehaviourLooper(mRunner); mSubAssets = new List <AssetBinder>(); }
protected virtual void OnDestroy() { if (mAssetBinder != null) { mAssetBinder.Dispose(); mAssetBinder = null; } }
public static AssetBinder GetBinder(BehaviourTreeRunner runner) { if (runner == null) { return(null); } if (runner.mAssetBinder == null || !runner.mAssetBinder.IsAvailable) { var asset = new AssetBinder(runner); runner.mAssetBinder = asset; } return(runner.mAssetBinder); }
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(); } } }
public static AssetBinder NewSubBinder(AssetBinder binder) { if (binder == null || binder.mRunner == null) { return(null); } if (binder.DeepAsSubTree >= binder.Runner.MaxSubTreeDeep) { var error = string.Format("在创建子行为树是超过了支持的最大深度值:{0}", binder.Runner.MaxSubTreeDeep); #if UNITY_EDITOR UnityEditor.EditorUtility.DisplayDialog("Error", error, "OK"); #endif RTLog.LogError(LogCat.AI, error); return(null); } var subbind = new AssetBinder(binder); subbind.mParent = binder; binder.mSubAssets.Add(subbind); return(subbind); }
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 Dispose() { Cleanup(); var tmp = mSubAssets; mSubAssets = null; for (int i = 0; i < tmp.Count; i++) { tmp[i].mParent = null; } if (mParent != null && mParent.mSubAssets != null) { mParent.mSubAssets.Remove(this); mParent = null; } if (mLooper != null) { mLooper.Dispose(); } mLooper = null; mRunner = null; }
public void Reset() { if (runner != null && tree == null) { tree = runner.SourceAsset; } if (tree != null) { runtimeBinder = runner == null ? null : runner.GetBinder(tree); if (tmpAsset == null) { tmpAsset = tree.Clone(); } else { tree.EditorMergeTo(null, tmpAsset); } 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(); } }
public void SetAsset(BehaviourTreeAsset behaviourAsset) { var bind = AssetBinder.GetBinder(this); bind.BindAsset(behaviourAsset, m_LoopMode); }