Author Topic: Atlases Prefab disconnected with its material, texture, and sprites  (Read 3496 times)

miyudreams

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Hi, I have a pipeline that creates many atlases prefabs using UIAtlasMaker API, through an editor script. This tool will create a material, a texture, and a prefab. After the generation, to test one of the newly created atlas Prefab, I dragged it into the Atlas Maker for viewing, the material, texture, and the sprite list looks good. (See attached PipelineTest.png)

I then take these atlases & move them to the appropriate game projects. These atlases are then imported into this Unity project. Again, I try testing out an atlas prefab by opening it in the Atlas Maker, the links to the material, & materials' link to the texutre, and the sprite list textures are disconnected (or empty). (See attached NewProject_onImport.png). Even if I try to reconnect the material & texture, the sprite list is still showing up as 0x0. (See attached NewProject_reconnect.png).

Any ideas here?
Thank you

Unity 5.1.3f1
NGUI 3.9.0

My pipeline tool script to create the atlas prefab is summarized below:

1. Load all needed png images as Texture2D into an array, allImageTex
2. Create a new Texture2D for the atlas material, atlasTex, & save to png:
  1. File.WriteAllBytes (texturePath, atlasTex.EncodeToPNG ());
3. Create a new Material:
  1. var material = new Material (Shader.Find ("Unlit/Transparent Colored"));
4. Call PackTextures:
  1. Rect [] coordinates = atlasTex.PackTextures (allImageTex.ToArray(), ATLAS_PADDING, TEXTURE_MAX_SIZE);
5. Set the material to the atlas texture:
  1. material.SetTexture ("_MainTex", atlasTex);
6. Save out the material texture:
  1. AssetDatabase.CreateAsset (material, newFolderDir + ".mat");
7. Loop through the Rect coordinates to create new UIAtlasMaker.SpriteEntry
  1. UIAtlasMaker.SpriteEntry se = new UIAtlasMaker.SpriteEntry();
  2. se.x = Mathf.RoundToInt(coordinate.x * width);
  3. se.y = Mathf.RoundToInt(coordinate.y * height);
  4. se.width = Mathf.RoundToInt(coordinate.width * width);
  5. se.height = Mathf.RoundToInt(coordinate.height * height);
  6. se.name = allImageTex[i].name;
  7. se.SetTexture(texPixels, se.width, se.height);
8. Update the atlas with the list of SpriteEntry per sprite texture added:
  1. UIAtlasMaker.UpdateAtlas(atlas, listSpriteEntry);
  2. atlas.MarkAsChanged();

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Atlases Prefab disconnected with its material, texture, and sprites
« Reply #1 on: September 26, 2015, 04:52:37 PM »
I suggest you have a closer look at UIAtlasMaker.UpdateTexture function. You can't just create materials / textures, then save them to disk and expect Unity to keep references. When you create something, you create an instance of it. You need to load whatever you saved after you've done so and use that reference instead. Note line 608 of UIAtlasMaker.cs:
  1. tex = NGUIEditorTools.ImportTexture(newPath, false, true, !atlas.premultipliedAlpha);