Hello Guest

Author Topic: 2.0 Migration for Atlas Generation API  (Read 4791 times)

aninocoders

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
2.0 Migration for Atlas Generation API
« on: August 19, 2013, 08:35:29 am »
Hello,

Our atlas generator no longer works in 2.1. API changes to tk2dSpriteCollection is not specified anywhere in the Migration Guide. This is the code that no longer compiles:


        private void CreateSpriteCollection(Dictionary<string, string> idAssetsPathMap) {
         // create game object with sprite collection
         GameObject go = new GameObject(spriteCollectionName);
         tk2dSpriteCollection collection = go.AddComponent<tk2dSpriteCollection>();
         collection.version = tk2dSpriteCollection.CURRENT_VERSION;
         
         UnityEngine.Object p = PrefabUtility.CreateEmptyPrefab(spriteCollectionPath);
           GameObject collectionPrefabGo = PrefabUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
         tk2dSpriteCollection collectionFromPrefab = collectionPrefabGo.GetComponent<tk2dSpriteCollection>();
         GameObject.DestroyImmediate(go);
         
         // prepare collection parameters
         collectionFromPrefab.textureParams = new tk2dSpriteCollectionDefinition[idAssetsPathMap.Count];
         collectionFromPrefab.targetHeight = dataManager.ScreenHeight;
         collectionFromPrefab.targetOrthoSize = 1.0f;
         collectionFromPrefab.maxTextureSize = 2048;
         collectionFromPrefab.forceSquareAtlas = true;
         collectionFromPrefab.textureCompression = this.textureCompression;
         collectionFromPrefab.allowMultipleAtlases = true;
         
         // add textures to the collection
         int i = 0;
         foreach(KeyValuePair<string, string> entry in idAssetsPathMap) {
            Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(entry.Value, typeof(Texture2D));
            
            collectionFromPrefab.textureParams = new tk2dSpriteCollectionDefinition();
            collectionFromPrefab.textureParams.name = entry.Key;
            collectionFromPrefab.textureParams.colliderType = tk2dSpriteCollectionDefinition.ColliderType.ForceNone;
            collectionFromPrefab.textureParams.texture = texture;
            
            ++i;
         }
         
         tk2dSpriteCollectionBuilder.Rebuild(collectionFromPrefab);
      }


tk2dSpriteCollection.targetHeight (and some others) are no longer public and there's no property or setter that we can use. How do we fix this?

aninocoders

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: 2.0 Migration for Atlas Generation API
« Reply #1 on: August 19, 2013, 09:19:07 am »
My current workaround is I set tk2dSpriteCollection.targetHeight and tk2dSpriteCollection.targetOrthoSize to public. But this is a hacky fix. Also the generated sprites no longer have the same size as it did before.

aninocoders

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: 2.0 Migration for Atlas Generation API
« Reply #2 on: August 19, 2013, 09:45:24 am »
Found it:

tk2dSpriteCollection.sizeDef

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 2.0 Migration for Atlas Generation API
« Reply #3 on: August 19, 2013, 09:54:40 am »
Yup. That has changed to support pixels per meter, etc using a common GUI.

Just as a quick tip - since everything in tk2d is almost always backwards compatible, look for an Upgrade function if in doubt about the non-public API. The upgrade function will upgrade the structs, and you can work out whats happened to these variables. Eg. sizeDef.CopyFromLegacy( useTk2dCamera, targetOrthoSize, targetHeight );