示例#1
0
 public PropertyData(AssetListConfiguration configuration, SerializedProperty property)
 {
     Type              = property.propertyType;
     IsArray           = property.isArray;
     IsInConfiguration = configuration.Columns != null &&
                         configuration.Columns.Any(c => c.PropertyPath.Equals(property.propertyPath));
 }
示例#2
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;
        }
示例#3
0
        /// <summary>
        /// Constructor for Path
        /// </summary>
        public ColumnContext(AssetListConfiguration configuration, AssetListWindow window)
        {
            configColumnIndex = -1;
            propertyPath      = null;
            propertyOverride  = PropertyOverride.Path;
            Texture persistent = EditorGUIUtility.IconContent("Project").image;
            Texture inScene    = EditorGUIUtility.ObjectContent(null, typeof(SceneAsset)).image;

            Texture GetIcon(Object o) => EditorUtility.IsPersistent(o) ? persistent : inScene;

            onGUI = (rect, sO, property) => PathLabelWithIcon(rect, sO, window, GetIcon);
        }
示例#4
0
        public ColumnContext(AssetListConfiguration c, NamePropertyDisplay nameDisplay, AssetListWindow window)
        {
            configColumnIndex = -1;
            propertyPath      = null;
            propertyOverride  = PropertyOverride.Name;
            Func <SerializedObject, SerializedProperty> getIconProperty = null;

            if (!string.IsNullOrEmpty(c.IconPropertyPath))
            {
                if (c.IconIsArray)
                {
                    AssetListConfiguration.ArrayData propInfo = c.IconArrayPropertyInformation;
                    Func <SerializedProperty, SerializedProperty> arrayLookup = GetArrayPropertyLookup(propInfo);
                    if (arrayLookup != null)
                    {
                        getIconProperty = context =>
                        {
                            SerializedProperty iconPath = context.FindProperty(c.IconPropertyPath);
                            return(arrayLookup?.Invoke(iconPath));
                        };
                    }
                }
                else
                {
                    getIconProperty = context => context.FindProperty(c.IconPropertyPath);
                }
            }

            switch (nameDisplay)
            {
            case NamePropertyDisplay.Label:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, GUI.Label);
                break;

            case NamePropertyDisplay.NicifiedLabel:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyNicifiedLabelProperty);
                break;

            case NamePropertyDisplay.CenteredLabel:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyCenteredLabelProperty);
                break;

            case NamePropertyDisplay.NicifiedCenteredLabel:
                onGUI = (rect, sO, property) => LargeObjectLabelWithPing(rect, sO, getIconProperty, window, ReadonlyNicifiedCenteredLabelProperty);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(nameDisplay), nameDisplay, null);
            }
        }
示例#5
0
        private void InitialiseWithoutConfiguration()
        {
            rootVisualElement.Clear();

            var data = StyleExtensions.GetStyleSheetAndUXML("BlankAssetList");

            data.Item2.CloneTree(rootVisualElement);
            rootVisualElement.styleSheets.Add(data.Item1);
            rootVisualElement.Q <DragAndDropBox>("DropTarget").RegisterSingle(CreateNewWindow);
            var container = rootVisualElement.Q <VisualElement>("ListViewContainer");

            AssetListConfiguration[] configurations = EditorUtils.LoadAssetsOfType <AssetListConfiguration>();
            if (configurations.Length == 0)
            {
                container.RemoveFromHierarchy();
            }
            else
            {
                var listView = container.Q <ListView>("ListView");
                foreach (AssetListConfiguration configAsset in configurations)
                {
                    var button = new Button(() => InitialiseWithConfiguration(configAsset))
                    {
                        text = configAsset.name
                    };
                    button.AddToClassList("listViewButton");
                    listView.Add(button);
                }
            }

            void CreateNewWindow(Object o)
            {
                AssetListConfiguration listConfiguration = CreateInstance <AssetListConfiguration>();

                listConfiguration.Configure(o);
                string name = o.GetType().Name;
                string path = EditorUtility.SaveFilePanelInProject($"Create New {name} List Configuration", $"{name} List", "asset", $"Save a Configuration asset for {name} List");

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
                AssetDatabase.CreateAsset(listConfiguration, path);
                InitialiseWithConfiguration(listConfiguration);
            }
        }
