Author Topic: I need some help.  (Read 255 times)

ufaforwork2

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
I need some help.
« on: July 16, 2017, 05:39:09 AM »
Hello. I am newbie.
I'm working on a game that's a fair way along in development, and I need to write some graphics / shader code to work alongside NGUI (v 3.9.7), but I'm not too familiar with the workings of the UI code itself.
แทงบอลเงินสด
I've got a shader that makes a scrolling 'sizzle' effect that sweeps across a UISprite button once in a while. I've implemented this by drawing a second copy of the sprite over the first one, with a new material using the original atlas texture's alpha channel to 'clip' the effect, and a second texture for the effect itself. The trouble is, the buttons are in a vertical stack, so the effect sweeps across all of them simultaneously. I'd like to add a horizontal offset per-button to break this up a bit.

The easiest way I can think of to do this is just to add an x offset using Material.SetFloat. I understand that the draw calls get batched though, so all the buttons will get drawn with the value of the last one to update. Is there any easy way to make sure each one gets drawn with its own value? I don't mind dropping a few draw calls if necessary, since it's only the menu screen, not the main game. สมัครแทงบอลเงินสด

As an aside, did secondary texture coordinates for detail textures ever get implemented? I saw ArenMook mention it in a post from a while back but I don't know if it was ever followed up.

toyob

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 7
    • View Profile
Re: I need some help.
« Reply #1 on: July 20, 2017, 05:44:17 AM »
I have faced a similar problem and solved it by extracting the textures from UIAtlas to a UITexture array upon start. Then I just apply the required UITexture on a Mesh Quad and put the shader on the material that belongs to that specific UITexture.

  1. UISpriteData data = spriteList[i];
  2.        
  3.                        
  4.                         Color[] pix = src_tex2d.GetPixels(data.x, sourceAtlas.texture.height - data.y - data.height, data.width, data.height);
  5.                         spriteTextures[i] = new Texture2D(data.width, data.height, TextureFormat.ARGB32, false);
  6.  
  7.                         spriteTextures[i].SetPixels(pix);
  8.                         spriteTextures[i].Apply();
  9.                
  10.                        
  11.                         IndividualSpriteTexturesDic.Add(spriteList[i].name,spriteTextures[i]);

toyob

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 7
    • View Profile
Re: I need some help.
« Reply #2 on: July 20, 2017, 05:49:08 AM »
Forgot the first line in the code, it should be

  1. List<UISpriteData> spriteList = sourceAtlas.spriteList;

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 327
  • -Receive: 1153
  • Posts: 22,063
  • Toronto, Canada
    • View Profile
Re: I need some help.
« Reply #3 on: July 22, 2017, 02:50:23 PM »
Yes, secondary texture coordinates got added a while back, and your NGUI 3.9.7 is very old now.

You can draw any NGUI sprite using a separate material by assigning a material to it -- but again you need to update your NGUI to have this functionality.

With a material assigned, it will create a new draw call, thus letting you use UIWidget's onRender to pass whatever values to the material you require. Don't attempt to modify the source material. Use UIWidget.onRender -- it will pass the copied material for your modification.