Author Topic: Change UITexutre's material offset at runtime didn't work like it in 2.x  (Read 3178 times)

simon129

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 20
    • View Profile
I'm using 3.0.2

reproduce step:
  • Create a new scene.
  • Through menu [NGUI] -> [Create] -> [Texture]
  • Assign "Fantasy Atlas" material provided from NGUI package to UITexture's material
  • Attach the code below
  • Hit Play

In my game, I use a custom shader to mask the texture, so I can't use UITexture's UV setting.
I tried MarkAsChanged(), it didn't work.
Disable/Enable UITexture or panel.Refresh() work, but I think I should not do that at runtime.
How do I make it work in 3.0.2 ?

Thanks.

  1. using UnityEngine;
  2. public class UITextureOffset : MonoBehaviour
  3. {
  4.         float offset;
  5.         UITexture tex;
  6.         void Start()
  7.         {
  8.                 tex = GetComponent<UITexture>();
  9.         }
  10.         void Update()
  11.         {
  12.                 offset += Time.deltaTime;
  13.                 if (offset > 1)
  14.                         offset = 0;
  15.                 tex.material.mainTextureOffset = new Vector2(offset, 0);
  16.         }
  17. }
  18.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change UITexutre's material offset at runtime didn't work like it in 2.x
« Reply #1 on: October 16, 2013, 02:38:29 AM »
UIWidget.drawCall.dynamicMaterial lets you modify it as you see fit.

Note that this may not be present in 3.0.2 -- but it's there in the current latest version that's available to Pro users -- so if you don't see it, you will see it in the next update.

I've also posted the source code for it a few days ago. It's a simple 'get' property that returns the "mMat" on the draw call.