public static void ColorizeFolderByPath(this RainbowFoldersSettings settings, string path, RainbowColorFolder colorIcons)
        {
            Undo.RecordObject(settings, "Modify Rainbow Folder Settings");

            var folders = settings.Folders;
            var folder  = folders.SingleOrDefault(x => x.Key == path);

            if (folder == null)
            {
                folders.Add(new RainbowFolder
                {
                    Key       = path,
                    Type      = RainbowFolder.KeyType.Path,
                    SmallIcon = colorIcons.SmallIcon,
                    LargeIcon = colorIcons.LargeIcon
                });
            }
            else
            {
                folder.SmallIcon = colorIcons.SmallIcon;
                folder.LargeIcon = colorIcons.LargeIcon;
            }

            EditorUtility.SetDirty(settings);
        }
Exemplo n.º 2
0
        public void ShowWithParams(Vector2 inPosition, List <string> paths, int pathIndex)
        {
            _paths    = paths;
            _settings = RainbowFoldersSettings.Instance;

            var size = paths.Count;

            _existingFolders = new RainbowFolder[size];
            _currentFolder   = new RainbowFolder(KeyType.Path, paths[pathIndex]);

            for (var i = 0; i < size; i++)
            {
                _existingFolders[i] = _settings.GetFolderByPath(paths[i]);
            }

            if (_existingFolders[pathIndex] != null)
            {
                _currentFolder.CopyFrom(_existingFolders[pathIndex]);
            }

            // Resize

            var customIconHeight       = (_currentFolder.IsIconCustom) ? LINE_HEIGHT * 2f : 0f;
            var customBackgroundHeight = (_currentFolder.IsBackgroundCustom) ? LINE_HEIGHT : 0f;

            var rect = new Rect(inPosition, WINDOW_SIZE)
            {
                height = WINDOW_HEIGHT + customIconHeight + customBackgroundHeight
            };

            _windowRect     = new Rect(Vector2.zero, rect.size);
            _backgroundRect = new Rect(Vector2.one, rect.size - new Vector2(2f, 2f));

            Show <RainbowFoldersPopup>(rect);
        }
        private static void ReplaceFolderIcon(string guid, Rect rect)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);

            if (!AssetDatabase.IsValidFolder(path))
            {
                return;
            }

            RainbowFoldersSettings setting = RainbowFoldersSettings.Instance;

            if (setting == null)
            {
                return;
            }
            RainbowFolder folder = RainbowFoldersSettings.Instance.GetFolderByPath(path, true);

            if (folder == null)
            {
                return;
            }

            bool isSmall = IsIconSmall(rect);

            // Backround
            Texture2D backgroundTex = folder.Background;

            if (backgroundTex != null)
            {
                Rect backgroundRect = GetBackgroundRect(rect, isSmall);
                DrawCustomBackground(backgroundRect, backgroundTex);
            }

            // Icon
            Texture2D iconTex = isSmall ? folder.SmallIcon : folder.LargeIcon;

            if (iconTex != null)
            {
                Rect iconRect = GetIconRect(rect, isSmall);
                DrawCustomIcon(guid, iconRect, iconTex, isSmall);
            }
        }
Exemplo n.º 4
0
        static void ReplaceFolderIcon(string guid, Rect rect)
        {
            var path = AssetDatabase.GUIDToAssetPath(guid);

            if (!AssetDatabase.IsValidFolder(path))
            {
                return;
            }

            var isSmall = rect.width > rect.height;

            if (isSmall)
            {
                rect.width = rect.height;
            }
            else
            {
                rect.height = rect.width;
            }

            _settings = _settings ?? RainbowFoldersSettings.Load();

            var texture = _settings.GetTextureByFolderName(Path.GetFileName(path), isSmall);

            if (texture == null)
            {
                return;
            }
            if (rect.width > LARGE_ICON_SIZE)
            {
                var offset   = (rect.width - LARGE_ICON_SIZE) / 2f;
                var position = new Rect(rect.x + offset, rect.y + offset, LARGE_ICON_SIZE, LARGE_ICON_SIZE);
                GUI.DrawTexture(position, texture);
            }
            else
            {
                GUI.DrawTexture(rect, texture);
            }
        }
        public static void Colorize(FolderColors color)
        {
            WarnAboutTwoColumnLayout();

            var selectedObj = Selection.activeObject;

            if (selectedObj == null)
            {
                Debug.LogWarning("Cannot apply color from the left column of the project view." +
                                 "Please right click the folder in the right column if you are using two-column layout");
                return;
            }

            if (!(selectedObj is DefaultAsset))
            {
                Debug.LogWarning(WARNING_MSG);
                return;
            }

            var path = AssetDatabase.GetAssetPath(selectedObj);

            if (!AssetDatabase.IsValidFolder(path))
            {
                Debug.LogWarning(WARNING_MSG);
                return;
            }

            var settings = RainbowFoldersSettings.Load();

            if (color != FolderColors.Default)
            {
                settings.ColorizeFolderByPath(path, FolderColorsStorage.GetInstance().GetFolderByColor(color));
            }
            else
            {
                settings.RemoveAllByPath(path);
            }
        }
Exemplo n.º 6
0
        public void ShowWithParams(Vector2 position, string[] paths, int pathIndex)
        {
            _paths    = paths;
            _settings = RainbowFoldersSettings.Instance;

            var size = paths.Length;

            _existingFolders = new RainbowFolder[size];
            _currentFolder   = new RainbowFolder(KeyType.Path, paths[pathIndex]);

            for (var i = 0; i < size; i++)
            {
                _existingFolders[i] = _settings.GetFolderByPath(paths[i]);
            }

            if (_existingFolders[pathIndex] != null)
            {
                _currentFolder.CopyFrom(_existingFolders[pathIndex]);
            }

            var rect = new Rect(position, WINDOW_SIZE);

            Show <RainbowFoldersPopup>(rect);
        }
 public static void RemoveAllByPath(this RainbowFoldersSettings settings, string path)
 {
     settings.Folders.RemoveAll(x => x.Key == path);
 }
        public static void OpenSettings()
        {
            var settings = RainbowFoldersSettings.Load();

            Selection.activeObject = settings;
        }