/// <summary> /// Callback from InternalAPIAccess to process a single parameter. Hopefully this remains stable on API changes. /// </summary> /// <param name="t">Type of parameter in our representation.</param> /// <param name="item">Raw parameter name.</param> /// <param name="defaultValue">Default value.</param> public void ProcessAnimatorParameter(AnimatorParameterType t, string item, string defaultValue) { string propName = CodeGenerationUtils.GeneratePropertyName(config.ParameterPrefix, item); string getterName = "Get" + propName; string setterName = "Set" + propName; string fieldName = CodeGenerationUtils.GeneratePropertyName(config.ParameterHashPrefix, item); fieldName = fieldName.FirstCharToLower(); VoidMethodCodeElement setterMethod = new VoidMethodCodeElement(setterName); GenericMethodCodeElement getterMethod = null; GenericFieldCodeElement field = new FieldCodeElement <int> (fieldName, "" + Animator.StringToHash(item)); field.ReadOnly = true; if (t == AnimatorParameterType.Bool) { getterMethod = new MethodCodeElement <bool> (getterName); getterMethod.Summary.Add("Access to boolean parameter " + item + ", default is: " + defaultValue + "."); getterMethod.Code.Add("return animator.GetBool (" + fieldName + ");"); setterMethod.Summary.Add("Set boolean value of parameter " + item + "."); setterMethod.Summary.Add("<param name=\"newValue\">New value for boolean parameter " + item + ".</param>"); setterMethod.AddParameter(typeof(bool), "newValue"); setterMethod.Code.Add("animator.SetBool (" + fieldName + ", newValue);"); } else if (t == AnimatorParameterType.Float) { getterMethod = new MethodCodeElement <float> (getterName); getterMethod.Summary.Add("Access to float parameter " + item + ", default is: " + defaultValue + "."); getterMethod.Code.Add("return animator.GetFloat (" + fieldName + ");"); setterMethod.Summary.Add("Set float value of parameter " + item + "."); setterMethod.Summary.Add("<param name=\"newValue\">New value for float parameter " + item + ".</param>"); setterMethod.AddParameter(typeof(float), "newValue"); setterMethod.Code.Add("animator.SetFloat (" + fieldName + ", newValue);"); // special case for float: provide setter with dampTime and deltaTime VoidMethodCodeElement methodExtended = new VoidMethodCodeElement(setterName); methodExtended.AddParameter(typeof(float), "newValue"); methodExtended.AddParameter(typeof(float), "dampTime"); methodExtended.AddParameter(typeof(float), "deltaTime"); methodExtended.Summary.Add("Set float parameter of " + item + " using damp and delta time ."); methodExtended.Summary.Add("<param name=\"newValue\">New value for float parameter " + item + ".</param>"); methodExtended.Summary.Add("<param name=\"dampTime\">The time allowed to parameter " + item + " to reach the value.</param>"); methodExtended.Summary.Add("<param name=\"deltaTime\">The current frame deltaTime.</param>"); methodExtended.Code.Add("animator.SetFloat (" + fieldName + ", newValue, dampTime, deltaTime);"); classCodeElement.Methods.Add(methodExtended); } else if (t == AnimatorParameterType.Int) { getterMethod = new MethodCodeElement <int> (getterName); getterMethod.Summary.Add("Access to integer parameter " + item + ", default is: " + defaultValue + "."); getterMethod.Code.Add("return animator.GetInteger (" + fieldName + ");"); setterMethod.Summary.Add("Set integer value of parameter " + item + "."); setterMethod.Summary.Add("<param name=\"newValue\">New value for integer parameter " + item + ".</param>"); setterMethod.AddParameter(typeof(int), "newValue"); setterMethod.Code.Add("animator.SetInteger (" + fieldName + ", newValue);"); } else if (t == AnimatorParameterType.Trigger) { setterMethod.Summary.Add("Activate trigger of parameter " + item + "."); setterMethod.Code.Add("animator.SetTrigger (" + fieldName + ");"); } else { Logger.Warning("Could not find type for param " + item + " as it seems to be no base type."); return; } classCodeElement.Methods.Add(setterMethod); if (getterMethod != null) { classCodeElement.Methods.Add(getterMethod); } field.Summary.Add("Hash of parameter " + item); classCodeElement.Fields.Add(field); }
/// <summary> /// Callback from InternalAPIAccess to process a single parameter. Hopefully this remains stable on API changes. /// </summary> /// <param name="t">Type of parameter in our representation.</param> /// <param name="item">Raw parameter name.</param> /// <param name="defaultValue">Default value.</param> public void ProcessAnimatorParameter (AnimatorParameterType t, string item, string defaultValue) { string propName = CodeGenerationUtils.GeneratePropertyName (config.ParameterPrefix, item); string getterName = "Get" + propName; string setterName = "Set" + propName; string fieldName = CodeGenerationUtils.GeneratePropertyName (config.ParameterHashPrefix, item); fieldName = fieldName.FirstCharToLower (); VoidMethodCodeElement setterMethod = new VoidMethodCodeElement (setterName); GenericMethodCodeElement getterMethod = null; GenericFieldCodeElement field = new FieldCodeElement<int> (fieldName, "" + Animator.StringToHash (item)); field.ReadOnly = true; if (t == AnimatorParameterType.Bool) { getterMethod = new MethodCodeElement<bool> (getterName); getterMethod.Summary.Add ("Access to boolean parameter " + item + ", default is: " + defaultValue + "."); getterMethod.Code.Add ("return animator.GetBool (" + fieldName + ");"); setterMethod.Summary.Add ("Set boolean value of parameter " + item + "."); setterMethod.Summary.Add ("<param name=\"newValue\">New value for boolean parameter " + item + ".</param>"); setterMethod.AddParameter (typeof (bool), "newValue"); setterMethod.Code.Add ("animator.SetBool (" + fieldName + ", newValue);"); } else if (t == AnimatorParameterType.Float) { getterMethod = new MethodCodeElement<float> (getterName); getterMethod.Summary.Add ("Access to float parameter " + item + ", default is: " + defaultValue + "."); getterMethod.Code.Add ("return animator.GetFloat (" + fieldName + ");"); setterMethod.Summary.Add ("Set float value of parameter " + item + "."); setterMethod.Summary.Add ("<param name=\"newValue\">New value for float parameter " + item + ".</param>"); setterMethod.AddParameter (typeof (float), "newValue"); setterMethod.Code.Add ("animator.SetFloat (" + fieldName + ", newValue);"); // special case for float: provide setter with dampTime and deltaTime VoidMethodCodeElement methodExtended = new VoidMethodCodeElement (setterName); methodExtended.AddParameter (typeof (float), "newValue"); methodExtended.AddParameter (typeof (float), "dampTime"); methodExtended.AddParameter (typeof (float), "deltaTime"); methodExtended.Summary.Add ("Set float parameter of " + item + " using damp and delta time ."); methodExtended.Summary.Add ("<param name=\"newValue\">New value for float parameter " + item + ".</param>"); methodExtended.Summary.Add ("<param name=\"dampTime\">The time allowed to parameter " + item + " to reach the value.</param>"); methodExtended.Summary.Add ("<param name=\"deltaTime\">The current frame deltaTime.</param>"); methodExtended.Code.Add ("animator.SetFloat (" + fieldName + ", newValue, dampTime, deltaTime);"); classCodeElement.Methods.Add (methodExtended); } else if (t == AnimatorParameterType.Int) { getterMethod = new MethodCodeElement<int> (getterName); getterMethod.Summary.Add ("Access to integer parameter " + item + ", default is: " + defaultValue + "."); getterMethod.Code.Add ("return animator.GetInteger (" + fieldName + ");"); setterMethod.Summary.Add ("Set integer value of parameter " + item + "."); setterMethod.Summary.Add ("<param name=\"newValue\">New value for integer parameter " + item + ".</param>"); setterMethod.AddParameter (typeof (int), "newValue"); setterMethod.Code.Add ("animator.SetInteger (" + fieldName + ", newValue);"); } else if (t == AnimatorParameterType.Trigger) { setterMethod.Summary.Add ("Activate trigger of parameter " + item + "."); setterMethod.Code.Add ("animator.SetTrigger (" + fieldName + ");"); } else { Logger.Warning ("Could not find type for param " + item + " as it seems to be no base type."); return; } classCodeElement.Methods.Add (setterMethod); if (getterMethod != null) { classCodeElement.Methods.Add (getterMethod); } field.Summary.Add ("Hash of parameter " + item); classCodeElement.Fields.Add (field); }