真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

【小松教你手游開發(fā)】【系統(tǒng)模塊開發(fā)】圖文混排(在label中插入表情)-創(chuàng)新互聯(lián)

本身ngui是自帶圖文混排的,這個(gè)可以在ngui的Example里找到。但是為什么不能用網(wǎng)上已經(jīng)說得很清楚,比如雨松momo的http://www.xuanyusong.com/archives/2908

目前成都創(chuàng)新互聯(lián)已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、平房網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

最重要的一點(diǎn)就是我們肯定不會(huì)選擇一個(gè)完整的中文字庫,動(dòng)態(tài)字體無辦法使用ngui的圖文混排

所以還是需要自己寫一個(gè)圖文混排。

首先圖文混排的基本邏輯是:

1.定義固定字符串格式作為圖片信息。

2.找到文字中的圖片信息的字符串提取并換成空格

3.根據(jù)圖片信息生成uisprite,并放在適當(dāng)?shù)膒osition

4.輸出文字和圖片

圖文混排有幾個(gè)重點(diǎn)是必須解決的:

1.找到圖片應(yīng)該放的position

2.如果圖片在文字末尾判斷是否放得下是否會(huì)被遮擋,是的話要把圖片放到下一行的開頭

3.按照?qǐng)D片的高度判斷這一行的開頭需要多少個(gè)換行符

4.如果一排有多個(gè)圖片且尺寸不一,這一排的圖片需要統(tǒng)一高度,不然會(huì)出現(xiàn)下面的情況

(如果圖片格式統(tǒng)一的話3,4倒是可以用湊合的辦法省略,但是我們想做一個(gè)適用各種大小圖片,每行可能有幾張圖片,適合各種情況的圖文混排)

接下來就是實(shí)現(xiàn)。

我的思路是:

有一大段文字且里面有許多圖片信息的前提下

1.首先把所有文字輸入都某個(gè)函數(shù),識(shí)別出第一個(gè)圖片信息的字符串,把這個(gè)包含圖片信息的字符串以及前面的文字裁剪下來,和裁剪以后的文字形成兩部分。

2.把裁剪的前面部分(包含圖片信息)分析出圖片信息,各種計(jì)算,最后得到圖片的position,生成gameObject并擺放好。保存各種信息。圖片部分用空格留出位置,形成新的字符串,和裁剪的第二部分的文字組合成新文字。

3.輸入到1里的那個(gè)函數(shù)。遞歸。

4.最終一次過輸出所有文字。

代碼直接寫到UILabel.cs里,也可以寫一個(gè)UIEmotionLabel.cs繼承UILabel.cs。

接下來看代碼:(最后會(huì)貼出所有代碼)

///   
/// label中有表情在顯示前調(diào)用進(jìn)行轉(zhuǎn)換  
///   
public void ShowEmotionLabel()  
{  
    m_newEmotionText = "";  
    string originalText = MyLabel.text;  

    //遞歸找表情并生成文字  
    CutAndShowEmotionLabel(originalText);  

    //輸出文字  
    MyLabel.text = m_newEmotionText;  
    MyLabel.UpdateNGUIText();  

    //每一行的表情重新排序?qū)ζ? 
    SortAllSprite();  
}

這個(gè)是唯一外部調(diào)用接口,當(dāng)要顯示圖片的時(shí)候調(diào)用這個(gè)函數(shù)。

通過注釋就可以看懂里面的邏輯,最后的SortAllSprite()最后會(huì)再解釋一下。

所以先看CutAndShowEmotionLabel(string str)這個(gè)函數(shù)。

