Hello,
I've found a strange issue with UI2DSprite in latest version of NGUI with latest version of Unity3D Pro.
I have a few icons which can be active or locked. So I manage it with code below:
public UnityEngine.Sprite Active;
public UnityEngine.Sprite Locked;
void OnEnable ()
{
var key = "Lesson"+LessonNumber;
if (!PlayerPrefs.HasKey (key))
{
if ( LessonNumber == 1 ) PlayerPrefs.SetString (key, "active");
else
PlayerPrefs.SetString (key, "locked");
PlayerPrefs.Save ();
}
LessonState = PlayerPrefs.GetString (key);
switch (LessonState)
{
case "active":
GetComponent<UI2DSprite> ().sprite2D = Active;
Debug.Log ("Sprite is "+GetComponent<UI2DSprite> ().sprite2D);
break;
case "locked":
GetComponent<UI2DSprite> ().sprite2D = Locked;
break;
}
}
It worked fine before I've update NGUI for latest version.
Now it works in this manner:
Application starts.
All sprites set up in right way.
When state of some icons changed Debug.log shows me that sprite2D component changes to right value, but nothing happens on scene and also inspector still shows old value in UI2DSprite component.
Can you help me with this issue or give me some advice?
UPDATE:
Looks like the problem is in the UIButton script which attached to my icons.
Logs from UI2Dsprite constructor:
// Set sprite2d to proper value after call from my script:
SET sprite2D to Lesson_2 (UnityEngine.Sprite)
UnityEngine.Debug:Log(Object)
UI2DSprite:set_sprite2D(Sprite) (at Assets/NGUI/Scripts/UI/UI2DSprite.cs:49)
LessonIcon_Control:OnEnable() (at Assets/Scripts/LessonIcon_Control.cs:44)
UnityEngine.GameObject:SetActive(Boolean)
//debug.log from my script, shows right value for sprite2d
Sprite is Lesson_2 (UnityEngine.Sprite)
UnityEngine.Debug:Log(Object)
LessonIcon_Control:OnEnable() (at Assets/Scripts/LessonIcon_Control.cs:47)
//OOPS! UIButton revert sprite2d value to previos :
SET sprite2D to Lesson_2_locked (UnityEngine.Sprite)
UnityEngine.Debug:Log(Object)
UI2DSprite:set_sprite2D(Sprite) (at Assets/NGUI/Scripts/UI/UI2DSprite.cs:49)
UIButton:SetSprite(Sprite) (at Assets/NGUI/Scripts/Interaction/UIButton.cs:304)
UIButton:SetState(State, Boolean) (at Assets/NGUI/Scripts/Interaction/UIButton.cs:275)
UIButton:OnEnable() (at Assets/NGUI/Scripts/Interaction/UIButton.cs:213)
Removing UIButton component helps. Now I will try to investigate what wrong wuth UIButton cause I would like to continue using it.