private static void LegacyRemoval(VRCExpressionParameters expressionParameters)
        {
            var legacyParamA = expressionParameters.FindParameter("J1I7T_A_Sync");
            var legacyParamB = expressionParameters.FindParameter("J1I7T_B_Sync");

            if (legacyParamA != null || legacyParamB != null)
            {
                EditorGUILayout.LabelField("Legacy", EditorStyles.boldLabel);
                if (legacyParamA != null)
                {
                    EditorGUILayout.HelpBox("Your avatar has an Expression Parameter with name J1I7T_A_Sync. It is no longer used.", MessageType.Error);
                }

                if (legacyParamB != null)
                {
                    EditorGUILayout.HelpBox("Your avatar has an Expression Parameter with name J1I7T_B_Sync. It is no longer used.", MessageType.Error);
                }

                if (GUILayout.Button("Fix: Remove legacy Expression Parameters"))
                {
                    expressionParameters.parameters = expressionParameters.parameters
                                                      .Where(parameter => parameter.name != "J1I7T_A_Sync")
                                                      .Where(parameter => parameter.name != "J1I7T_B_Sync")
                                                      .ToArray();
                    ForceSaveAsset(expressionParameters);
                }
            }
        }
 public static IEnumerable <string> CheckWarnings(VRCExpressionsMenu menu, VRCExpressionParameters param)
 {
     return(from paramName in GetParams(GetMenus(menu))
            let isDefined = string.IsNullOrEmpty(paramName) || param.FindParameter(paramName) != null
                            where !isDefined
                            select "Menu uses a parameter that is not defined: " + paramName);
 }
        public static VRCExpressionParameters.Parameter AddVRCExpressionsParameter(VRCAvatarDescriptor avatarDescriptor, VRCExpressionParameters.ValueType type, string name, List <Object> dirtyAssets)
        {
            VRCExpressionParameters parameters = avatarDescriptor.expressionParameters;

            VRCExpressionParameters.Parameter parameter = parameters.FindParameter(name);

            if (parameter == null)
            {
                var list = parameters.parameters.Where(e => e != null && !string.IsNullOrEmpty(e.name)).ToList();
                parameter = new VRCExpressionParameters.Parameter
                {
                    name      = name,
                    valueType = type,
                };
                list.Add(parameter);
                parameters.parameters = list.ToArray();
            }

            dirtyAssets.Add(parameters);
            dirtyAssets.Add(avatarDescriptor.gameObject);
            return(parameter);
        }
Beispiel #4
0
 public static bool HasParameter(this VRCExpressionParameters obj, string name)
 {
     return(obj.FindParameter(name) != null);
 }
Beispiel #5
0
 public static bool HasParameter(this VRCExpressionParameters source, string name)
 {
     return(source.FindParameter(name) != null);
 }
        /// <summary>
        /// Creates a copy of the avatar descriptor's parameter asset or creates one if it doesn't exist, adds a provided parameter,
        /// assigns the new parameter asset, and stores it in the specified directory.
        /// </summary>
        /// <param name="descriptor">The avatar descriptor to add the parameter to.</param>
        /// <param name="parameter">The parameter to add.</param>
        /// <param name="directory">The unique directory to store the new parameter asset, ex. "Assets/MyCoolScript/GeneratedAssets/725638/".</param>
        /// <param name="overwrite">Optionally, choose to not overwrite an asset of the same name in directory. See class for more info.</param>
        public static void AddParameter(VRCAvatarDescriptor descriptor, VRCExpressionParameters.Parameter parameter, string directory, bool overwrite = true)
        {
            if (descriptor == null)
            {
                Debug.LogError("Couldn't add the parameter, the avatar descriptor is null!");
                return;
            }
            else if ((parameter == null) || (parameter.name == null))
            {
                Debug.LogError("Couldn't add the parameter, it or its name is null!");
                return;
            }
            else if ((directory == null) || (directory == ""))
            {
                Debug.Log("Directory was not specified, storing new parameters asset in " + defaultDirectory);
                directory = defaultDirectory;
            }

            descriptor.customExpressions = true;
            VRCExpressionParameters parameters = ScriptableObject.CreateInstance <VRCExpressionParameters>();

            parameters.parameters = new VRCExpressionParameters.Parameter[0];

            if (descriptor.expressionParameters == null)
            {
                AssetDatabase.CreateAsset(parameters, directory + "Parameters.asset");
            }
            else
            {
                if ((descriptor.expressionParameters.CalcTotalCost() + VRCExpressionParameters.TypeCost(parameter.valueType)) > VRCExpressionParameters.MAX_PARAMETER_COST)
                {
                    Debug.LogError("Couldn't add parameter '" + parameter.name + "', not enough memory free in the avatar's parameter asset!");
                    return;
                }

                string path = (directory + descriptor.expressionParameters.name + ".asset");
                path = (overwrite) ? path : AssetDatabase.GenerateUniqueAssetPath(path);
                if (AssetDatabase.GetAssetPath(descriptor.expressionParameters) != path) // if we have not made a copy yet
                {                                                                        // CopyAsset with two identical strings yields exception
                    AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(descriptor.expressionParameters), path);
                }
                parameters = AssetDatabase.LoadAssetAtPath(path, typeof(VRCExpressionParameters)) as VRCExpressionParameters;
            }

            if (parameters.FindParameter(parameter.name) == null)
            {
                int count = parameters.parameters.Length;
                VRCExpressionParameters.Parameter[] parameterArray = new VRCExpressionParameters.Parameter[count + 1];
                for (int i = 0; i < count; i++)
                {
                    parameterArray[i] = parameters.GetParameter(i);
                }
                parameterArray[count] = parameter;
                parameters.parameters = parameterArray;
            }

            EditorUtility.SetDirty(parameters);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            descriptor.expressionParameters = parameters;
        }