/// <summary> /// Get the ChainBehavior by Index /// </summary> /// <param name="index"></param> /// <returns></returns> ChainBehavior GetChainBehavior(int index) { int nextChainBehaviorIndex = model.chainBehaviors[model.currentChainIndex].followUps[index]; ChainBehavior nextChainBehavior = model.chainBehaviors[nextChainBehaviorIndex]; return(nextChainBehavior); }
/// <summary> /// Return a bool to determine if meet the next behavior's condition /// </summary> /// <returns></returns> bool CanStartNextBehavior() { if (model.chainBehaviors.Count == 0 || model.chainBehaviors == null) { Debug.LogError("There is no chain connection in your behaivor, please create chain connection by using ChainEditor"); return(false); } // by default set to Default if (model.currentChainIndex >= model.chainBehaviors.Count) { model.currentChainIndex = 0; } int currentPriority = -1; for (int f = 0; f < model.chainBehaviors[model.currentChainIndex].followUps.Count; f++) { ChainBehavior nextChainBehavior = GetChainBehavior(f); ActorBehavior exceptedBehavior = nextChainBehavior.behavior; // Check Input buffer if (GameManager_Input.Instance.bufferKeys.Any(p => p == exceptedBehavior.inputKey || p == exceptedBehavior.altInputKey)) // todo maybe add key combo and motion input buffer { // the behaviors will have certain requirements if (exceptedBehavior.MetRequirements(model)) { // Update the current priority level if (UpdatePriorityLevel(nextChainBehavior.priority, ref currentPriority)) { // if there is no followups, then go to the index 1 which is Default behavior model.currentChainIndex = (nextChainBehavior.followUps.Count > 0) ? nextChainBehavior.idIndex : 0; //nextBehavior = model.GetBehavior(nextInputInfo.behaviorIndex); nextBehavior = model.GetBehavior(exceptedBehavior.name); return(true); } } } } return(false); }