示例#6
0
        public static string GetString(SerializedProperty property, AssetListConfiguration configuration, AssetListConfiguration.ColumnConfiguration columnConfig)
        {
            switch (property.propertyType)
            {
            case SerializedPropertyType.Float:
                return(GetString(property.floatValue, columnConfig.NumericalDisplay));

            case SerializedPropertyType.Integer:
                return(GetString(property.intValue, columnConfig.NumericalDisplay));

            case SerializedPropertyType.Boolean:
                return(property.boolValue.ToString());

            case SerializedPropertyType.String:
                return(GetString(property.stringValue, columnConfig.StringDisplay));

            case SerializedPropertyType.ObjectReference:
                return(property.objectReferenceValue == null ? string.Empty : property.objectReferenceValue.name);

            case SerializedPropertyType.LayerMask:
                return(property.enumDisplayNames[property.intValue]);

            case SerializedPropertyType.Enum:
                return(property.enumDisplayNames[property.intValue]);

            case SerializedPropertyType.ArraySize:
                return(property.arraySize.ToString());

            case SerializedPropertyType.Character:
                return(property.stringValue);

            case SerializedPropertyType.Color:
                return(property.colorValue.ToString());

            case SerializedPropertyType.Vector2:
                return(property.vector2Value.ToString());

            case SerializedPropertyType.Vector3:
                return(property.vector3Value.ToString());

            case SerializedPropertyType.Vector4:
                return(property.vector4Value.ToString());

            case SerializedPropertyType.Quaternion:
                return(property.quaternionValue.eulerAngles.ToString());

            case SerializedPropertyType.FixedBufferSize:
                return(property.fixedBufferSize.ToString());

            case SerializedPropertyType.Vector2Int:
                return(property.vector2IntValue.ToString());

            case SerializedPropertyType.Vector3Int:
                return(property.vector3IntValue.ToString());

            case SerializedPropertyType.Rect:
                return(property.rectValue.ToString());

            case SerializedPropertyType.RectInt:
                return(property.rectIntValue.ToString());

            case SerializedPropertyType.Bounds:
                return(property.boundsValue.ToString());

            case SerializedPropertyType.BoundsInt:
                return(property.boundsIntValue.ToString());

            case SerializedPropertyType.ExposedReference:
                return(property.exposedReferenceValue.name);

            case SerializedPropertyType.Gradient:
                Gradient gradient = GetGradientValue(property);
                if (gradient == null)
                {
                    return(string.Empty);
                }
                StringBuilder sB                 = new StringBuilder(20);
                string        asciiGradient      = " .:-=+*#%@";
                int           gradientMultiplier = asciiGradient.Length - 1;
                for (int i = 0; i < 20; i++)
                {
                    float grayscale = 1 - gradient.Evaluate(i / 19f).grayscale;
                    sB.Append(asciiGradient[Mathf.Clamp(Mathf.RoundToInt(grayscale * gradientMultiplier), 0, gradientMultiplier)]);
                }
                return(sB.ToString());

            case SerializedPropertyType.AnimationCurve:
                return(property.animationCurveValue.ToString());

                                #if UNITY_2019_3_OR_NEWER
            case SerializedPropertyType.ManagedReference:
                                #endif
            case SerializedPropertyType.Generic:
            default:
                throw new ArgumentOutOfRangeException($"{property.propertyType} is not supported by {nameof(GetString)}");
            }

            Gradient GetGradientValue(SerializedProperty sp)
            {
                PropertyInfo propertyInfo = typeof(SerializedProperty).GetProperty(
                    "gradientValue",
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    null,
                    typeof(Gradient),
                    Array.Empty <Type>(),
                    null
                    );

                return(propertyInfo?.GetValue(sp, null) as Gradient);
            }
        }