Author Topic: UITexture.mainTexture cannot unload resources?  (Read 2027 times)

hjbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
UITexture.mainTexture cannot unload resources?
« on: January 02, 2014, 03:10:11 AM »
code:
      Texture texture = uiTexture .mainTexture;
      mainBGUITexture.mainTexture = Resources.Load(path + "/" + curFrame, typeof(Texture)) as Texture;
      Resources .UnloadAsset (texture);
this code run in Update Function´╝îResources .UnloadAsset (texture) does not work,but it work well on NGUI 2.6
I did not carefully read UITexture code,but add two lines of code:uiTexture.enable= false;uiTexture.enable= true;
it can UnloadAsset ,why?  Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture.mainTexture cannot unload resources?
« Reply #1 on: January 02, 2014, 11:37:44 AM »
NGUI panels create draw calls. Draw calls reference textures. When you set some UITexture's mainTexture reference, the change won't result in the draw calls being destroyed right away. The call will be delayed.

You need to delay your UnloadAsset call until the end of frame (yield new WaitForEndOfFrame()).

hjbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UITexture.mainTexture cannot unload resources?
« Reply #2 on: January 02, 2014, 11:38:57 PM »
Thank you very much