void CutAndShowEmotionLabel(string str)  
   {  
       EmotionData emoData = GetEmotionData(str);//解析str中的第一個(gè)表情字符串  

       if (emoData != null)  
       {  
           m_spriteList.Add(emoData);  

           //把str按第一個(gè)表情字符串的最后一個(gè)字母分成兩部分  
           string trimString = str.Substring(0, emoData.end_index);  
           string trimLeftString = str.Substring(emoData.end_index);  

           //生成表情和表情前面的文字部分  
           GenEmotionLabel(emoData, trimString);  
           m_newEmotionText = m_newEmotionText + trimLeftString;  

           //遞歸繼續(xù)找表情  
           CutAndShowEmotionLabel(m_newEmotionText);  
       }  
       else  
       {  
           //找不到表情返回,最后確定文字輸出  
           m_newEmotionText =str;  
           return;  
       }  

   }

第一行就是用自己的方法解析。

上面的邏輯就是按思路寫的

唯一有點(diǎn)不一樣的就是多了一個(gè)m_spriteList.Add(emoData);

因?yàn)樽詈笮枰阉袌D片按每行輸出時(shí)可能要對(duì)其高度,所以都要先保存下來。

這里面最重要的是GenEmotionLabel(emoData, trimString);這個(gè)函數(shù)

void GenEmotionLabel(EmotionData emoData, string tramString)  
{  
    //生成gameobject  
    GameObject go = CreateEmotionSprite(emoData);  
    float spriteWidth = NGUIMath.CalculateRelativeWidgetBounds(gameobject.transform, go.transform, true).size.x / go.transform.localScale.x;  
    float spriteHeight = NGUIMath.CalculateRelativeWidgetBounds(gameobject.transform, go.transform, true).size.y / go.transform.localScale.y;  

    //計(jì)算出圖片的位置,判斷文字的轉(zhuǎn)換和空格  
    Vector3 position = CalcuEmotionSpritePosition(tramString, emoData.start_index, spriteWidth, spriteHeight);  

    //擺放圖片位置  
    PlaceEmotionSprite(go, position);  

    m_spriteList[m_spriteList.Count - 1].go = go;  
}

CreateEmotionSprite()就是根據(jù)分析出來的圖片信息實(shí)例化一個(gè)GameObject,但是這時(shí)候position位置還是不能確定。

在算出圖片的寬高后。把這些數(shù)據(jù)都輸入到CalcuEmotionSpritePosition();這個(gè)函數(shù)里算出最后的position。

獲得position數(shù)據(jù)在PlaceEmotionSprite()函數(shù)正確的擺放
所以這里最關(guān)鍵的還是CalcuEmotionSpritePosition()。

Vector3 CalcuEmotionSpritePosition(string str, int startIndex, float spriteWidth, float spriteHeight)  
{  
    Vector3 position = GenBlankString(str, startIndex, spriteWidth, spriteHeight);  
    return position;  
}

這里看GenBlankString()函數(shù)。

Vector3 GenBlankString(string str, int startIndex, float spriteWidth, float spriteHeight)  
   {  
       int finalIndex = startIndex;  

       BetterList tempVerts = new BetterList();  
       BetterList tempIndices = new BetterList();  

       //1.把圖片信息換成空格  
       string emontionText = str.Substring(startIndex);  
       int blankNeedCount = CaculateBlankNeed(spriteWidth);  
       str = str.Replace(emontionText, GenBlank(blankNeedCount));  
       //把換好的文字放回label再計(jì)算sprite應(yīng)該放的坐標(biāo),  
       UpdateCharacterPosition(str,out tempVerts,out tempIndices);  

       //2.如果在label末尾且圖片放不下,判斷是否換行  
       bool needWrap = NeedWrap(tempVerts, tempIndices, startIndex, startIndex + blankNeedCount);  
       if (needWrap)  
       {  
           str = str.Insert(startIndex, "\n");  
           finalIndex +=1;  

           //重新計(jì)算當(dāng)前所有字符的位置  
           UpdateCharacterPosition(str, out tempVerts, out tempIndices);  
       }  

       //3.按圖片的高,生成回車(換行)  
       int returnCount = GenCarriageReturn(tempVerts, tempIndices, ref str, finalIndex, spriteHeight, needWrap);  
       finalIndex += returnCount;  

       //4.重新賦值要輸出的str  
       m_newEmotionText = str;  

       //重新計(jì)算當(dāng)前所有字符的位置  
       UpdateCharacterPosition(str, out tempVerts, out tempIndices);  

       //保存行數(shù),最后重新排放每行的圖片使用  
       m_spriteList[m_spriteList.Count - 1].line_index = CalcuLineIndex(tempVerts, tempIndices, startIndex) - lastScale;  

       //最終計(jì)算圖片該放的位置  
       Vector3 position = new Vector3();  
       if (needWrap)  
       {  
           position = new Vector3(tempVerts[0].x, tempVerts[GetIndexFormIndices(finalIndex, tempIndices)].y, tempVerts[0].z);  
       }  
       else  
       {  
           position = tempVerts[GetIndexFormIndices(finalIndex, tempIndices)];  
       }  

       return position;  
   }

