Hello Guest

Author Topic: How can I change the tk2dSprite's "Texture" in runtime?  (Read 6419 times)

zyy

  • Newbie
  • *
  • Posts: 3
    • View Profile
How can I change the tk2dSprite's "Texture" in runtime?
« on: August 08, 2013, 04:52:49 am »
tk2dSprite and it's tk2dSpriteCollectionData is builded in Unity's Editor,
Only need re-link the texture at runtime.
Because need pack the texture in assetBundle, and download at runtime;
this is my test code,
but get a err message :

"UnassignedReferenceException: The variable material of 'tk2dSpriteCollectionData' has not been assigned.
You probably need to assign the material variable of the tk2dSpriteCollectionData script in the inspector."

Code: [Select]
        GameObject nol = GameObject.Find( "normal" );
        tk2dSprite script = (tk2dSprite)nol.GetComponent( "tk2dSprite" );
        tk2dSpriteCollectionData col = script.Collection;
        Material mat = col.material;
        mat.SetTexture( "txt", loadTex );
        //Texture tex = mat.mainTexture;
        //tex = loadTex;
« Last Edit: August 08, 2013, 10:18:46 am by zyy »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I change the tk2dSprite's "Texture" in runtime?
« Reply #1 on: August 08, 2013, 08:55:45 am »
What are you trying to do here? Is there any reason you're not putting the asset bundle into the atlas itself?

zyy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: How can I change the tk2dSprite's "Texture" in runtime?
« Reply #2 on: August 08, 2013, 10:12:02 am »
What are you trying to do here? Is there any reason you're not putting the asset bundle into the atlas itself?

Thanks your reply.

putting the asset bundle into the atlas itself?

I want to pack the atlas into a asset bundle;
download it from httpServer when the client at runtime, and re-link it with tk2dSprite , it's tk2dSpriteCollectionData,
(Sprite and SpriteCollectionData has been created in unityEditor not at runtime)
« Last Edit: August 08, 2013, 10:24:01 am by zyy »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I change the tk2dSprite's "Texture" in runtime?
« Reply #3 on: August 08, 2013, 09:00:07 pm »
You can find some sample code to create and use sprite collection asset bundles on this thread:
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,2277.0.html

Hope that helps.

zyy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: How can I change the tk2dSprite's "Texture" in runtime?
« Reply #4 on: August 09, 2013, 02:59:42 am »
Thanks~