Example #1
0
 public static TagDatabaseAsset GetDatabase()
 {
     if (m_TagAsset == null)
     {
         m_TagAsset = AssetUtils.GetFirstOrCreate <TagDatabaseAsset>("TagDatabase");
     }
     return(m_TagAsset);
 }
        public void TagGUI()
        {
            var selectedPresets = serializedObject.targetObjects.Cast <ScreenshotResolutionAsset>().ToList();

            // Create tag
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Create tag", GUILayout.MaxWidth(100));
            newTag = EditorGUILayout.TextField(newTag);
            if (GUILayout.Button("Add", GUILayout.MaxWidth(40)))
            {
                foreach (var selected in selectedPresets)
                {
                    TagDatabaseAsset.AddTag((ScreenshotResolutionAsset)selected, newTag);
                }
            }
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.Separator();

            // Existing tags
            var tags = TagDatabaseAsset.GetAllTags();

            foreach (var tag in tags)
            {
                bool hasTag = TagDatabaseAsset.HasTag(selectedPresets, tag);

                EditorGUILayout.BeginHorizontal();
                if (!hasTag)
                {
                    if (GUILayout.Button("+", GUILayout.MaxWidth(20)))
                    {
                        foreach (var preset in selectedPresets)
                        {
                            TagDatabaseAsset.AddTag(preset, tag);
                        }
                    }
                    EditorGUILayout.LabelField(tag, EditorStyles.miniLabel);
                }
                else
                {
                    if (GUILayout.Button("-", GUILayout.MaxWidth(20)))
                    {
                        foreach (var preset in selectedPresets)
                        {
                            TagDatabaseAsset.RemoveTag(preset, tag);
                        }
                    }
                    EditorGUILayout.LabelField(tag, EditorStyles.boldLabel);
                }
                EditorGUILayout.EndHorizontal();
            }
        }
Example #3
0
        void DrawTagsPopup()
        {
            tags.Clear();
            tags = TagDatabaseAsset.GetAllTags();
            tags.Insert(0, "All");
            int selectedTag = EditorGUILayout.Popup("Tags", tagsId, tags.ToArray());

            if (tagsId != selectedTag)
            {
                tagsId = selectedTag;
                if (tagsId != 0)
                {
                    m_TagFilter = tags[tagsId];
                }
                else
                {
                    m_TagFilter = "";
                }
                UpdateDeviceSelectorList();
            }
        }
Example #4
0
        void DrawDeviceItem(ScreenshotResolutionAsset preset)
        {
            if (preset == null)
            {
                return;
            }

            EditorGUILayout.BeginHorizontal(GUILayout.Height(20));

            // BUTTONS
            if (GUILayout.Button("Add", GUILayout.Width(35)))
            {
                AddDevice(preset);
            }
            if (GUILayout.Button("Select", GUILayout.Width(45)))
            {
                Selection.activeObject = preset;
            }

            // Bold if already in list
            var style = EditorStyles.label;

            if (m_Config.m_Resolutions.Where(x => preset.name == x.m_ResolutionName).ToList().Count > 0)
            {
                style = EditorStyles.boldLabel;
            }

            // Popularity if popularity selection
            if (m_SelectedPopularityCollection != null)
            {
                float  frequency = m_SelectedPopularityCollection.GetPopularity(preset);
                string fs        = "";
                if (frequency > 0f)
                {
                    fs = frequency.ToString() + "%";
                }
                EditorGUILayout.LabelField(fs, style, GUILayout.Width(50));
            }

            // Device name
            EditorGUILayout.LabelField(preset.name, style, GUILayout.Width(200));
            if (m_ShowDetailedDevice)
            {
                EditorGUILayout.LabelField(preset.m_Resolution.m_Platform, style, GUILayout.Width(70));
            }
            EditorGUILayout.LabelField("" + preset.m_Resolution.m_Width + "x" + preset.m_Resolution.m_Height, style, GUILayout.Width(75));
            if (m_ShowDetailedDevice)
            {
                EditorGUILayout.LabelField(preset.m_Resolution.m_PPI > 0 ? preset.m_Resolution.m_PPI.ToString() : "", style, GUILayout.Width(30));
            }
            EditorGUILayout.LabelField(preset.m_Resolution.m_Ratio, style, GUILayout.Width(50));
            if (m_ShowDetailedDevice)
            {
                EditorGUILayout.LabelField(preset.m_Resolution.m_SafeAreaPortrait == Rect.zero ? " " : "X", EditorStyles.centeredGreyMiniLabel, GUILayout.Width(50));
                EditorGUILayout.LabelField(preset.m_Resolution.m_DeviceCanvas == null ? " " : "X", EditorStyles.centeredGreyMiniLabel, GUILayout.Width(35));
            }
            EditorGUILayout.LabelField(TagDatabaseAsset.GetTagString(preset), style, GUILayout.MinWidth(50));
            EditorGUILayout.LabelField(preset.m_Resolution.m_Category, style, GUILayout.MinWidth(70));


            EditorGUILayout.EndHorizontal();
        }
