Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - HankTurbo

Pages: [1]
1
Support / Re: Create SpriteCollection(s) via code
« on: October 30, 2014, 11:36:19 pm »
Thanks for the reply.

I agree that the "data driven sprite collections" looks a lot better than my approach, and if I get time I will update the code to make use of that much better framework.

Again, thanks for your help.

2
Support / Re: Create SpriteCollection(s) via code
« on: October 29, 2014, 11:17:22 pm »
And then I figured it out...

Quote
GameObject.DestroyImmediate(go);

Had to be done after the rebuild.

Thanks for your help!

3
Support / Re: Create SpriteCollection(s) via code
« on: October 29, 2014, 10:17:58 pm »
Thanks.

I'll have a look at it.

What do you mean?
Quote
It looks like your'e recreating the prefab every time...

For my own sake I would like to know what I'm doing wrong. I hate not getting stuff working. So any help would be much appreciated.

This code snippet will generate a SpriteCollection for one page in the book. If a SpriteCollection already exists, it will not try and create it. Otherwise it will need to create it. This snippet of code will run XX amount of times. The SpriteCollection only holds one Sprite, and as far as I can tell, don't I then need to:
1. create a temp gameobject to add a new SpriteCollection
2. create the new sprite collection prefab
3. set sprite collections settings
4. add textures/sprites
5. build sprite collection

4
Support / Create SpriteCollection(s) via code
« on: October 29, 2014, 06:13:28 am »
Hiya,

I'm trying to set up an automated system for creating SpriteCollection(s). I'm creating a book, and each book has one large image. So what I'm trying to do is to create one SpriteCollection per page using an EditorWindow. The problem I'm having is that I run into an issue where tk2dSpriteCollectionBuilder.Rebuild runs, but the SpriteCollection doesn't keep its reference to the Data Object (SpriteCollectionData), and because of that I get the error: "Sprite collection (xxx) has no sprites" when I try to set a tk2dSprite to the given SpriteCollection.

Code: [Select]
string basepath = SPRITE_COLLECTION_BASEPATH + _bookID + "/";
string filename = _bookID + "_" + "Page" + pageNum + ".prefab";
string prefabPath = basepath + filename;

if (new FileInfo(prefabPath).Exists) {
D.Log("Ignoring to create a SpriteCollection as it already exists: '" + filename + "'.");
return;
}

// create game object with sprite collection
GameObject go = new GameObject("TempSpriteCollection");
tk2dSpriteCollection collection = go.AddComponent<tk2dSpriteCollection>();
collection.version = tk2dSpriteCollection.CURRENT_VERSION;
tk2dEditorUtility.SetGameObjectActive(go, false);

// create potential target folder
DirectoryInfo targetFolder = new DirectoryInfo(basepath);
if (!targetFolder.Exists) Directory.CreateDirectory(basepath);

// create prefab
UnityEngine.Object p = PrefabUtility.CreateEmptyPrefab(prefabPath);
GameObject collectionPrefabGo = PrefabUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
tk2dSpriteCollection collectionFromPrefab = collectionPrefabGo.GetComponent<tk2dSpriteCollection>();
GameObject.DestroyImmediate(go);

// adjust SpriteCollection settings
collectionFromPrefab.sizeDef.type = tk2dSpriteCollectionSize.Type.PixelsPerMeter;
collectionFromPrefab.sizeDef.pixelsPerMeter = 1;
collectionFromPrefab.maxTextureSize = 4096;
tk2dSpriteCollectionPlatform platform2x = new tk2dSpriteCollectionPlatform();
platform2x.name = tk2dSystem.GetAssetPlatform("2x").name;
tk2dSpriteCollectionPlatform platform1x = new tk2dSpriteCollectionPlatform();
platform1x.name = tk2dSystem.GetAssetPlatform("1x").name;
collectionFromPrefab.platforms = new List<tk2dSpriteCollectionPlatform>(new tk2dSpriteCollectionPlatform[] { platform2x, platform1x } );

// create defintion for sprite/texture page
tk2dSpriteCollectionDefinition def = new tk2dSpriteCollectionDefinition();
def.name = "Page" + pageNum;
def.colliderType = tk2dSpriteCollectionDefinition.ColliderType.UserDefined;
def.texture = (Texture2D)AssetDatabase.LoadAssetAtPath(SPRITE_BASEPATH + _bookID + "/" + "Page" + pageNum + "@2x.jpg", typeof(Texture2D));
def.dice = true;
def.diceUnitX = def.diceUnitY = 256;