先介紹一下NGUI提供的計(jì)算每個(gè)字符在字符串中位置的函數(shù)。

NGUIText.PrintCharacterPositions(str, tempVerts, tempIndices);

輸入str,輸出tempVerts,tempIndices。通過這兩個(gè)變量獲取每個(gè)字符的position信息

這里我封裝了個(gè)函數(shù)通過字符在字符串中的index來獲取在tempVerts中index_v,繼而通過tempVerts[index_v]獲取vecter3

int GetIndexFormIndices(int index, BetterList list)  
{  
    for (int i = 0; i < list.size; i++)  
        if (list[i] == index)  
            return i;  
    return 0;  
}

我把NGUIText.PrintCharacterPositions(str, tempVerts, tempIndices)的用法寫成一個(gè)接口。

void UpdateCharacterPosition(string str,out BetterList verts,out BetterList indices)  
{  
    //把換好的文字放回label再計(jì)算sprite應(yīng)該放的坐標(biāo),  
    //計(jì)算當(dāng)前所有字符的位置  
    MyLabel.text = str;  
    MyLabel.UpdateNGUIText();  
    BetterList tempVerts = new BetterList();  
    BetterList tempIndices = new BetterList();  
    NGUIText.PrintCharacterPositions(str, tempVerts, tempIndices);  

    verts = tempVerts;  
    indices = tempIndices;  
}

這個(gè)接口的意思就是把str放到label里,讓NGUI重新擺放一下文字,之后調(diào)用PrintCharacterPositions,返回這兩個(gè)變量,就更新了位置信息。這時(shí)候就可以取得每個(gè)字符的位置信息,也就是圖片將要擺放的位置。(在每次改變文字后都要重新調(diào)用才能確定位置準(zhǔn)確)

回到上面的GenBlankString().

1.首先根據(jù)圖片寬度計(jì)算需要多少個(gè)空格來預(yù)留出位置。調(diào)用UpdateCharacterPosition()更新,重新獲得位置信息(這部分我暫時(shí)是估算哈,比如5像素1空格)

2.判斷是否需要換行。調(diào)用UpdateCharacterPosition()更新,重新獲得位置信息(判斷圖片信息字符串(已換成空格)的第一個(gè)字符和最后一個(gè)字符是否在同一行,如果不同行證明要換行)
3.按圖片的高,生成換行符。調(diào)用UpdateCharacterPosition()更新,重新獲得位置信息
4.這時(shí)文字已經(jīng)確定不會(huì)再添加任何符號(hào),所以重新復(fù)制最終要輸出的文字m_newEmotionText = str;

步驟3需要特別講一下:

