public override string GenerateCode(Object obj) { var navAgent = "navAgent".ToVariableName(this); var targetPos = "targetPos".ToVariableName(this); string result = null; result += CodeGenerator.GenerateVariableDeclaration(navAgent, typeof(NavMeshAgent), agent); result += CodeGenerator.GenerateVariableDeclaration(targetPos, typeof(Vector3), target.Access("transform", "position"), false).AddLineInFirst(); { //While var fleePos = "fleePos".ToVariableName(this); string fleePosContents = targetPos.AddOperation(navAgent.Access("transform", "position").SubtractOperation(targetPos).Wrap().Access("normalized")); fleePosContents = fleePosContents.MultiplyOperation( fledDistance.ToCode().AddOperation(lookAhead.ToCode()).AddOperation(navAgent.Access("stoppingDistance")).Wrap()); string contents = CodeGenerator.GenerateVariableDeclaration(fleePos, typeof(Vector3), fleePosContents, false); contents += CodeGenerator.GenerateIfStatement( navAgent.InvokeCode("SetDestination", fleePos).RemoveSemicolon().Wrap(), CodeGenerator.GenerateBreak()).AddLineInFirst() + CodeGenerator.GenerateYieldReturn(null).AddLineInFirst(); result += CodeGenerator.GenerateCondition("while", CodeGenerator.GenerateArithmetiCode( navAgent.Access("transform", "position"), targetPos, ArithmeticType.Subtract).Wrap(). Access("magnitude"). Compare( fledDistance.ToCode(), ComparisonType.GreaterThanOrEqual), contents).AddLineInFirst(); } return(result); }
public override string GenerateCode(Object obj) { string data = null; if (vector3Variable.isAssigned) { if (storeX.isAssigned) { data += CodeGenerator.GenerateSetCode(storeX.ParseValue(), vector3Variable.Access("x")); } if (storeY.isAssigned) { data += CodeGenerator.GenerateSetCode(storeY.ParseValue(), vector3Variable.Access("y")); } if (storeZ.isAssigned) { data += CodeGenerator.GenerateSetCode(storeZ.ParseValue(), vector3Variable.Access("z")); } } return(data); }