Example #5
0
        void FilterDeviceList()
        {
            // Reset to page 0
            currentPage = 0;

            // Init with all presets
            m_FilteredPresets.Clear();
            m_FilteredPresets.AddRange(m_Presets);

            // Filter with the text filter
            if (m_TextFilter != "")
            {
                var splits = m_TextFilter.ToLower().Split(' ');
                foreach (var s in splits)
                {
                    m_FilteredPresets = m_FilteredPresets.Where(x => (x.name + " "
                                                                      + x.m_Resolution.m_Category + " "
                                                                      + x.m_Resolution.m_Platform + " "
                                                                      + x.m_Resolution.m_Ratio + " "
                                                                      + TagDatabaseAsset.GetTagString(x) + " "
                                                                      + x.m_Resolution.m_Width + "x" + x.m_Resolution.m_Height).ToLower().Contains(s)).ToList();
                }
            }
            // Filter by category, collection or popularity
            if (m_CategoryFilter != "")
            {
                if (m_SelectedCollection != null)
                {
                    m_FilteredPresets = m_FilteredPresets.Where(x => m_SelectedCollection.m_Presets.Contains(x)).ToList();
                }
                else if (m_SelectedPopularityCollection != null)
                {
                    m_FilteredPresets = m_FilteredPresets.Where(x => m_SelectedPopularityCollection.Contains(x)).ToList();
                }
                else
                {
                    m_FilteredPresets = m_FilteredPresets.Where(x => ("" + x.m_Resolution.m_Category).Contains(m_CategoryFilter)).ToList();
                }
            }
            // Ratio
            if (m_RatioFilter != "")
            {
                m_FilteredPresets = m_FilteredPresets.Where(x => ("" + x.m_Resolution.m_Ratio).Contains(m_RatioFilter)).ToList();
            }
            // Tags
            if (m_TagFilter != "")
            {
                m_FilteredPresets = m_FilteredPresets.Where(x => ("" + TagDatabaseAsset.GetTagString(x)).Contains(m_TagFilter)).ToList();
            }
            // PPI
            if (m_PPIFilter != "")
            {
                m_FilteredPresets = m_FilteredPresets.Where(x => ("" + x.m_Resolution.m_PPI).Contains(m_PPIFilter)).ToList();
            }
            // Safe Area
            if (m_HasSafeAreaOnly)
            {
                m_FilteredPresets = m_FilteredPresets.Where(x => x.m_Resolution.m_SafeAreaPortrait != Rect.zero).ToList();
            }
            // Canvas
            if (m_HasImageOnly)
            {
                m_FilteredPresets = m_FilteredPresets.Where(x => x.m_Resolution.m_DeviceCanvas != null).ToList();
            }
        }