Hello Guest

Author Topic: tk2dSpriteAnimation and AssetBundles. Clarifications needed.  (Read 4507 times)

KarlBuiter

  • Newbie
  • *
  • Posts: 2
    • View Profile
tk2dSpriteAnimation and AssetBundles. Clarifications needed.
« on: September 12, 2013, 03:44:35 am »
Hello,

  I have a project that successfully uses TK2D for several sets of Sprite Animations.  I now need to expand the project to several flavors and will load assets using AssetBundles and instantiate the loaded prefabs.

  I exported all the art, sprite, animation, and prefab objects into an empty project.  This was related to a thread discussing asset isolation.  TK2D was imported.  I have been experimenting with both forms of ExportAssetBundles... one method involves creating separate bundles for Sprites, Animations, then Prefabs without dependencies; the other involves packing the bundle at the Prefab level with dependencies.

  In the main program, I have been loading each of the asset bundles (in order) with LoadAll() for Sprites and Animations; then explicit load and instantiation for each of the prefabs.

  The Sprites seem to work - though they seem to be misbehaving someone on being active or not active.  But with Animations - I get the first frame of the animation - the properties/watch suggest all frames are referenced, its playing, has fps, it is not paused, etc.  But nothing plays.

  I have seen references to including SpriteCollectionData data component in the bundle.  I followed a reference a Demo Sprite Collection and copying the data part to my assetbundle but its only 6k, not 28k as suggested.  This whole part is a bit confusing.

  So here is a bit of code on how I am trying to load this (in a non-dependency way)

   void LoadSpritesBundle ()
   {   
      var assetPath = "file://" + Application.dataPath + "/Bundles/MySceneSprites.unity3d";
      
      // Open the Asset
      WWW www = WWW.LoadFromCacheOrDownload (assetPath, 1);
      
      // Get the Asset Bundle
      AssetBundle bundle = www.assetBundle;
      
      // Load all the assets
      bundle.LoadAll ();
   }   
   
   void LoadAnimsBundle()
   {   
      var assetPath = "file://" + Application.dataPath + "/Bundles/MySceneAnims.unity3d";
      
      // Open the Asset
      WWW www = WWW.LoadFromCacheOrDownload (assetPath, 1);
      
      // Get the Asset Bundle
      AssetBundle bundle = www.assetBundle;
      
      // Load all the assets
      bundle.LoadAll ();
   }
   
   void LoadPrefabBundle()
   {
      GameObject myObject;

      var assetPath = "file://" + Application.dataPath + "/Bundles/MyScenePrefabs.unity3d";
      
      // Open the Asset
      WWW www = WWW.LoadFromCacheOrDownload (assetPath, 1);
      
      // Get the Asset Bundle
      AssetBundle bundle = www.assetBundle;
      
      // Load
      myObject = bundle.Load ( "MyObject", typeof(GameObject)) as GameObject;
      Instantiate (myObject);
      //Instantiate (myObject, new Vector3(87.0f,81.0f,-5.1f),Quaternion.identity);
      myObjectAnimatedSpriteArray[0] = myObject.GetComponent<tk2dAnimatedSprite>();
....
}

I obviously gone on a tangent.  But the info I have digested so far seems to have confused me a bit... particularly the SpriteCollection Data part.

Help me find my way back :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSpriteAnimation and AssetBundles. Clarifications needed.
« Reply #1 on: September 12, 2013, 11:21:04 am »
I've not experienced any issues with asset bundles at all. I think part of it is how you're creating it in the first place, and what you're actually putting in them. I don't imagine we're going to get very far describing things in the forum - lots of things can go wrong here. Can you create a simple demo project for this and email to support at unikronsoftware dot com? Happy to take a look for you.

KarlBuiter

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: tk2dSpriteAnimation and AssetBundles. Clarifications needed.
« Reply #2 on: September 12, 2013, 10:49:30 pm »
I got it running.  It was a flub in my instantiation reference...  component grab from the prefab, not the instantiated object.

Thanks,  Good exercise.