/// <summary>
        /// Callback from InternalAPIAccess to process a single Animator state.
        /// </summary>
        /// <param name="layer">Layer index.</param>
        /// <param name="layerName">Layer name.</param>
        /// <param name="item">State name.</param>
        public void ProcessAnimatorState(StateInfo info)
        {
            string layerPrefix = (info.Layer > 0 || config.ForceLayerPrefix ? null : info.LayerName);
            string name        = CodeGenerationUtils.GenerateStateName(config.AnimatorStatePrefix, info.Name, layerPrefix);

            name = name.FirstCharToUpper();
            string fieldName = CodeGenerationUtils.GenerateStateName(config.AnimatorStateHashPrefix, info.Name, layerPrefix);

            fieldName = fieldName.FirstCharToLower();
            // field declaration
            GenericFieldCodeElement field = new GenericFieldCodeElement(typeof(int), fieldName, "" + info.Id);

            field.ReadOnly = true;
            field.Summary.Add("Hash of Animator state " + info.Name);
            classCodeElement.Fields.Add(field);
            string methodName = "Is" + name;
            // IsXXX method ()
            MethodCodeElement <bool> method = new MethodCodeElement <bool> (methodName);

            method.Origin = "state " + info.Name;
            method.Code.Add("return " + fieldName + " == animator.GetCurrentAnimatorStateInfo (" + info.Layer + ").nameHash" + ";");
            method.Summary.Add("true if the current Animator state of layer " + info.Layer + " is  \"" + info.Name + "\".");
            classCodeElement.Methods.Add(method);
            // overloaded IsXXX (int nameHash)
            MethodCodeElement <bool> methodWithLayerParameter = new MethodCodeElement <bool> (methodName);

            methodWithLayerParameter.Origin = "state " + info.Name;
            methodWithLayerParameter.AddParameter(typeof(int), "nameHash");
            methodWithLayerParameter.Code.Add("return nameHash == " + fieldName + ";");
            methodWithLayerParameter.Summary.Add("true if the given (state) nameHash equals Animator.StringToHash (\"" + info.Name + "\").");
            classCodeElement.Methods.Add(methodWithLayerParameter);
            // state dictionary is filled in overriden method InitialiseEventManager
            object [] parameters = new object[] { info.Id,
                                                  info.Layer,
                                                  info.LayerName,
                                                  info.Name,
                                                  info.Tag,
                                                  info.Speed,
                                                  info.FootIK,
                                                  info.Mirror,
                                                  info.Motion.Name,
                                                  info.Motion.Duration };
            string parameterList = CodeElementUtils.GetCallParameterString(parameters);

            EventManagerInitialiser.Code.Add(StateInfoDict + ".Add (" + info.Id + ", new StateInfo (" + parameterList + "));");
        }
Пример #2
0
        MetaInfo Get(BaseAnimatorAccess component)
        {
            var key = GetKey(component);

            if (!entries.ContainsKey(key))
            {
                string fileName       = key + ".cs";
                string backupFileName = key + ".txt";
                string file           = CodeGenerationUtils.GetPathToFile(fileName);
                string backupFile     = CodeGenerationUtils.GetPathToFile(backupFileName, backupDir);
                string timestamp      = "";
                if (!string.IsNullOrEmpty(backupFile))
                {
                    timestamp += File.GetCreationTime(backupFile);
                }
                entries [key] = new MetaInfo(file, backupFile, timestamp);
            }
            return(entries [key]);
        }
        /// <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);
        }