コード例 #1
0
        // Adds or removes a parameter based on the enabled boolean.
        public void UpdateParameter(AnimatorControllerParameter parameter, bool enabled)
        {
            if (parameter.type == AnimatorControllerParameterType.Int || parameter.type == AnimatorControllerParameterType.Float || parameter.type == AnimatorControllerParameterType.Bool)
            {
                List <Parameter> param             = new List <Parameter>(_avatar.expressionParameters.parameters);
                bool             somethingModified = false;
                if (enabled)
                {
                    param.Add(new Parameter
                    {
                        name         = parameter.name,
                        valueType    = AV3ManagerFunctions.GetValueTypeFromAnimatorParameterType(parameter.type),
                        defaultValue = 0,
                        saved        = false
                    });
                    somethingModified = true;
                }
                else
                {
                    for (int i = 0; i < param.Count; i++)
                    {
                        if (!param[i].name.Equals(parameter.name))
                        {
                            continue;
                        }
                        param.RemoveAt(i);
                        somethingModified = true;
                    }
                }

                if (somethingModified)
                {
                    _avatar.expressionParameters.parameters = param.ToArray();
                    foreach (var layer in _layers)
                    {
                        layer.UpdateParameterList();
                    }
                }
                EditorUtility.SetDirty(_avatar.expressionParameters);
            }
            UsedParameterMemory = _avatar.expressionParameters.CalcTotalCost();
        }
コード例 #2
0
        public void CleanupParametersList()
        {
            var syncedParameters = _layers?.SelectMany(x => x.Parameters)
                                   .Where(x => x.Item2)
                                   .Select(x => x.Item1)
                                   .ToArray();

            if (_useDefaultParameters)
            {
                syncedParameters = (syncedParameters ?? Array.Empty <AnimatorControllerParameter>()).Append(new AnimatorControllerParameter {
                    name = "VRCEmote", type = AnimatorControllerParameterType.Int, defaultInt = 0
                })
                                   .Append(new AnimatorControllerParameter {
                    name = "VRCFaceBlendH", type = AnimatorControllerParameterType.Float, defaultFloat = 0
                })
                                   .Append(new AnimatorControllerParameter {
                    name = "VRCFaceBlendV", type = AnimatorControllerParameterType.Float, defaultFloat = 0
                })
                                   .ToArray();
            }

            var param     = new List <Parameter>(_avatar.expressionParameters.parameters);
            var remaining = new List <Parameter>(param);

            bool somethingModified = false;

            foreach (var parameter in param)
            {
                bool toDelete = syncedParameters?.All(syncedParameter => !parameter.name.Equals(syncedParameter.name)) ?? false;

                if (!toDelete)
                {
                    continue;
                }
                remaining.Remove(parameter);
                somethingModified = true;
            }

            foreach (var syncedParameter in syncedParameters)
            {
                bool toAdd = param.All(parameter => !parameter.name.Equals(syncedParameter.name));
                if (!toAdd)
                {
                    continue;
                }
                remaining.Add(new Parameter
                {
                    name         = syncedParameter.name,
                    valueType    = AV3ManagerFunctions.GetValueTypeFromAnimatorParameterType(syncedParameter.type),
                    defaultValue = 0,
                    saved        = false
                });
                somethingModified = true;
            }

            if (!somethingModified)
            {
                return;
            }

            _avatar.expressionParameters.parameters = remaining.ToArray();
            EditorUtility.SetDirty(_avatar.expressionParameters);
            UsedParameterMemory = _avatar.expressionParameters.CalcTotalCost();
        }