예제 #1
0
        /// <summary>
        /// Here's how the drawer checks what avenue to take:
        /// 1. If valid folder and folder has assigned icon, draw replacement icon and exit.
        /// 2. Else if asset successfully loads, try to draw it by passing any PvIconAttributes through registry.
        /// 3. Else check if asset path matches regex, and draw replacement if it does.
        /// 4. Else check if asset extension matches one of the registered extns, and draw replacement if it does
        /// 5. Failed to find a good substitute icon. Leave original icon intact.
        /// </summary>
        public void DrawProjectIcon(string guid, Rect selectionrect)
        {
            /*
             *          ValidateProjectBrowser();
             *          bool didClip = false;
             *          if (_getProjectBrowserRect != null)
             *          {
             *              Rect projectBrowserRect = _getProjectBrowserRect();
             *              Rect clippingRect = new Rect(Vector2.down * (18f), projectBrowserRect.size - new Vector2(0f, 36f));
             *              /EditorGUI.DrawRect(clippingRect, Color.green);
             *              GUI.BeginClip(clippingRect);
             *              selectionrect = new Rect(selectionrect.position - clippingRect.position, selectionrect.size);
             *              didClip       = true;
             *          }
             */

            //determine whether given asset is currently selected
            bool selected = Array.IndexOf(Selection.assetGUIDs, guid) > -1;

            string path  = AssetDatabase.GUIDToAssetPath(guid);
            Object asset = AssetDatabase.LoadAssetAtPath(path, typeof(Object));

            //PvCustomizerGUI.InvertedColors = selected;

            PvCustomizerSettings settings = PvCustomizerSettings.GetOrCreateSettings();

            if (AssetDatabase.IsValidFolder(path) && settings.DrawFolderIcons)
            {
                if (settings.TryMatchAgainstRules(path, out var pattern))
                {
                    DrawFolderIcon(path, selectionrect, pattern, selected);
                }
            }
            else if (asset != null && settings.DrawAssetIcons)
            {
                //if the class has an attribute defined, draw it
                if (PvIconAttributeCache.TryGetClassAttribute(asset.GetType(), out var attrs))
                {
                    foreach (PvIconAttribute attr in attrs)
                    {
                        TryDrawFromValue(asset, asset, selectionrect, attr, selected);
                    }
                }
                //else, descend into the members
                else
                {
                    bool didDraw = FindAndDrawAttributes(asset, selectionrect, selected);
                }
            }

            /*if (didClip)
             * {
             *  GUI.EndClip();
             * }*/
        }
예제 #2
0
 private static void DrawTextureDirect(Rect rect, Texture2D texture, Material material, PvScaleMode?scaleMode,
                                       Color?tint = null)
 {
     if (texture == null)
     {
         return;
     }
     material.SetFloat(s_TintAmount, PvCustomizerSettings.GetOrCreateSettings().TintAmount);
     material.SetColor(s_Tint, tint ?? Color.white);
     UnityEditor.EditorGUI.DrawPreviewTexture(rect, texture, material,
                                              (scaleMode ?? PvScaleMode.ScaleToFit).UnityScaleMode());
 }
        internal static PvCustomizerSettings GetOrCreateSettings()
        {
            if (_settings == null)
            {
                _settings = AssetDatabase.LoadAssetAtPath <PvCustomizerSettings>(k_MyCustomSettingsPath);
                if (_settings == null)
                {
                    _settings           = CreateInstance <PvCustomizerSettings>();
                    _settings.assetIcon = Resource.Load <Sprite>("Icons/logo_small.png");
                    LoadDefaultRules(_settings);
                    if (!Directory.Exists(ResourcesFolder))
                    {
                        Directory.CreateDirectory(ResourcesFolder);
                    }
                    AssetDatabase.CreateAsset(_settings, k_MyCustomSettingsPath);
                    AssetDatabase.SaveAssets();
                }
            }

            return(_settings);
        }
 private static void LoadDefaultRules(PvCustomizerSettings settings)
 {
     //todo
 }