问题
-
Sprite的AssetBundle比预期更大。
-
图集在AssetBundle中被保存两次。
原因
问题 #1
在Unity 5.2.2p4前,Sprite Atlas和AssetBundle共同使用时有个bug。考虑到您想创建两个AssetBundle:
-
三个Sprite被标记为同一个Atlas并被打包进一个AssetBundle("art.unity3d")。
-
一个使用相同Atlas的Sprite并打包进另一个不同的AssetBundle("prefab.unity3d")。
当您创建AssetBundle时,"art.prefab"将包含相应的Sprite顶点,即一个指向Atlas的纹理。第二个预置物体也将存储(复制)这个Atlas纹理。
问题 #2:
另一个问题是当使用者把其中一个Sprite标记进另一个AssetBundle时,这一另外的AssetBundle也将包含这个Atlas的图像。
解决方案
问题 #1:
- 更新到Unity 5.2.2p4或最新版本。
问题 #2:
- 被打包进相同Atlas的Sprite需要被打包进相同的AssetBundle。
下方的图像显示了两个使用相同的AssetBundle和包装标签的Sprite。
下面的这个例子检查这些被分进相同Atlas的Sprite是否被打包进不同的AssetBundle中:
public class SpriteChecker
{
// This will create a Menu named "Support", with a sub-menu
// named "SpriteChecker", in the Editor menu bar. [MenuItem("Support/SpriteChecker")] static void CheckSpritesTagsAndBundles ()
{
// Get all the GUIDs (identifiers in project) of the Sprites in the Project string[] guids = AssetDatabase.FindAssets ("t:sprite");
// Dictionary to store the tags and bundle names Dictionary<string,string> dict = new Dictionary<string, string>(); foreach( string guid in guids)
{ string path = AssetDatabase.GUIDToAssetPath(guid); TextureImporter ti = TextureImporter.GetAtPath( path) as TextureImporter;
// If the tag is not in the dictionary, add it if (!dict.ContainsKey (ti.spritePackingTag )) dict.Add(ti.spritePackingTag, ti.assetBundleName); else
// If the tag is associated with another bundle name, show an error if (dict[ti.spritePackingTag] != ti.assetBundleName) Debug.LogWarning("Sprite : " + ti.assetPath + " should be packed in "+ dict[ti.spritePackingTag] ); }
} }
更多信息