Наследование: UnityEngine.ScriptableObject
        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);
            }
        }
Пример #2
0
        public static T LoadSetting <T>(string relativePath) where T : UnityEngine.Object
        {
            var assetPath = Path.Combine("Assets/", relativePath);
            // var asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);

            T   asset  = null;
            var assets = FindAssetsByType <T>();

            if (assets.Count > 0)
            {
                asset = assets[0];

                if (assets.Count > 1)
                {
                    Debug.LogWarning($"There is more than one instance of type {typeof(T).Name} in the Assets folder. {assets[0].name} was selected", assets[0]);
                }
            }

            if (!asset)
            {
                string name = typeof(T).Name;
                string guid = AssetDatabase.FindAssets($"{name}")[0];
                string originalAssetPath = AssetDatabase.GUIDToAssetPath(guid);
                asset = AssetDatabase.LoadAssetAtPath <T>(originalAssetPath);

                if (name == "RainbowFoldersSettings")
                {
                    Settings.RainbowFoldersSettings originalData = asset as Settings.RainbowFoldersSettings;
                    Settings.RainbowFoldersSettings newData      = ScriptableObject.CreateInstance(typeof(T)) as Settings.RainbowFoldersSettings;
                    newData.Folders = new System.Collections.Generic.List <Settings.RainbowFolder>(originalData.Folders.Count);
                    for (int i = 0; i < originalData.Folders.Count; ++i)
                    {
                        newData.Folders.Add(new Settings.RainbowFolder(originalData.Folders[i]));
                    }

                    string[] dirs    = assetPath.Split('/');
                    string   allPath = dirs[0];
                    for (int i = 1; i < dirs.Length - 1; ++i)
                    {
                        if (!AssetDatabase.IsValidFolder(allPath + "/" + dirs[i]))
                        {
                            AssetDatabase.CreateFolder(allPath, dirs[i]);
                        }
                        allPath = allPath + "/" + dirs[i];
                    }

                    AssetDatabase.CreateAsset(newData, assetPath);
                    AssetDatabase.SaveAssets();
                    asset = AssetDatabase.LoadAssetAtPath <T>(assetPath);
                }
            }

            return(asset);
        }
        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);
        }