Author Topic: Assigning material to atlas  (Read 3449 times)

Nomy

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Assigning material to atlas
« on: July 24, 2015, 03:03:17 AM »
I have a custom black and white shader that I want to apply to my atlas. I know that the shader will effect all sprites in the atlas, and that is fine. I came across a post mentioned I should use UISprite's onRender to set the new material, but I don't understand how to apply it (syntax). Please help!  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assigning material to atlas
« Reply #1 on: July 24, 2015, 10:56:50 AM »
Just select the material used by the atlas and change it there.

Nomy

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Assigning material to atlas
« Reply #2 on: July 26, 2015, 07:58:17 PM »
I'd like to change it during runtime via script. Is there a way I can do this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assigning material to atlas
« Reply #3 on: July 27, 2015, 08:37:34 PM »
Exactly the same way. Access the material on the atlas, then change it. However UIPanels can create their own copy of the material for things like scroll views and will change the shader in this material. To change it there you need to access the actual draw calls. Look at UIWidget.onRender -- it will be called with the material used to draw it.

Nomy

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Assigning material to atlas
« Reply #4 on: July 30, 2015, 09:55:28 PM »
Sorry in advance, my C# is a bit rusty. I suppose I would create an instance of UIDrawCall.OnRender and set it to onRender. The delegate takes a Material, but I don't know what I'm supposed to do with the material in the method.

  1. var cb = new UIDrawCall.OnRenderCallback(CbMethod);
  2. someSprite.onRender = cb;
  3.  
  4. void CbMethod(Material mat)
  5. {
  6.  
  7. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assigning material to atlas
« Reply #5 on: July 31, 2015, 10:02:17 PM »
You are overcomplicating it.
  1. someSprite.onRender = MyCustomRender;
  1. void MyCustomRender (Material mat)
  2. {
  3.     Debug.Log("Drawing the sprite. Change the material as needed.");
  4. }
Note: change the material's properties. Don't try to assign a different material. You can change the shader or set shader properties here.