int lastScale = 1;  
   int lastIndex = 0;  
   int GenCarriageReturn(BetterList vectList, BetterList indexList, ref string str, int startIndex, float spriteHeight, bool isWrap)  
   {  
       float fontSize = MyLabel.fontSize * gameobject.transform.localScale.x;  

       int scale = Mathf.CeilToInt(spriteHeight / fontSize) - 1;  

       if (CheckIfSameLine(vectList, indexList, startIndex, lastIndex))  
       {  
           if (lastScale < scale)  
           {  
               scale = scale - lastScale;  
               lastScale = scale + lastScale;  
           }  
           else  
           {  
               scale = 0;  
           }  
       }  
       else  
       {  
           lastScale = scale;  
       }  
       lastIndex = startIndex;  

       string CarriageReturn = "";  
       for (int i = 0; i < scale; i++)  
       {  
           CarriageReturn = CarriageReturn + '\n';  
           lastIndex += 1;  
       }  

       //if(CheckIfIsLineFirstCharacter(vectList, indexList, startIndex))  
       //{  
       //    CarriageReturn = CarriageReturn + '\n';  
       //    scale += 1;  
       //}  

       if (!isWrap && scale > 0)  
       {  
           CarriageReturn = CarriageReturn + '\n';  
           scale += 1;  
           lastIndex += 1;  
           lastScale += 1;  
       }  

       str = str.Insert(FindLineFirstIndex(vectList, indexList, startIndex) - 1, CarriageReturn);  

       return scale;  
   }

可以看到在scale就是我需要多少個(gè)換行符。

接著下面的邏輯是如果這次判斷的startIndex(這個(gè)圖片的第一個(gè)字符)和上次lastIndex(上一個(gè)圖片的第一個(gè)字符)如果是同一行的話,需要判斷后面的圖片有沒有比前面的更大,如果更大需要判斷大多少,還需要多少個(gè)回車。

因?yàn)槿绻恍袃?nèi)多個(gè)圖片的大小不一,只取大的圖片的大小生成換行符。

再后面是判斷,有種情況是本身文字放到label剛好處于文字末尾(就是本身就需要一個(gè)換行符),所以如果是這種情況需要再插入一個(gè)換行符。

接著就把換行符插入到這一行的第一個(gè)字符前(還是通過位置信息去判斷這行的第一個(gè)字符)

這個(gè)就是判斷圖片位置的邏輯,然后就一遍遍的遞歸把所有圖片找出來放置好。

最后還需要把每一行的圖片檢索一下,同一行有多個(gè)圖片時(shí),所有圖片的y軸都跟最后一個(gè)對(duì)齊(因?yàn)樽詈笠粋€(gè)的y軸肯定是最低的,要跟最低的對(duì)齊)

void SortAllSprite()  
{  
    for (int i = m_spriteList.Count - 1; i > 0; i--)  
    {  
        if (m_spriteList[i].line_index == m_spriteList[i - 1].line_index)  
        {  
            m_spriteList[i - 1].pos.y = m_spriteList[i].pos.y;  
            m_spriteList[i - 1].go.transform.localPosition = m_spriteList[i - 1].pos;  
        } 
    }  
}

這樣就完成了圖文混排。

下面是所有代碼(掛在UILabel.cs上, UILabel的代碼不顯示)

string m_newEmotionText = "";  
List m_spriteList = new List();  

///   
/// label中有表情在顯示前調(diào)用進(jìn)行轉(zhuǎn)換  
///   
public void ShowEmotionLabel()  
{  
    m_newEmotionText = "";  
    string originalText = MyLabel.text;  

    //遞歸找表情并生成文字  
    CutAndShowEmotionLabel(originalText);  

    //輸出文字  
    MyLabel.text = m_newEmotionText;  
    MyLabel.UpdateNGUIText();  

    //每一行的表情重新排序?qū)ζ? 
    SortAllSprite();  
}  

