// this lambda needs to be passed to pattern being executed (to constrain position to totem radius) //Func<Vector3, Vector3> GetDestinationInTotem() //{ // Func<Vector3, Vector3> fn = (v) => // { // if (!localTotem) // { // return v; // } // Vector3 totemPos = localTotem.transform.position; // float destinationDist = Vector3.Distance(totemPos, v); // if (destinationDist > localTotem.radius) // { // // position + direction.normalized * radius 0 shortens destination to point on totem radius // return totemPos + (v - totemPos).normalized * localTotem.radius; // } // return v; // }; // return fn; //} // Wrapper Method that allocates data to each of the AI Modes - Conditions for // execution are defined at the top of each respective Mode class public void MakeDecisionFrom(SenseMemoryFactory.SMData senseData) { // SelectMany() makes 1 list out of all the pattern lists (derived/transformed from deciders) that pass the condition (based on SMData) //List<Pattern> relevantPatterns = deciders.SelectMany(d => d.DeciderBasedOn(data)).ToList(); Decider relevantDecider = null; Pattern pattern = null; // run each decider through it's bool test for relevence based on senses foreach (Decider d in deciders) { if (d.DeciderBasedOn(senseData) != null) { relevantDecider = d; break; } } if (relevantDecider != null) { // tell decider to run specific conditions to choose one of it's patterns pattern = relevantDecider.ChoosePattern(senseData); } else { Debug.Log("No relevant Decider chosen! (MakeDecisionFrom() method)"); return; } //Pattern pattern = pM.SelectPattern(relevantPatterns); if (pattern) { pM.TryExecutePattern(pattern, senseData); } //TurnOffDecidersBasedOn(pattern); }