// add sprite/texture page defintion to SpriteCollection
List<tk2dSpriteCollectionDefinition> list = new List<tk2dSpriteCollectionDefinition>();
list.Add(def);
collectionFromPrefab.textureParams = list.ToArray();

// build SpriteCollection
tk2dSpriteCollectionBuilder.Rebuild(collectionFromPrefab);
Debug.Log("collectionFromPrefab.spriteCollection = " + collectionFromPrefab.spriteCollection);

AssetDatabase.Refresh();

At the end I log the data object and it's correct there, and then when I check the SpriteCollection in the Editor it is missing.

This doesn't happen all the time. I would initially run this code for X number of pages. And it would happen sometimes after one page has been completed, and sometimes straight away. I don't think I have seen it run more that two times before failing (texture size at 2x: 2732x1931). If I run it doing one page at a time, it will still fail after one, two or three runs.

The SpriteCollectionData prefab is generated correctly and sits in its Data folder. If I then try and run a "Commit" from the Editor it will start creating new Data objects that don't work. Probably because all the names get all haywired.

Hope you can give me a hint on how to solve this. I was hoping to avoid doing a lot of manual work for this.

5
Support / Re: Asset Bundle and tk2d
« on: September 22, 2014, 11:09:14 am »
Cheers, I'll give it a crack... just don't like modifying external libraries too much in case I need to update it for some reason (creates a general havoc).

Thanks for quick and helpful replies!

6
Support / Re: Asset Bundle and tk2d
« on: September 22, 2014, 10:41:13 am »
Thanks for that, I'll keep that in mind next time it happens.

Would my approach to platform bundles work, or should I find another way to do it?

7
Support / Re: Asset Bundle and tk2d
« on: September 22, 2014, 03:44:22 am »
Yes, I'm using platform collections. I have however made a system where I followed instructions from this forum entry http://2dtoolkit.com/forum/index.php?topic=1522.0
Would the scenario mentioned in this forum entry not work? If I build seperate bundles with 1x and 2x textures, and load them... would it not set the correct sprites using this approach? I am still at making bundles stage, so haven't loaded any of them in yet.

However waking up Monday morning with a fresh restart on my machine, I don't get the error anymore?? So it seems fixed(?), or that is at least the dream.

I will report back with more information if it start occuring again.

8
Support / Re: Asset Bundle and tk2d
« on: September 21, 2014, 12:42:03 am »
Thanks for the quick reply.

It's definitely an error, or at least that's what it's coming up as in the editor.

If I create a bundle with a single prefab with the above mentioned content, I get the error and the file size for the bundle is about 5.5 MB.
If I create a bundle with only the SpriteCollectionData object from the sprite in the prefab I don't get the error and file size for the bundle is about 10.5 MB.

So unfortunately I don't think it is creating the bundle correctly.

The only special thing I'm doing is that I've disabled "//if (!i.managedSpriteCollection)" in "BuildLookupIndex" for "tk2dSpriteGuiUtility", to be able to choose 1x and 2x SpriteCollections in the editor. So I can build seperate bundles for 1x and 2x.

I've attached a zip file of the actual prefab, but I don't know if that is enough? Do you want a whole project setup?

9
Support / Asset Bundle and tk2d
« on: September 19, 2014, 06:17:50 am »
Hiya,

First of I would like to congratulate you on a fantastic product.

I have an issue with Asset Bundles and tk2d where I get the following error
    Inconsistent asset when sorting preload assets: '' fileID: 0

My asset bundle is extremely simple. I have one prefab which consist of
 - prefab (empty gameobject)
  -> sprite (tk2dSprite)

When I try and build a bundle (with dependencies) from this prefab (using the script from here http://docs.unity3d.com/Manual/abfaq.html), it throws the above error.

I tested building a bundle from just a tk2dSpriteCollectionData, and that works fine.
I tested building a bundle with just empty gameobjects, and that works fine.
But with a tk2dSprite attached to a gameobject it doesn't work.

Is this not possible?

Thanks in advance for any help given.

Pages: [1]