Beispiel #1
0
        public sealed override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
        {
            Brush brush = AssetDatabase.LoadMainAssetAtPath(assetPath) as Brush;

            if (brush == null)
            {
                return(null);
            }

            if (brush.m_Mask == null)
            {
                brush.m_Mask = Brush.DefaultMask();
            }
            PreviewHelpers.AdjustWidthAndHeightForStaticPreview(brush.m_Mask.width, brush.m_Mask.height, ref width, ref height);
            return(Brush.GenerateBrushTexture(brush.m_Mask, brush.m_Falloff, brush.m_RadiusScale, brush.m_BlackWhiteRemapMin, brush.m_BlackWhiteRemapMax, brush.m_InvertRemapRange, width, height, true));
        }
Beispiel #2
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            Texture2D mask = (Texture2D)m_Mask.objectReferenceValue;

            if (mask == null)
            {
                mask         = Brush.DefaultMask();
                m_HasChanged = true;
            }

            int texWidth  = Mathf.Min(mask.width, 256);
            int texHeight = Mathf.Min(mask.height, 256);

            if (m_HasChanged || m_PreviewTexture == null)
            {
                m_PreviewTexture = Brush.GenerateBrushTexture(mask, m_Falloff.animationCurveValue, m_RadiusScale.floatValue, m_BlackWhiteRemapMin.floatValue, m_BlackWhiteRemapMax.floatValue, m_InvertRemapRange.boolValue, texWidth, texHeight, true);
                m_HasChanged     = false;
            }

            float zoomLevel  = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
            Rect  wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");

            if (m_PreviewTexture.alphaIsTransparency)
            {
                EditorGUI.DrawTextureTransparent(wantedRect, m_PreviewTexture);
            }
            else
            {
                EditorGUI.DrawPreviewTexture(wantedRect, m_PreviewTexture);
            }

            m_Pos = PreviewGUI.EndScrollView();
        }