#region 圖文混排輔助函數(shù)  
void CutAndShowEmotionLabel(string str)  
{  
    EmotionData emoData = GetEmotionData(str);//解析str中的第一個(gè)表情字符串  

    if (emoData != null)  
    {  
        m_spriteList.Add(emoData);  

        //把str按第一個(gè)表情字符串的最后一個(gè)字母分成兩部分  
        string trimString = str.Substring(0, emoData.end_index);  
        string trimLeftString = str.Substring(emoData.end_index);  

        //生成表情和表情前面的文字部分  
        GenEmotionLabel(emoData, trimString);  
        m_newEmotionText = m_newEmotionText + trimLeftString;  

        //遞歸繼續(xù)找表情  
        CutAndShowEmotionLabel(m_newEmotionText);  
    }  
    else  
    {  
        //找不到表情返回,最后確定文字輸出  
        m_newEmotionText =str;  
        return;  
    }  

}  

void GenEmotionLabel(EmotionData emoData, string tramString)  
{  
    //生成gameobject  
    GameObject go = CreateEmotionSprite(emoData);  
    float spriteWidth = NGUIMath.CalculateRelativeWidgetBounds(gameobject.transform, go.transform, true).size.x / go.transform.localScale.x;  
    float spriteHeight = NGUIMath.CalculateRelativeWidgetBounds(gameobject.transform, go.transform, true).size.y / go.transform.localScale.y;  

    //計(jì)算出圖片的位置,判斷文字的轉(zhuǎn)換和空格  
    Vector3 position = CalcuEmotionSpritePosition(tramString, emoData.start_index, spriteWidth, spriteHeight);  

    //擺放圖片位置  
    PlaceEmotionSprite(go, position);  

    m_spriteList[m_spriteList.Count - 1].go = go;  
}  

int lastScale = 1;  
int lastIndex = 0;  
int GenCarriageReturn(BetterList vectList, BetterList indexList, ref string str, int startIndex, float spriteHeight, bool isWrap)  
{  
    float fontSize = MyLabel.fontSize * gameobject.transform.localScale.x;  

    int scale = Mathf.CeilToInt(spriteHeight / fontSize) - 1;  

    if (CheckIfSameLine(vectList, indexList, startIndex, lastIndex))  
    {  
        if (lastScale < scale)  
        {  
            scale = scale - lastScale;  
            lastScale = scale + lastScale;  
        }  
        else  
        {  
            scale = 0;  
        }  
    }  
    else  
    {  
        lastScale = scale;  
    }  
    lastIndex = startIndex;  

    string CarriageReturn = "";  
    for (int i = 0; i < scale; i++)  
    {  
        CarriageReturn = CarriageReturn + '\n';  
        lastIndex += 1;  
    }  

    //if(CheckIfIsLineFirstCharacter(vectList, indexList, startIndex))  
    //{  
    //    CarriageReturn = CarriageReturn + '\n';  
    //    scale += 1;  
    //}  

    if (!isWrap && scale > 0)  
    {  
        CarriageReturn = CarriageReturn + '\n';  
        scale += 1;  
        lastIndex += 1;  
        lastScale += 1;  
    }  

    str = str.Insert(FindLineFirstIndex(vectList, indexList, startIndex) - 1, CarriageReturn);  

    return scale;  
}  

Vector3 CalcuEmotionSpritePosition(string str, int startIndex, float spriteWidth, float spriteHeight)  
{  
    Vector3 position = GenBlankString(str, startIndex, spriteWidth, spriteHeight);  
    return position;  
}  

