예제 #1
0
        public void PlaceClearBrush(SingleBrush brush, Vector2 point, float lerp = 1f)
        {
            var localPoint = cachedTransform.InverseTransformPoint(point);
            var bounds     = meshBounds;

            localPoint.z = 0;
            if (!bounds.Contains(localPoint))
            {
                return;
            }
            SetDirty();
            var decalWidth  = m_decal.width;
            var decalHeight = m_decal.height;
            var b           = brush.GetBrush(gameObject.tag, 0);
            var brushWidth  = b.width;
            var brushHeigth = b.height;
            var uv          = GetUV(localPoint, b);

            var xStart = (int)((uv.x * decalWidth) - (brushWidth * .5f));
            var yStart = (int)((uv.y * decalHeight) - (brushHeigth * .5f));

            var pixelCount = b.points.Length;

            for (int i = 0; i < pixelCount; i++)
            {
                var p   = b.points[i];
                var x   = xStart + p.x;
                var y   = yStart + p.y;
                var old = m_decal.GetPixel(x, y);
                old.a -= lerp;
                m_decal.SetPixel(x, y, old);
            }

            m_decal.Apply();
        }
예제 #2
0
        public void PlaceBrush(SingleBrush brush, Vector2 point, float lerp = 1f, Color color = default(Color))
        {
            var localPoint = cachedTransform.InverseTransformPoint(point);
            var bounds     = meshBounds;

            localPoint.z = 0;
            if (!bounds.Contains(localPoint))
            {
                return;
            }
            SetDirty();
            var decalWidth  = m_decal.width;
            var decalHeight = m_decal.height;
            var b           = brush.GetBrush(gameObject.tag, 0);
            var brushWidth  = b.width;
            var brushHeigth = b.height;
            var uv          = GetUV(localPoint, b);

            var xStart = (int)((uv.x * decalWidth) - (brushWidth * .5f));
            var yStart = (int)((uv.y * decalHeight) - (brushHeigth * .5f));

            var  pixelCount   = b.points.Length;
            bool replaceColor = color != default(Color);

            for (int i = 0; i < pixelCount; i++)
            {
                var p   = b.points[i];
                var x   = xStart + p.x;
                var y   = yStart + p.y;
                var old = m_decal.GetPixel(x, y);
                if (replaceColor)
                {
                    color.a = p.color.a;
                }
                var c = Color.Lerp(old, replaceColor ? color : p.color, lerp * p.color.a);
                if (p.color.a < .3f)
                {
                    c = old;
                }
                c.a += old.a * 2;
                m_decal.SetPixel(x, y, c);
            }

            m_decal.Apply();
        }
예제 #3
0
        public override SingleBrush GetBrush(string tag, float angle, int order)
        {
            var         a     = 360f;
            SingleBrush brush = m_brushes[0].brush.GetBrush(tag, order);
            var         count = brushes.Count;

            for (int i = 0; i < count; i++)
            {
                BrushAnglePair b         = m_brushes[i];
                var            angleDiff = Mathf.DeltaAngle(angle, b.angle);
                if (angleDiff < a)
                {
                    brush = b.brush.GetBrush(tag, order);
                    a     = angleDiff;
                }
            }
            return(brush);
        }