コード例 #1
0
        private void AddMissingConverters(SerializedProperty arrayProperty, IEnumerable <Type> converterTypes, bool newAreEnabledByDefault)
        {
            var elements     = EnumerateArrayElements(arrayProperty);
            var elementTypes = elements
                               .Select(e => TypeCache.FindType(e.FindPropertyRelative(nameof(ConverterConfig.converterName)).stringValue))
                               .ToArray();

            Type[] missingConverters = converterTypes
                                       .Where(type => !elementTypes.Contains(type))
                                       .ToArray();

            foreach (Type converterType in missingConverters)
            {
                int nextIndex = arrayProperty.arraySize;
                arrayProperty.InsertArrayElementAtIndex(nextIndex);
                SerializedProperty elemProp = arrayProperty.GetArrayElementAtIndex(nextIndex);

                SerializedProperty enabledProp       = elemProp.FindPropertyRelative(nameof(ConverterConfig.enabled));
                SerializedProperty converterNameProp = elemProp.FindPropertyRelative(nameof(ConverterConfig.converterName));

                enabledProp.boolValue         = newAreEnabledByDefault;
                converterNameProp.stringValue = converterType.FullName;
            }
        }
コード例 #2
0
        private void FoldoutConvertersList(SerializedProperty property, AnimBool fadedAnim)
        {
            string displayName = $"{property.displayName} ({(property.arraySize == 0 ? "none found" : property.arraySize.ToString())})";

            EditorGUI.indentLevel++;
            property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, displayName, true);
            EditorGUI.indentLevel--;
            fadedAnim.target = property.isExpanded;

            if (EditorGUILayout.BeginFadeGroup(fadedAnim.faded))
            {
                EditorGUI.indentLevel++;

                var allConfigsWithType = EnumerateArrayElements(property)
                                         .Select(o => (
                                                     serializedProperty: o,
                                                     type: TypeCache.FindType(o.FindPropertyRelative(nameof(ConverterConfig.converterName)).stringValue)
                                                     ));

                foreach (var namespaceGroup in allConfigsWithType.GroupBy(o => GetTypeNamespace(o.type)))
                {
                    var groupLabel = new GUIContent {
                        tooltip = GetNamespaceTooltip(namespaceGroup),
                        text    = GetNamespaceHeader(namespaceGroup),
                    };
                    EditorGUILayout.LabelField(groupLabel, EditorStyles.boldLabel);

                    EditorGUI.indentLevel++;
                    foreach (var configWithType in namespaceGroup.OrderBy(o => o.type?.Name))
                    {
                        SerializedProperty enabledProp = configWithType.serializedProperty.FindPropertyRelative(nameof(ConverterConfig.enabled));
                        if (configWithType.type != null)
                        {
                            var toggleContent = new GUIContent {
                                text    = configWithType.type.Name,
                                tooltip = configWithType.type.AssemblyQualifiedName,
                            };

                            bool oldValue = enabledProp.boolValue;
                            enabledProp.boolValue = EditorGUILayout.ToggleLeft(toggleContent, enabledProp.boolValue);

                            if (oldValue != enabledProp.boolValue)
                            {
                                _isDirty = true;
                            }
                        }
                        else
                        {
                            if (enabledProp.boolValue)
                            {
                                enabledProp.boolValue = false;
                            }

                            SerializedProperty converterNameProp = configWithType.serializedProperty.FindPropertyRelative(nameof(ConverterConfig.converterName));
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.ToggleLeft($"Unkown type: {converterNameProp.stringValue}", false);
                            EditorGUI.EndDisabledGroup();
                        }
                    }
                    EditorGUI.indentLevel--;
                    EditorGUILayout.Space();
                }

                EditorGUI.indentLevel--;
            }

            EditorGUILayout.EndFadeGroup();
        }