Author Topic: Masking UITexture inside ScrollView doesn't work!!  (Read 10808 times)

Mistra

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Masking UITexture inside ScrollView doesn't work!!
« Reply #15 on: July 29, 2015, 07:04:10 AM »
I solved the issue by following cropping function. newtex is your desired cropped face.
Use a transparent overly if you want rounded corners or anything relating.

public void CreateCroppedTex (UITexture tex,Vector2 pixelOffset) {
               
// rect values to crop
               int x;
               int y;
               int width;
               int height;

      Texture2D _texture = tex.mainTexture as Texture2D;
      Sprite newSprite = Sprite.Create(_texture,
                                         new Rect(x, y,width, height),
                                       new Vector2(0.5f, 0.5f));

      Color[] c =   newSprite.texture.GetPixels((int)newSprite.textureRect.x,
                                              (int)newSprite.textureRect.y,
                                                       (int)faceWidth,
                                                       (int)faceHeight );

      Texture2D newtex = new Texture2D( (int)faceWidth, (int)faceHeight, TextureFormat.ARGB32,false);
      newtex.filterMode = FilterMode.Bilinear;
      newtex.SetPixels(c);
      newtex.Apply();

      tex.mainTexture = newtex;

   }

cedtat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Masking UITexture inside ScrollView doesn't work!!
« Reply #16 on: August 22, 2015, 07:37:23 AM »
Hello,

I am actually trying to do exactly the same as Scryed, I have a scroll view, with a table composed of a list of textures. Each UITexture is nested inside a panel with a circle mask and now I am experiencing the same problem as scryed. The profile picture is not clipped by the scrollview on the edge. It only disappears when completly outside of the scrollview. I have 3 UIPanel (UIRoot, ScrollView and texture mask)

I have tried changing the shader on my texture with "Unlit - Transpasrent Masked" 1,2 and 3 and "Unlit - Transparent Colored" versions but without any success.
Obviously I have missed something, is there someone here to help me ?

Thanks,
Cedric

cedtat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Masking UITexture inside ScrollView doesn't work!!
« Reply #17 on: August 22, 2015, 02:08:20 PM »
ok, thanks to this subject, I found a solution :http://www.tasharen.com/forum/index.php?topic=13450.0

I understood it was not possible to mix rect-based clipping with texture mask-based clipping.
So I stopped using a panel above my texture to mask it inside a scrollview. I am now using a material with a shader modified from "unlit/Transparent Colored 1".
I made multiple errors in the process of creating the shader, not placing it in appropriate ressource folder and not naming it correclty so that NGUI find it.

Cheers,
Cedric