Vector3 GenBlankString(string str, int startIndex, float spriteWidth, float spriteHeight)  
{  
    int finalIndex = startIndex;  

    BetterList tempVerts = new BetterList();  
    BetterList tempIndices = new BetterList();  

    //1.把圖片信息換成空格  
    string emontionText = str.Substring(startIndex);  
    int blankNeedCount = CaculateBlankNeed(spriteWidth);  
    str = str.Replace(emontionText, GenBlank(blankNeedCount));  
    //把換好的文字放回label再計(jì)算sprite應(yīng)該放的坐標(biāo),  
    UpdateCharacterPosition(str,out tempVerts,out tempIndices);  

    //2.如果在label末尾且圖片放不下,判斷是否換行  
    bool needWrap = NeedWrap(tempVerts, tempIndices, startIndex, startIndex + blankNeedCount);  
    if (needWrap)  
    {  
        str = str.Insert(startIndex, "\n");  
        finalIndex +=1;  

        //重新計(jì)算當(dāng)前所有字符的位置  
        UpdateCharacterPosition(str, out tempVerts, out tempIndices);  
    }  

    //3.按圖片的高,生成回車(換行)  
    int returnCount = GenCarriageReturn(tempVerts, tempIndices, ref str, finalIndex, spriteHeight, needWrap);  
    finalIndex += returnCount;  

    //4.重新賦值要輸出的str  
    m_newEmotionText = str;  

    //重新計(jì)算當(dāng)前所有字符的位置  
    UpdateCharacterPosition(str, out tempVerts, out tempIndices);  

    //保存行數(shù),最后重新排放每行的圖片使用  
    m_spriteList[m_spriteList.Count - 1].line_index = CalcuLineIndex(tempVerts, tempIndices, startIndex) - lastScale;  

    //最終計(jì)算圖片該放的位置  
    Vector3 position = new Vector3();  
    if (needWrap)  
    {  
        position = new Vector3(tempVerts[0].x, tempVerts[GetIndexFormIndices(finalIndex, tempIndices)].y, tempVerts[0].z);  
    }  
    else  
    {  
        position = tempVerts[GetIndexFormIndices(finalIndex, tempIndices)];  
    }  

    return position;  
}  

GameObject CreateEmotionSprite(EmotionData data)  
{  
    GameObject go = new GameObject("(clone)emotion_sprite");  
    go.transform.parent = gameobject.transform;  

    UISprite sprite = go.AddComponent();  
    sprite.atlas = CResourceManager.Instance.GetAtlas(data.atlas_name);  
    sprite.spriteName = data.sprite_name;  
    sprite.MakePixelPerfect();  
    sprite.pivot = UIWidget.Pivot.BottomLeft;  

    float scaleFactor = 1 / gameobject.transform.localScale.x;  
    go.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);//字體可能縮小了0.5,所以掛在字體下要放大2倍  

    go.transform.localPosition = new Vector3(5000, 5000, 0);//先把它放到看不見的地方  

    return go;  
}  

void PlaceEmotionSprite(GameObject go, Vector3 position)  
{  
    float fontSize = MyLabel.fontSize * gameobject.transform.localScale.x;  

    float div = fontSize * go.transform.localScale.x / 2;  

    Vector3 newPosition = new Vector3(position.x, position.y - div, position.z);  
    //Vector3 newPosition = position;  
    go.transform.localPosition = newPosition;  

    m_spriteList[m_spriteList.Count - 1].pos = newPosition;  
}  

EmotionData GetEmotionData(string text)  
{  
    EmotionData tempData = null;  
    int index = text.IndexOf("%p");  
    if (index != -1)  
    {  
        tempData = new EmotionData();  
        tempData.start_index = index;  

        int altasEndIndex = text.IndexOf("$", index);  
        tempData.atlas_name = text.Substring(index + 2, altasEndIndex - (index + 2));  

        int spriteEndIndex = text.IndexOf("$", altasEndIndex + 1);  
        tempData.sprite_name = text.Substring(altasEndIndex + 1, spriteEndIndex - (altasEndIndex + 1));  

        tempData.end_index = spriteEndIndex + 1;  
    }  
    return tempData;  
}  

int GetIndexFormIndices(int index, BetterList list)  
{  
    for (int i = 0; i < list.size; i++)  
        if (list[i] == index)  
            return i;  
    return 0;  
}  

int CaculateBlankNeed(float spriteWidth)  
{  
    int count = Mathf.CeilToInt(spriteWidth / (float)6);  
    return count;  
}  

