public virtual void AddDynamicSpriteData(string spriteName, Texture2D textureReference, DynamicSpriteData.eSpriteResTypes type, bool is_runtime = true) { }
public override void AddDynamicSpriteData(string spriteName, Texture2D textureReference, DynamicSpriteData.eSpriteResTypes type, bool is_runtime = true) { DynamicSpriteData data = GetFreeSpriteData(); if (data == null) { data = new DynamicSpriteData(); m_DynamicSpriteDatas.Add(data); } else { SquareAllocator.Node node = data.UserData as SquareAllocator.Node; if (node != null) { m_Allocator.Free(node); } } if (textureReference != data.TextureReference) { data.UnloadTexture(); } data.name = spriteName; data.SpriteResourceType = type; data.UsageReference = is_runtime ? 1 : 0; data.RuntimeFlag = is_runtime; data.TextureReference = textureReference; CalculateSpriteData(data); }
public override void AddDynamicSpriteData(string spriteName, Texture2D textureReference, DynamicSpriteData.eSpriteResTypes type, bool is_runtime = true) { DynamicSpriteData sprite_data = GetFreeSpriteData(); if (sprite_data != null) { if (sprite_data.TextureReference != textureReference) { sprite_data.UnloadTexture(); } sprite_data.name = spriteName; sprite_data.TextureReference = textureReference; sprite_data.UsageReference = is_runtime ? 1 : 0; sprite_data.RuntimeFlag = is_runtime; sprite_data.SpriteResourceType = type; } else { EB.Debug.LogError("Try to load two many fixed-size textures in dynamic atlas"); } }
public override void AddDynamicSpriteData(string spriteName, Texture2D textureReference, DynamicSpriteData.eSpriteResTypes type, bool is_runtime = true) { //EB.Debug.LogError("AddDynamicSpriteData spriteName : {0}", spriteName); DynamicSpriteData data = GetSpriteData(spriteName); if (data != null) { EB.Debug.LogError("AddDynamicSpriteData: spriteName {0} exists", spriteName); data.AddReference(); return; } data = new DynamicSpriteData(); data.name = spriteName; data.SpriteResourceType = type; data.UsageReference = is_runtime ? 1 : 0; data.RuntimeFlag = is_runtime; data.TextureReference = textureReference; m_DynamicSpriteDatas.Add(data); if (!m_SpritePacker.PackSprites(m_DynamicSpriteDatas)) { //Debug.Log("AddDynamicSpriteData: CAN NOT pack all of the sprites in the atlas, try reuse unused node"); //failed to pack, get free space from current page. var freeData = FindFreeSpriteData(textureReference.width, textureReference.height); if (freeData == null) { //Debug.LogWarning("AddDynamicSpriteData: CAN NOT pack all of the sprites in the atlas, try remove unused node"); for (int i = m_DynamicSpriteDatas.size - 1; i >= 0; --i) { if (m_DynamicSpriteDatas[i].RuntimeFlag && m_DynamicSpriteDatas[i].UsageReference <= 0) { m_DynamicSpriteDatas[i].UnloadTexture(); m_DynamicSpriteDatas.RemoveAt(i); } } EB.Debug.LogError("================== m_DynamicSpriteDatas : {0}", m_DynamicSpriteDatas.size); } else { //Debug.LogFormat("AddDynamicSpriteData: {0} reuse node {1}", spriteName, freeData.name); m_DynamicSpriteDatas.Remove(data); if (freeData.TextureReference != textureReference) { freeData.UnloadTexture(); } freeData.name = spriteName; freeData.SpriteResourceType = type; freeData.UsageReference = is_runtime ? 1 : 0; freeData.RuntimeFlag = is_runtime; freeData.TextureReference = textureReference; } m_Packed = false; } else { m_Packed = true; } }