Esempio n. 1
0
        internal void InitialiseWithConfiguration(AssetListConfiguration configuration)
        {
            rootVisualElement.Clear();

            bool changedConfiguration = this.configuration != configuration;

            this.configuration = configuration;
            objects            = AssetListUtility.LoadAssetsByTypeName(configuration.TypeString, out type, out isComponent, configuration.AssetContext);
            GUIContent objectContent = EditorGUIUtility.ObjectContent(null, type);

            titleContent = new GUIContent(configuration.name, objectContent.image);

            if (treeViewState == null)
            {
                treeViewState = new TreeViewState();
            }

            var headerState = new MultiColumnHeaderState(GetColumnsFromConfiguration(configuration));

            if (MultiColumnHeaderState.CanOverwriteSerializedFields(multiColumnHeaderState, headerState))
            {
                MultiColumnHeaderState.OverwriteSerializedFields(multiColumnHeaderState, headerState);
            }

            if (changedConfiguration)
            {
                initialisedSizes       = false;
                multiColumnHeaderState = headerState;
            }

            var multiColumnHeader = new MultiColumnHeader(headerState);

            treeView = new MultiColumnTreeView(treeViewState, multiColumnHeader, this);

            (StyleSheet styleSheet, VisualTreeAsset uxml) = StyleExtensions.GetStyleSheetAndUXML("AssetList");
            uxml.CloneTree(rootVisualElement);
            rootVisualElement.styleSheets.Add(styleSheet);

            var    toolbarSearchField = rootVisualElement.Q <ToolbarSearchField>("SearchField");
            string searchString       = treeView.searchString;

            if (searchString != null)
            {
                toolbarSearchField.SetValueWithoutNotify(treeView.searchString);
            }
            toolbarSearchField.RegisterValueChangedCallback(evt => treeView.searchString = evt.newValue);

            var toolbarMenu = rootVisualElement.Q <ToolbarMenu>("ExportMenu");

            toolbarMenu.menu.AppendAction("TSV", action => ExportToTSV());

            assetListContainer = rootVisualElement.Q <IMGUIContainer>("AssetList");
            assetListContainer.onGUIHandler = MultiColumnListGUI;
        }
Esempio n. 2
0
        private static Func <SerializedProperty, SerializedProperty> GetArrayPropertyLookup(AssetListConfiguration.ArrayData propInfo)
        {
            Func <SerializedProperty, SerializedProperty> getProperty;
            string arrayPropertyPath = propInfo.ArrayPropertyPath;

            switch (propInfo.ArrayIndexing)
            {
            case ArrayIndexing.First:
                getProperty = arrayProperty =>
                {
                    if (arrayProperty.arraySize == 0)
                    {
                        return(null);
                    }
                    SerializedProperty element = arrayProperty.GetArrayElementAtIndex(0);
                    return(element?.FindPropertyRelative(arrayPropertyPath));
                };
                break;

            case ArrayIndexing.ByKey:
                Regex  regex            = new Regex(propInfo.ArrayQuery);
                string arrayPropertyKey = propInfo.ArrayPropertyKey;
                getProperty = arrayProperty =>
                {
                    if (arrayProperty == null)
                    {
                        return(null);
                    }
                    for (int i = 0; i < arrayProperty.arraySize; i++)
                    {
                        SerializedProperty property = arrayProperty.GetArrayElementAtIndex(i);
                        SerializedProperty key      = property.FindPropertyRelative(arrayPropertyKey);

                        string keyForRegex = AssetListUtility.GetValueForRegex(key);
                        if (!regex.IsMatch(keyForRegex))
                        {
                            continue;
                        }

                        return(property.FindPropertyRelative(arrayPropertyPath));
                    }

                    return(null);
                };
                break;

            case ArrayIndexing.ByIndex:
                int index = propInfo.ArrayIndex;
                getProperty = arrayProperty =>
                {
                    if (arrayProperty.arraySize <= index)
                    {
                        return(null);
                    }
                    SerializedProperty element = arrayProperty.GetArrayElementAtIndex(index);
                    return(element?.FindPropertyRelative(arrayPropertyPath));
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(getProperty);
        }