string GenBlank(int count)  
{  
    string blank = "";  
    for (int i = 0; i < count; i++)  
    {  
        blank = blank + " ";  
    }  
    return blank;  
}  

bool NeedWrap(BetterList vecList, BetterList indicList, int startIndex, int endIndex)  
{  
    int startIndic = GetIndexFormIndices(startIndex, indicList);  
    int endIndic = GetIndexFormIndices(endIndex, indicList);  

    if (vecList[startIndic].y == vecList[endIndic].y)  
        return false;  
    else  
        return true;  
}  

bool CheckIfSameLine(BetterList vecList, BetterList indicList, int firstIndex, int SecondIndex)  
{  
    int firstIndic = GetIndexFormIndices(firstIndex, indicList);  
    int secondIndic = GetIndexFormIndices(SecondIndex, indicList);  

    if (vecList[firstIndic].y == vecList[secondIndic].y)  
        return true;  
    else  
        return false;  
}  

int FindLineFirstIndex(BetterList vecList, BetterList indicList, int index)  
{  
    int startIndic = GetIndexFormIndices(index, indicList);  
    if (startIndic > 1)  
    {  
        if (vecList[startIndic].y == vecList[startIndic - 1].y)  
            index = FindLineFirstIndex(vecList, indicList, index - 1);  
        else  
            return index;  
    }  
    else  
    {  
        return 1;  
    }  
    return index;  
}  

int CalcuLineIndex(BetterList vecList, BetterList indicList, int index)  
{  
    int startIndic = GetIndexFormIndices(index, indicList);  
    int count = 0;  
    float lastVecY = 0;  
    for (int i = 0; i < vecList.size; i++)  
    //for (int i =0;i< startIndic; i++)  
    {  
        if (lastVecY != vecList[i].y)  
        {  
            count++;  
            lastVecY = vecList[i].y;  
        }  
    }  
    return count;  
}  

bool CheckIfIsLineFirstCharacter(BetterList vecList, BetterList indicList, int index)  
{  
    int startIndic = GetIndexFormIndices(index, indicList);  
    if (startIndic > 1)  
    {  
        if (vecList[startIndic].y == vecList[startIndic - 1].y)  
            return false;  
        else  
            return true;  
    }  
    else  
    {  
        return false;  
    }  
}  

void SortAllSprite()  
{  
    for (int i = m_spriteList.Count - 1; i > 0; i--)  
    {  
        if (m_spriteList[i].line_index == m_spriteList[i - 1].line_index)  
        {  
            m_spriteList[i - 1].pos.y = m_spriteList[i].pos.y;  
            m_spriteList[i - 1].go.transform.localPosition = m_spriteList[i - 1].pos;  
        }  

    }  
}  

void UpdateCharacterPosition(string str,out BetterList verts,out BetterList indices)  
{  
    //把換好的文字放回label再計(jì)算sprite應(yīng)該放的坐標(biāo),  
    //計(jì)算當(dāng)前所有字符的位置  
    MyLabel.text = str;  
    MyLabel.UpdateNGUIText();  
    BetterList tempVerts = new BetterList();  
    BetterList tempIndices = new BetterList();  
    NGUIText.PrintCharacterPositions(str, tempVerts, tempIndices);  

    verts = tempVerts;  
    indices = tempIndices;  
}  
#endregion

補(bǔ)上EmotionData類


public class EmotionData  
{  
    public int start_index;  
    public int end_index;  
    public string atlas_name;  
    public string sprite_name;  
    public float sprite_width;  

    public int line_index;  
    public Vector3 pos;  
    public GameObject go;  
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。


標(biāo)題名稱:【小松教你手游開發(fā)】【系統(tǒng)模塊開發(fā)】圖文混排(在label中插入表情)-創(chuàng)新互聯(lián)
文章URL:http://www.weahome.cn/article/cscihj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部