Example #1
0
        /// <summary>
        /// apply color with sprite as a brush on target texture
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="offset"></param>
        /// <param name="applyanceColor"></param>
        /// <param name="brushApplyier"></param>
        public virtual void ApplyOn(Sprite sprite, Vector2 offset, Color applyanceColor, BrushApplyier brushApplyier, bool wentOutside)
        {
            if (brushApplyierMain == null)
            {
                brushApplyierMain = brushApplyier;
                strokeColor       = new Color(brushApplyierMain.ignoreColors[0].r, brushApplyierMain.ignoreColors[0].g, brushApplyierMain.ignoreColors[0].b, brushApplyierMain.ignoreColors[0].a);
            }
            if (wentOutside)
            {
                brushApplyierMain.pixelUVOld  = offset;
                brushApplyierMain.wentOutside = false;
            }

            if (Input.GetMouseButtonDown(0))
            {
                brushApplyierMain.pixelUVOld = offset;
                if (useCustomPatterns)
                {
                    DrawPatternCircle((int)offset.x, (int)offset.y);
                }
                else
                {
                    DrawCircle((int)offset.x, (int)offset.y, applyanceColor);
                }
                UpdateTexture();
            }

            //check distance from previous drawing point and connect them with DrawLine

            //if (Vector2.Distance(offset, brushApplyierMain.pixelUVOld) > brushSize)
            //{
            //if (!brushApplyierMain.pixelUVOld.Equals(offset))

            if (Mathf.Abs((int)offset.x - (int)brushApplyierMain.pixelUVOld.x) > 100 || Mathf.Abs((int)offset.y - (int)brushApplyierMain.pixelUVOld.y) > 100)
            {
                brushSizeDiv4 = idealAmount;
            }
            else
            {
                brushSizeDiv4 = minimumAmount;
            }

            if (useCustomPatterns)
            {
                DrawLineWithPattern(new Vector2((int)brushApplyierMain.pixelUVOld.x, (int)brushApplyierMain.pixelUVOld.y), new Vector2((int)offset.x, (int)offset.y));
            }
            else
            {
                DrawLine((int)brushApplyierMain.pixelUVOld.x, (int)brushApplyierMain.pixelUVOld.y, (int)offset.x, (int)offset.y, applyanceColor);
            }
            UpdateTexture();
            brushApplyier.EnableDraggable();
            brushApplyierMain.pixelUVOld = offset;



            //}
        }
Example #2
0
        /// <summary>
        /// Apply brush on Raycast hit target
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="hit"></param>
        /// <param name="applyanceColor"></param>
        /// <param name="brushApplyier"></param>
        public override void ApplyOn(Sprite sprite, Vector2 offset, Color applyanceColor, BrushApplyier brushApplyier, bool wentOutside)
        {
            Color oldColor = sprite.texture.GetPixel((int)offset.x, (int)offset.y);

            brushApplyierMain = brushApplyier;

            if (brushApplyier.ignoreColors.Contains(oldColor))
            {
                brushApplyier.EnableDraggable();
                return;
            }

            FloodFillNew.instance.Fill2(sprite.texture, offset, applyanceColor, oldColor);
        }
Example #3
0
        /// <summary>
        /// Apply brush on Raycast hit target
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="hit"></param>
        /// <param name="applyanceColor"></param>
        /// <param name="brushApplyier"></param>
        public void ApplyWithRaycast(Sprite sprite, RaycastHit hit, Color applyanceColor, BrushApplyier brushApplyier, bool wentOutside)
        {
            brushApplyier.DisableDraggable();
            Vector2 pixelUV  = Vector2.zero;
            Vector2 hitPoint = brushApplyier.camMain.WorldToScreenPoint(hit.point);

            RectTransformUtility.ScreenPointToLocalPointInRectangle(hit.collider.GetComponent <RectTransform>(), hitPoint, brushApplyier.camMain, out pixelUV);
            pixelUV.x /= hit.collider.GetComponent <RectTransform>().rect.width;
            pixelUV.y /= hit.collider.GetComponent <RectTransform>().rect.height;
            pixelUV   += new Vector2(0.5f, 0.5f);
            //Debug.Log("pixelUV Increased: " + pixelUV);

            /*
             * if (pixelUV.x == 0 && pixelUV.y == 0)
             * {
             *
             *  Vector2 hitPoint = Camera.main.WorldToScreenPoint(hit.point);
             *  RectTransformUtility.ScreenPointToLocalPointInRectangle(hit.collider.GetComponent<RectTransform>(), hitPoint, Camera.main, out pixelUV);
             *  pixelUV.x /= hit.collider.GetComponent<RectTransform>().rect.width;
             *  pixelUV.y /= hit.collider.GetComponent<RectTransform>().rect.height;
             *  pixelUV += new Vector2(0.5f, 0.5f);
             *  Debug.Log("pixelUV Increased: " + pixelUV);
             * }
             */

            pixelUV.x *= sprite.texture.width;
            pixelUV.y *= sprite.texture.height;


            ApplyOn(sprite, pixelUV, applyanceColor, brushApplyier, wentOutside);
        }
Example #4
0
 /// <summary>
 /// Changes brush texture to brush apollyier's size
 /// </summary>
 /// <param name="brushApplyier"></param>
 public void ResizeBrushTexture(BrushApplyier brushApplyier)
 {
     //TextureScale.Bilinear(brushTexture, (int)(textureWidth * (brushApplyier.GetBrushSize())), (int)(textureHeight * (brushApplyier.GetBrushSize())));
     brushTexture.Resize((int)(textureWidth * (brushApplyier.GetBrushSize())), (int)(textureHeight * (brushApplyier.GetBrushSize())), TextureFormat.RGBA32, false);
 }
Example #5
0
        /// <summary>
        /// Apply brush on Raycast hit target
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="hit"></param>
        /// <param name="applyanceColor"></param>
        /// <param name="brushApplyier"></param>
        public override void ApplyOn(Sprite sprite, Vector2 offset, Color applyanceColor, BrushApplyier brushApplyier, bool firstTouch = false)
        {
            if (flood != null)
            {
                StopCoroutine(flood);
            }
            stack = new List <Vector2>();


            targetColor = sprite.texture.GetPixel((int)offset.x, (int)offset.y);
            stack.Add(offset);

            bool ignore = false;

            foreach (Color ignoreColor in brushApplyier.ignoreColors)
            {
                if (Vector4.Distance((Vector4)ignoreColor, (Vector4)targetColor) < brushApplyier.ColorSensitivity)
                {
                    ignore = true;
                    continue;
                }
            }
            if (ignore)
            {
                return;
            }

            flood = StartCoroutine(FloodFill(sprite, applyanceColor));
        }