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; }
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; } } } }