void HandleExternalBTDeserialization(Task taskObj) { if (taskObj is BehaviorTreeReference == false) { return; } BehaviorTreeReference callExternalBehaviorTree = taskObj as BehaviorTreeReference; string externalBTAssetName = callExternalBehaviorTree.taskParams.externalBTAssetName; if (string.IsNullOrEmpty(externalBTAssetName)) { return; } callExternalBehaviorTree.externalBTAsset = Resources.Load <BehaviorTreeAsset>("BTAssets/" + System.IO.Path.GetFileNameWithoutExtension(externalBTAssetName)); if (callExternalBehaviorTree.externalBTAsset == null) { Debug.LogError(string.Format("fail to find the asset file '{0}'", externalBTAssetName)); return; } if (Playing) { BehaviorTreeAsset tmp = ScriptableObject.Instantiate(callExternalBehaviorTree.externalBTAsset); //if (Application.isEditor) //{ tmp.MonitorAsset = callExternalBehaviorTree.externalBTAsset; //} if (tmp.Deserialize(taskObj.BT.Transform) == false) { Debug.LogError(string.Format("externalBTAsset {0} deserialization failure", externalBTAssetName)); return; } callExternalBehaviorTree.externalBTAsset = tmp; } }
void Awake() { if (_btAsset == null) { return; } BehaviorTreeAsset tmp = ScriptableObject.Instantiate <BehaviorTreeAsset>(_btAsset); //if (Application.isEditor) //{ tmp.MonitorAsset = _btAsset; //} if (tmp.Deserialize(transform) == false) { Debug.LogError(string.Format("deserialization failure."), this); return; } _btAsset = tmp; _btAsset.BT.OnAwake(); }