PaintedMask.cs 865 B

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. namespace SoftMasking.Samples {
  4. [RequireComponent(typeof(RectTransform))]
  5. public class PaintedMask : UIBehaviour {
  6. public Canvas renderCanvas;
  7. public Camera renderCamera;
  8. public SoftMask targetMask;
  9. RenderTexture _renderTexture;
  10. protected override void Start() {
  11. base.Start();
  12. _renderTexture = new RenderTexture((int)maskSize.x, (int)maskSize.y, 0, RenderTextureFormat.ARGB32);
  13. _renderTexture.Create();
  14. renderCamera.targetTexture = _renderTexture;
  15. targetMask.renderTexture = _renderTexture;
  16. }
  17. Vector2 maskSize {
  18. get {
  19. var rectTransform = (RectTransform)targetMask.transform;
  20. return rectTransform.rect.size;
  21. }
  22. }
  23. }
  24. }