private static void GeneratePackTextureImpl(CNode node, ref PackTextureAttrSet packTextureAttrSet) { if (node != null && packTextureAttrSet != null && packTextureAttrSet.packTexture) { if (node.IsFilled) { TextureVertexAttr attri = node.refTextureInfo; CalcVertexAtrribute( packTextureAttrSet.packTexWidth, packTextureAttrSet.packTexHeight, ref attri ); packTextureAttrSet.texVertexAttrList.Add(attri); Fill2PackTexture(packTextureAttrSet.packTexture, attri); } if (node.leftChild != null) { GeneratePackTextureImpl(node.leftChild, ref packTextureAttrSet); } if (node.rightChild != null) { GeneratePackTextureImpl(node.rightChild, ref packTextureAttrSet); } } }
public void CopyForm(PackTextureAttrSet other) { if (other != null) { packTexture = other.packTexture; packSprite = other.packSprite; texVertexAttrList = new List <TextureVertexAttr>(other.texVertexAttrList); } }
private static void GeneratePackTexture(CNode root, out PackTextureAttrSet outPackTextureAttrSet) { outPackTextureAttrSet = null; if (root != null) { outPackTextureAttrSet = ScriptableObject.CreateInstance <PackTextureAttrSet>(); outPackTextureAttrSet.texVertexAttrList = new List <TextureVertexAttr>(); //后面的格式指定 outPackTextureAttrSet.packTexture = new Texture2D(root.refTextureInfo.blockDetail.rect.w, root.refTextureInfo.blockDetail.rect.h, TextureFormat.RGBA32, false); SetDefaultColor(ref outPackTextureAttrSet.packTexture, mDefaultColor); GeneratePackTextureImpl(root, ref outPackTextureAttrSet); } }
public static void Pack(Texture2D[] splitTexs, int width, int height, out PackTextureAttrSet outPackTextureAttrSet) { outPackTextureAttrSet = null; if (splitTexs != null) { SortTexture(ref splitTexs); CNode rootNode = GenerateRootNode(splitTexs, width, height); if (rootNode != null) { //插一插 for (int i = 0; i < splitTexs.Length; ++i) { if (rootNode.Insert(splitTexs[i]) == null) { string assetPath = AssetDatabase.GetAssetPath(splitTexs[i]); Debug.LogWarning(string.Format("no suitable area:{0}", assetPath)); } } //遍历一下节点树生成图集 GeneratePackTexture(rootNode, out outPackTextureAttrSet); } } }
public static void Pack(Sprite[] sprites, int packTexWidth, int packTexHeight, out PackTextureAttrSet outPackTextureAttrSet) { outPackTextureAttrSet = null; if (sprites != null) { Texture2D[] textures = new Texture2D[sprites.Length]; for (int i = 0; i < sprites.Length; ++i) { Texture2D readyTex = sprites[i].texture;; textures[i] = readyTex; SetTextureReadble(readyTex, true); } Pack(textures, packTexWidth, packTexHeight, out outPackTextureAttrSet); //复原不可读 for (int i = 0; i < textures.Length; ++i) { Texture2D readyTex = textures[i]; if (readyTex != null) { SetTextureReadble(readyTex, false); } } } }