예제 #1
0
        public void GetTeture(string name, OnCallBackTexRect callback)
        {
            if (m_UsingTexture.ContainsKey(name))
            {
                if (callback != null)
                {
                    SaveTextureData data = m_UsingTexture[name];
                    data.referenceCount++;
                    Texture2D tex2D = m_PageList[data.texIndex].texture;
                    callback(tex2D, data.rect);
                }
            }
            else
            {
                //FIXME! 这里需要改成自己的加载方式
                var texture = Resources.Load <Texture2D>(name);
                //---------------
                if (texture == null)
                {
                    Debug.LogError("Failed To load Texture:" + name);
                    callback(null, new Rect(0, 0, 0, 0));
                    return;
                }

                GetTextureData data = DynamicAtlasMgr.S.AllocateGetTextureData();
                data.name     = texture.name;
                data.callback = callback;
                m_GetTextureTaskList.Add(data);

                OnRenderTexture(data.name, texture);
            }
        }
예제 #2
0
        private void OnRenderTexture(string name, Texture2D texture2D)
        {
            if (texture2D == null)
            {
                for (int i = m_GetTextureTaskList.Count - 1; i >= 0; i--)
                {
                    GetTextureData task = m_GetTextureTaskList[i];
                    if (task.name.Equals(name))
                    {
                        if (task.callback != null)
                        {
                            task.callback(null, new Rect(0, 0, 0, 0));
                        }
                    }

                    DynamicAtlasMgr.S.ReleaseGetTextureData(task);
                    m_GetTextureTaskList.RemoveAt(i);
                }

                return;
            }

            int index = 0;
            IntegerRectangle useArea = InsertArea(texture2D.width, texture2D.height, out index);

            // Debug.LogError(name + ":Index:" + index);

            if (useArea == null)
            {
                Debug.LogError("No Area");
                return;
            }

            Rect uv = new Rect((useArea.x), (useArea.y), texture2D.width, texture2D.height);

            m_PageList[index].AddTexture(useArea.x, useArea.y, texture2D);

            SaveTextureData saveTextureData = DynamicAtlasMgr.S.AllocateSaveTextureData();

            saveTextureData.texIndex = index;
            saveTextureData.rect     = uv;
            m_UsingTexture[name]     = saveTextureData;

            for (int i = m_GetTextureTaskList.Count - 1; i >= 0; i--)
            {
                GetTextureData task = m_GetTextureTaskList[i];
                if (task.name.Equals(name))
                {
                    m_UsingTexture[name].referenceCount++;
                    if (task != null)
                    {
                        // Texture2D dstTex = m_Page.texture;//m_Tex2DLst[index];
                        Texture2D dstTex = m_PageList[index].texture;
                        task.callback(dstTex, uv);
                    }
                }
                DynamicAtlasMgr.S.ReleaseGetTextureData(task);
                m_GetTextureTaskList.RemoveAt(i);
            }
        }
예제 #3
0
        public GetTextureData AllocateGetTextureData()
        {
            if (m_GetTextureDataList.Count > 0)
            {
                return(m_GetTextureDataList.Pop());
            }
            GetTextureData data = new GetTextureData();

            return(data);
        }
예제 #4
0
        public void SetTexture(Texture texture, OnCallBackTexRect callBack)
        {
            if (texture == null)
            {
                Debug.Log("Texture is Null");
                callBack(null, new Rect(0, 0, 0, 0));
                return;
            }

            if (texture.width > m_Width || texture.height > m_Height)
            {
                Debug.Log("Texture is too big");
                callBack(null, new Rect(0, 0, 0, 0));
                return;
            }

            if (m_UsingTexture.ContainsKey(texture.name))
            {
                if (callBack != null)
                {
                    SaveTextureData textureData = m_UsingTexture[texture.name];
                    textureData.referenceCount++;
                    Texture2D tex2D = m_PageList[textureData.texIndex].texture;
                    callBack(tex2D, textureData.rect);
                }

                return;
            }

            GetTextureData data = DynamicAtlasMgr.S.AllocateGetTextureData();

            data.name     = texture.name;
            data.callback = callBack;
            m_GetTextureTaskList.Add(data);

            OnRenderTexture(data.name, (Texture2D)texture);
        }
예제 #5
0
 public void ReleaseGetTextureData(GetTextureData data)
 {
     m_GetTextureDataList.Add(data);
 }