Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: cheuksh on April 25, 2014, 09:17:02 AM

Title: Pic does not show up after mainTexture assigned.
Post by: cheuksh on April 25, 2014, 09:17:02 AM
If I click the button, the texture show.
But if I change the PicReady from its own class, the texture not show....

Is it any hidden function inside the OnClick event that need to update or redraw the pic. Any other function I need to call if I update the texture outside the on click event?


  1.         public UITexture uiTexture;    
  2.         public MyPicPick MyPic;
  3.  
  4.         void Start() {
  5.                 StartCoroutine(UpdateImage());
  6.         }
  7.  
  8.         void OnClick() {
  9.                 NGUIDebug.Log("Call From On Click");
  10.                 MyPic.PicReady = true;         
  11.         }
  12.  
  13.         public void ChangePicReady() {
  14.                 NGUIDebug.Log("Call From Other");
  15.                 MyPic.PicReady = true;
  16.         }
  17.  
  18.         IEnumerator UpdateImage() {
  19.                 while (true) {
  20.                         yield return new WaitForSeconds(4);
  21.                         if (MyPic.PicReady) {                          
  22.                                 string url = "file://" + PlayerPrefs.GetString("PicPath");
  23.                                 WWW www = new WWW(url);
  24.                                 yield return www;
  25.                                 uiTexture.mainTexture = www.texture;
  26.                         }
  27.                 }
  28.         }
Title: Re: Strange behavior
Post by: ArenMook on April 25, 2014, 10:19:56 AM
No, there is no difference. And in your case all you're doing is flipping a (what looks like) boolean value. There is no difference in logic.
Title: Re: Strange behavior
Post by: cheuksh on April 25, 2014, 06:27:25 PM
But calling both function directly the new texture wont draw. Only I click the button and let the UICamera event listener system fire the onClick then, the texture change.

I NGUIDebug.Logged the width of the texture in both case right after I assigned the www.texture to the mainTexture, and the mainTexture show a value of 600, meaning the texture are correctly assigned. I called the ChangePicReady() function from other class which is basically class is initiated by an Android Image Picker Plugin. It save a texture from the Photo Library and return a path. I physically confirmed that the file are there. So it is nothing wrong to with the picker plugin,(The path are the same in both case anyway). I also tried to call the onclick function directly from the picker plugin, again, function is called, UpdateImage() function runned smoothyly, maintexture changed. But it just wont show up until I physically click it. I was stuck for two days already and without any clue.....
Title: Re: Pic does not show up after mainTexture assigned.
Post by: cheuksh on April 25, 2014, 10:28:12 PM
To demonstrate it:
I modified the code with debug message and took some screen shot for comparison:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class test : MonoBehaviour {
  5.  
  6.         // Use this for initialization 
  7.         public UITexture uiTexture;    
  8.         public bool  PicReady = false;
  9.  
  10.         void Start() {
  11.                 NGUIDebug.Log(Time.frameCount + "Before Assignement mainTexture Width is" + uiTexture.mainTexture.height);
  12.                 StartCoroutine(UpdateImage());
  13.         }
  14.  
  15.         public void OnClick() {
  16.                 NGUIDebug.Log(Time.frameCount + " I clicked the button");
  17.                 PicReady = true;               
  18.         }
  19.  
  20.         public void ChangePicReady() {
  21.                 NGUIDebug.Log(Time.frameCount + " I changed the PicReady from other script");
  22.                 PicReady = true;
  23.         }
  24.  
  25.         IEnumerator UpdateImage() {
  26.                 while (true) {
  27.                         yield return new WaitForSeconds(5);
  28.                         if (PicReady) {                        
  29.                                 string url = "file://" + PlayerPrefs.GetString("PicPath");
  30.                                 NGUIDebug.Log(Time.frameCount + " PicReady: " + PicReady + " url " + url);
  31.                                 WWW www = new WWW(url);
  32.                                 yield return www;                              
  33.                                 uiTexture.mainTexture = www.texture;
  34.                                 NGUIDebug.Log(Time.frameCount + " After Assigned mainTexture " + uiTexture.mainTexture.height);
  35.                         }
  36.                 }
  37.         }
  38. }
  39.  

You can see from my attachement pic. I first called ChangePicReady(), at frame 616. Then, UpdateImage() called three times, you can see the mainTexture width changed from 302 (at frame 1) to 427 (at frame 693). Which means texture assigned sucessfully but it does not draw. And then I click the test button which contains this test script at frame 1260. The Little Pong Texture show up after the next UpdateImage() called.
Title: Re: Pic does not show up after mainTexture assigned.
Post by: ArenMook on April 26, 2014, 03:11:13 PM
Think about it logically. Why would it matter where the boolean value is assigned from?

What version of NGUI are you using here?
Title: Re: Pic does not show up after mainTexture assigned.
Post by: cheuksh on April 28, 2014, 04:27:40 AM
Version 3.0.6 f7
It shouldn't be the flipping of a bool value...So I better rephase the issue:

UITexture's mainTexture assigned successfully (by checking the mainTexture width), but the texture not draw and remain the old one.

Is it because callback is from other application outside unity (Android Photo Library)..
Is it because I am clicking the cloned version of a gameObject including all button and sprite..

The behavior really very strange....difficult to believe ..that's why I enclose the pic with step by step debug message.
Actaully event I called OnClick from other script, it wont show up. only when the Onclick is called by the UICamera event, then it show.
Title: Re: Pic does not show up after mainTexture assigned.
Post by: ArenMook on April 29, 2014, 02:26:42 PM
Yeah... please update. 306 is very old. I can only help with the latest version.