//Happens every frame in Edit mode. //Uses transform.position of the units to approximate what they would do in Play mode with the NavMeshAgent private void ProcessEditModeFrame(Playable playable) { previousInputFinalPositions = defaultPositions; int inputCount = playable.GetInputCount(); int unitCount = trackBinding.units.Count; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <AICommandBehaviour> inputPlayable = (ScriptPlayable <AICommandBehaviour>)playable.GetInput(i); AICommandBehaviour input = inputPlayable.GetBehaviour(); //Some actionTypes have special needs switch (input.commandType) { case AICommand.CommandType.Die: case AICommand.CommandType.Stop: //Do nothing if it's a Die or Stop action continue; //Will skip to the next input clip in the for loop above case AICommand.CommandType.AttackTarget: //Force the finalPosition to the attack target in case of an Attack action if (input.targetUnit != null) { input.targetPosition = input.targetUnit.transform.position; } break; } //Create an array of final positions for the entire Platoon finalPositions = trackBinding.GetFormationPositions(input.targetPosition); if (inputWeight > 0f) { double progress = inputPlayable.GetTime() / inputPlayable.GetDuration(); newPositions = new Vector3[unitCount]; for (int j = 0; j < unitCount; j++) { newPositions[j] = Vector3.Lerp(previousInputFinalPositions[j], finalPositions[j], (float)progress); } trackBinding.SetPositions(newPositions); continue; } else { previousInputFinalPositions = finalPositions; //cached to act as initial position for the next input } } }