Exemplo n.º 1
0
        /// <summary>
        /// <para>Paints the item in the project window.</para>
        /// </summary>
        /// <param name="guid">The GUID of the asset to check.</param>
        /// <param name="rect">The Rect in which the item is drawn.</param>
        private static void ItemOnGUI(string guid, Rect rect)
        {
            if (Event.current.type != EventType.Repaint || string.IsNullOrEmpty(guid))
            {
                return;
            }

            if (!AssetIconsPreferences.Enabled.Value)
            {
                return;
            }

            var assetTarget = pipeline.AssetTargets.GetOrCreateFromGuid(guid);

            if (string.IsNullOrEmpty(assetTarget.Extension))
            {
                return;
            }

            if (assetTarget.Extension == ".asset")
            {
                if (assetTarget.Drawer != null)
                {
                    if (assetTarget.Drawer.CanDraw())
                    {
                        var backgroundRect = AssetIconsGUIUtility.AreaToIconRect(rect, 128);
                        AssetIconsGUI.DrawBackground(backgroundRect);

                        assetTarget.Drawer.Draw(rect, assetTarget.IsSelected);
                    }
                }
            }
            else if (AssetIconsPreferences.DrawGUIStyles.Value && assetTarget.Extension == ".guiskin")
            {
                var obj = assetTarget.ObjectReference;
                if (obj is GUISkin)
                {
                    rect = AssetIconsGUIUtility.AreaToIconRect(rect);
                    AssetIconsGUI.DrawBackground(rect);

                    var skin = (GUISkin)obj;
                    skin.box.Draw(rect, new GUIContent("Style"), 0, assetTarget.IsSelected);
                }
            }
            else
            {
                var icon = AssetIconsPreferences.TypeIcons[assetTarget.Extension];
                if (icon != null && icon.ObjectReference != null && icon.GraphicDrawer != null)
                {
                    if (icon.GraphicDrawer.CanDraw())
                    {
                        AssetIconsGUI.DrawBackground(rect);

                        icon.GraphicDrawer.Draw(rect, assetTarget.IsSelected, AssetIconsCompiledStyle.Default);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            if (previewGraphicStyle == null)
            {
                previewGraphicStyle = new AssetIconsCompiledStyle(new AssetIconsStyle()
                {
                    MaxSize = 64
                });

                smallLabelRect = new GUIStyle(EditorStyles.centeredGreyMiniLabel)
                {
                    alignment = TextAnchor.MiddleCenter
                };
            }

            var sliderRect        = new Rect(position.x, position.y + 6, position.width, EditorGUIUtility.singleLineHeight);
            var labelRect         = EditorGUI.PrefixLabel(sliderRect, spaceContent);
            var previewBackground = new Rect(labelRect.xMin, sliderRect.yMax + 4,
                                             labelRect.width, position.yMax - 12 - sliderRect.yMax);

            var previewArea = new Rect(
                previewBackground.x + 8, previewBackground.y + 8,
                previewBackground.width - 16, previewBackground.height - 10);

            var normalRect   = new Rect(previewArea.x, previewArea.y, (previewArea.width * 0.5f) - 3.0f, previewArea.height - 18.0f);
            var selectedRect = new Rect(normalRect.xMax + 6.0f, previewArea.y, normalRect.width, previewArea.height - 18.0f);

            var normalLabelRect   = new Rect(normalRect.x, normalRect.yMax + 2.0f, normalRect.width, 14.0f);
            var selectedLabelRect = new Rect(selectedRect.x, selectedRect.yMax + 2.0f, selectedRect.width, 14.0f);

            var tintStrengthProperty = property.FindPropertyRelative("tintStrength");

            tintStrengthProperty.floatValue = EditorGUI.Slider(sliderRect, label,
                                                               tintStrengthProperty.floatValue, 0.0f, 1.0f);

            if (Event.current.type == EventType.Repaint)
            {
                EditorGUI.HelpBox(previewBackground, " ", MessageType.None);

                AssetIconsGUI.DrawSprite(normalRect, AssetIconsResources.CurrentTheme.SampleImage, previewGraphicStyle, false);
                AssetIconsGUI.DrawSprite(selectedRect, AssetIconsResources.CurrentTheme.SampleImage, previewGraphicStyle, true);
            }

            EditorGUI.LabelField(normalLabelRect, normalContent, smallLabelRect);
            EditorGUI.LabelField(selectedLabelRect, selectedContent, smallLabelRect);

            EditorGUI.EndProperty();
        }
            public void Draw(Rect rect, bool selected, AssetIconsCompiledStyle style)
            {
                var drawRect = AssetIconsGUIUtility.AreaToIconRect(rect, style.MaxSize);

                if (currentValue != null)
                {
                    var col = AssetIconsGUI.BackgroundColor;
                    col = new Color(col.r, col.g, col.b, 0);

                    var setup = new AssetIconsCameraSetup()
                    {
                        BackgroundColor       = col,
                        TransparentBackground = true,
                        Orthographic          = style.Projection == IconProjection.Orthographic,

                        PreviewDirection = new Vector3(-1.0f, -1.0f, -1.0f)
                    };

                    var thumbnail = AssetIconsRenderCache.GetTexture(setup, currentValue);

                    AssetIconsGUI.DrawTexture(rect, thumbnail, style, selected);
                }
            }
            public void Draw(Rect rect, bool selected, AssetIconsCompiledStyle style)
            {
                var drawRect = AssetIconsGUIUtility.AreaToIconRect(rect, style.MaxSize);

                AssetIconsGUI.DrawColor(drawRect, color, style, selected);
            }
            public void Draw(Rect rect, bool selected, AssetIconsCompiledStyle style)
            {
                var drawRect = AssetIconsGUIUtility.AreaToIconRect(rect, style.MaxSize);

                AssetIconsGUI.DrawTexture(drawRect, currentValue, style, selected);
            }