Ejemplo n.º 1
0
        public void OnCollisionStay(Collision collision)
        {
            if(cam == null)
                return;

            if(!collision.contacts.Any(p => p.otherCollider.GetComponent<InkCanvas>() != null))
                return;

            cam.transform.position = transform.position + offset;

            var contact = collision.contacts.First(p => p.otherCollider.GetComponent<InkCanvas>() != null);
            var canvas = contact.otherCollider.GetComponent<InkCanvas>();

            var buf = RenderTexture.GetTemporary(brush.BrushTexture.width, brush.BrushTexture.height);
            GrabArea.Clip(brush.BrushTexture, brush.Scale, rt, Vector3.one * 0.5f, brush.RotateAngle, GrabArea.GrabTextureWrapMode.Clamp, buf);
            ReverseUV.Vertical(buf, buf);

            if(debugMode)
                Graphics.Blit(buf, debug);

            var brushBuf = brush.BrushTexture;
            brush.BrushTexture = buf;

            canvas.Paint(brush, contact.point);

            RenderTexture.ReleaseTemporary(buf);
            brush.BrushTexture = brushBuf;
        }
Ejemplo n.º 2
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hitInfo))
         {
             var d = hitInfo.transform.GetComponent <DynamicCanvas>();
             if (d != null && !grab)
             {
                 d.Paint(brush, hitInfo);
             }
             if (grab)
             {
                 GrabArea.Clip(brush.BrushTexture, brush.Scale, hitInfo.transform.GetComponent <MeshRenderer>().sharedMaterial.mainTexture, hitInfo.textureCoord, wrapMode, t);
                 brush.BrushTexture  = t;
                 brush.ColorBlending = PaintBrush.ColorBlendType.UseBrush;
                 grab = false;
             }
         }
     }
 }
Ejemplo n.º 3
0
        public Shape ResizeShape(int x, int y, Shape s, GrabArea grabArea)
        {
            s.selected = true;

            Point p = new Point(x, y);

            // Snap to grid
            p = SnapToGrid(p);

            ReplaceBitmapRegion(s.buffer, s.x1, s.y1);

            if (grabArea == GrabArea.HANDLE_BTMCENTER)
            {
                s        = new Shape(s.ShapeDef, s.x1, s.y1, s.bitmap.Width, p.Y - s.y1);
                s.buffer = GetBitmapRegion(s.rect);
            }

            if (grabArea == GrabArea.HANDLE_BTMLEFT)
            {
                s        = new Shape(s.ShapeDef, p.X, s.y1, s.bitmap.Width + (s.x1 - p.X), p.Y - s.y1);
                s.buffer = GetBitmapRegion(s.rect);
            }

            if (grabArea == GrabArea.HANDLE_BTMRIGHT)
            {
                s        = new Shape(s.ShapeDef, s.x1, s.y1, p.X - s.x1, p.Y - s.y1);
                s.buffer = GetBitmapRegion(s.rect);
            }

            if (grabArea == GrabArea.HANDLE_MIDLEFT)
            {
                s        = new Shape(s.ShapeDef, p.X, s.y1, s.bitmap.Width + (s.x1 - p.X), s.bitmap.Height);
                s.buffer = GetBitmapRegion(s.rect);
            }

            if (grabArea == GrabArea.HANDLE_MIDRIGHT)
            {
                s        = new Shape(s.ShapeDef, s.x1, s.y1, p.X - s.x1, s.bitmap.Height);
                s.buffer = GetBitmapRegion(s.rect);
            }

            if (grabArea == GrabArea.HANDLE_TOPLEFT)
            {
                s        = new Shape(s.ShapeDef, p.X, p.Y, s.bitmap.Width + (s.x1 - p.X), s.bitmap.Height + (s.y1 - p.Y));
                s.buffer = GetBitmapRegion(s.rect);
            }

            if (grabArea == GrabArea.HANDLE_TOPRIGHT)
            {
                s        = new Shape(s.ShapeDef, s.x1, p.Y, p.X - s.x1, s.bitmap.Height + (s.y1 - p.Y));
                s.buffer = GetBitmapRegion(s.rect);
            }

            if (grabArea == GrabArea.HANDLE_TOPCENTER)
            {
                s        = new Shape(s.ShapeDef, s.x1, p.Y, s.bitmap.Width, s.bitmap.Height + (s.y1 - p.Y));
                s.buffer = GetBitmapRegion(s.rect);
            }


            Draw(s);
            DrawHandles(s);

            return(s);
        }