Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: simon129 on October 15, 2013, 01:55:27 AM

Title: Change UITexutre's material offset at runtime didn't work like it in 2.x
Post by: simon129 on October 15, 2013, 01:55:27 AM
I'm using 3.0.2

reproduce step:

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.  
Title: Re: Change UITexutre's material offset at runtime didn't work like it in 2.x
Post by: ArenMook 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.