public void EraseHUDVertex(HUDVertex v) { int nIndex = v.m_hudVertexIndex; if (nIndex >= 0 && nIndex < m_SpriteVertex.size) { if (m_SpriteVertex[nIndex] != null && v.ID == m_SpriteVertex[nIndex].ID) { mDirty = true; mHaveNullVertex = true; m_SpriteVertex[nIndex] = null; return; } } for (int i = m_SpriteVertex.size - 1; i >= 0; --i) { if (m_SpriteVertex[i] != null && m_SpriteVertex[i].ID == v.ID) { mDirty = true; mHaveNullVertex = true; m_SpriteVertex[i] = null; break; } } }
void RebuildCharUV(ref CharacterInfo tempCharInfo) { if (m_aSprite.size == 0) { return; } UIFont uiFont = GetHUDTitleFont(); int nStart = 0, nEnd = 0; for (int i = 0; i < m_nTitleNumb; ++i) { HUDTilteLine title = m_TitleLine[i]; if (string.IsNullOrEmpty(title.m_szValidText)) { continue; } uiFont.PrepareQueryText(title.m_szValidText); nEnd = title.m_nEnd; nStart = title.m_nStart; for (; nStart < nEnd; ++nStart) { HUDVertex v = m_aSprite[nStart]; if (0 == v.AtlasID) { uiFont.GetCharacterInfo(v.ch, ref tempCharInfo); v.RebuildCharUV(tempCharInfo); if (v.hudMesh != null) { v.hudMesh.VertexDirty(); } } } } }
void PushSliceTitle(int nSpriteID, int nWidth, int nHeight, float fx, float fy, float fBloodPos) { UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(nSpriteID); if (sp == null) { return; } int nAtlasID = sp.m_nAtlasID; int nStart = m_aSprite.size; for (int i = 0; i < 9; ++i) { HUDVertex node = HUDVertex.QueryVertex(); node.WorldPos = m_vPos; node.ScreenPos = m_vScreenPos; node.SpriteID = nSpriteID; node.AtlasID = nAtlasID; node.Scale = m_fScale; node.Offset.Set(fx, fy); node.Move.Set(0f, 0f); node.width = (short)nWidth; node.height = (short)nHeight; m_aSprite.Add(node); } SlicedFill(nSpriteID, nWidth, nHeight, nStart, fBloodPos); }
void UpdateGif(ref bool bMeshDirth, float deltaTime) { for (int i = 0; i < m_HyperlinkNode.size; ++i) { HUDVertex v = m_HyperlinkNode[i]; int nOldSpriteID = v.SpriteID; if (v.hudGif == null) { continue; } v.hudGif.Update(deltaTime); int nNewSpriteID = v.hudGif.GetSpriteID(); if (nOldSpriteID != nNewSpriteID) { bMeshDirth = true; if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } int nAtlasID = CAtlasMng.instance.GetAtlasIDBySpriteID(nNewSpriteID); v.hudMesh = m_MeshRender.QueryMesh(nAtlasID); v.hudMesh.PushHUDVertex(v); v.AtlasID = nAtlasID; v.SpriteID = nNewSpriteID; v.InitSprite(v.width, v.height); v.Scale = m_fScale; } } }
void InitTitleHUDMesh(HUDTitleInfo title) { if (!title.m_bInitHUDMesh && !title.m_bNeedHide) { title.m_bInitHUDMesh = true; for (int i = 0, nSize = title.m_aSprite.size; i < nSize; ++i) { HUDVertex v = title.m_aSprite[i]; if (v.hudMesh == null) { if (v.AtlasID != 0) { v.hudMesh = m_MeshRender.QueryMesh(v.AtlasID); } else { v.hudMesh = m_MeshRender.FontMesh(); } v.hudMesh.PushHUDVertex(v); } } //if (title.m_aSprite.size == 0) // return; //CharacterInfo tempCharInfo = new CharacterInfo(); //title.RebuildCharUV(ref tempCharInfo); } }
public void HideMeridianNumber() { if (m_nMeridianIndex > 0 && m_nMeridianIndex != m_nTitleNumb - 1) { return; } HUDTilteLine title = m_TitleLine[m_nMeridianIndex]; if (title.m_nType != HUDTilteType.HeadIcon) { return; } int nStart = title.m_nStart; int nEnd = title.m_nEnd; for (--nEnd; nEnd >= nStart && nEnd < m_aSprite.size; --nEnd) { HUDVertex v = m_aSprite[nEnd]; if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } v.hudMesh = null; m_aSprite.RemoveAt(nEnd); HUDVertex.ReleaseVertex(v); } m_nMeridianIndex = 0; --m_nTitleNumb; --m_nLines; }
protected void SetScale(float fScale) { for (int i = m_aSprite.size - 1; i >= 0; --i) { HUDVertex v = m_aSprite[i]; v.Scale = fScale; } }
protected void PrepareRebuildMesh() { for (int i = m_aSprite.size - 1; i >= 0; --i) { HUDVertex v = m_aSprite[i]; v.hudMesh = null; } }
// 功能:下对齐 // 参数:nStart, nEnd - 开始与结束的位置 // fHeight - 高度 protected void AlignDown(int nStart, int nEnd, float fOffsetX, float fHeight) { for (int i = nStart; i < nEnd; ++i) { HUDVertex v = m_aSprite[i]; v.Offset.x += fOffsetX; v.Offset.y += fHeight - v.height; } }
protected void Offset(int nStart, int nEnd, float fOffsetX, float fOffsetY) { for (int i = nStart; i < nEnd; ++i) { HUDVertex v = m_aSprite[i]; v.Offset.x += fOffsetX; v.Offset.y += fOffsetY; } }
public void PushHUDVertex(HUDVertex v) { mDirty = true; v.m_hudVertexIndex = m_SpriteVertex.size; m_SpriteVertex.Add(v); if (!m_bQueryTexture) { QueryTexture(); } }
public static void ReleaseVertex(HUDVertex p) { if (p != null) { p.hudGif = null; p.m_pNext = s_InvalidList; s_InvalidList = p; ++s_nInvalidCount; } }
protected void OnChangeScreenPos() { for (int i = m_aSprite.size - 1; i >= 0; --i) { HUDVertex v = m_aSprite[i]; v.ScreenPos = m_vScreenPos; v.Scale = m_fScale; v.WorldPos = m_vPos; if (v.hudMesh != null) { v.hudMesh.VertexDirty(); } } }
protected HUDVertex PushSprite(int nSpriteID, int nWidth, int nHeight, float fx, float fy) { HUDVertex node = HUDVertex.QueryVertex(); node.WorldPos = m_vPos; node.ScreenPos = m_vScreenPos; node.SpriteID = nSpriteID; node.Offset.Set(fx, fy); node.Move.Set(0f, 0f); node.InitSprite(nWidth, nHeight); node.Scale = m_fScale; m_aSprite.Add(node); return(node); }
public void ReleaseVertex() { for (int i = m_aSprite.size - 1; i >= 0; --i) { HUDVertex v = m_aSprite[i]; if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } v.hudMesh = null; HUDVertex.ReleaseVertex(v); m_aSprite[i] = null; } m_aSprite.Clear(); }
public void PushSprite(float y, int nSpriteID) { HUDVertex node = HUDVertex.QueryVertex(); node.WorldPos = m_vPos; node.ScreenPos = m_vScreenPos; node.Offset.Set(m_nWidth, y); node.SpriteID = nSpriteID; node.InitSprite(); m_aSprite.Add(node); m_nWidth += node.width + m_nSpriteGap; if (m_nHeight < node.height) { m_nHeight = node.height; } }
public static HUDVertex QueryVertex() { HUDVertex p = s_InvalidList; if (p != null) { s_InvalidList = p.m_pNext; --s_nInvalidCount; p.m_pNext = null; } if (p == null) { p = new HUDVertex(); p.m_nID = ++s_nVertexID; } return(p); }
public void EraseSpriteFromMesh() { if (!m_bInitHUDMesh) { return; } m_bInitHUDMesh = false; for (int i = m_aSprite.size - 1; i >= 0; --i) { HUDVertex v = m_aSprite[i]; if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } v.hudMesh = null; } }
public void InitSprite(int nWidth = 0, int nHeight = 0) { ch = '\0'; AtlasID = -1; UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(SpriteID); if (sp == null) { return; } AtlasID = sp.m_nAtlasID; width = nWidth <= 0 ? (short)(sp.outer.width + 0.5f) : (short)nWidth; height = nHeight <= 0 ? (short)(sp.outer.height + 0.5f) : (short)nHeight; Scale = 1.0f; Rect mOuterUV = sp.outer; UITexAtlas texAtlas = CAtlasMng.instance.GetAtlasByID(sp.m_nAtlasID); if (texAtlas != null && texAtlas.coordinates == UITexAtlas.Coordinates.Pixels) { mOuterUV = HUDVertex.ConvertToTexCoords(mOuterUV, texAtlas.texWidth, texAtlas.texHeight); } float fL = 0.0f; float fT = 0.0f; float fR = width; float fB = height; vecRU.Set(fR, fT); // 右上角 vecRD.Set(fR, fB); // 右下角 vecLD.Set(fL, fB); // 左下角 vecLU.Set(fL, fT); // 左上角 float uvR = mOuterUV.xMax; float uvL = mOuterUV.xMin; float uvB = mOuterUV.yMin; float uvT = mOuterUV.yMax; uvRU.Set(uvR, uvB); uvRD.Set(uvR, uvT); uvLD.Set(uvL, uvT); uvLU.Set(uvL, uvB); clrLD = clrLU = clrRD = clrRU = Color.white; }
protected HUDVertex PushShadow(ref CharacterInfo tempCharInfo, char ch, float fx, float fy, Color32 clrShadow, float fMoveX, float fMoveY) { HUDVertex node = HUDVertex.QueryVertex(); node.WorldPos = m_vPos; node.ScreenPos = m_vScreenPos; node.ch = ch; node.Offset.Set(fx, fy); node.Move.Set(fMoveX, fMoveY); node.clrLU = clrShadow; node.clrLD = clrShadow; node.clrRD = clrShadow; node.clrRU = clrShadow; node.InitChar(tempCharInfo); node.Scale = m_fScale; m_aSprite.Add(node); return(node); }
protected HUDVertex PushChar(ref CharacterInfo tempCharInfo, char ch, float fx, float fy, Color32 clrLeftUp, Color32 clrLeftDown, Color32 clrRightUp, Color32 clrRightDown) { HUDVertex node = HUDVertex.QueryVertex(); node.WorldPos = m_vPos; node.ScreenPos = m_vScreenPos; node.ch = ch; node.Offset.Set(fx, fy); node.Move.Set(0f, 0f); node.clrLU = clrLeftUp; node.clrLD = clrLeftDown; node.clrRD = clrRightDown; node.clrRU = clrRightUp; node.InitChar(tempCharInfo); node.Scale = m_fScale; m_aSprite.Add(node); return(node); }
void RebuildCharUV(UIFont uiFont) { CharacterInfo tempCharInfo = new CharacterInfo(); uiFont.PrepareQueryText(m_szTalk); for (int i = m_aSprite.size - 1; i >= 0; --i) { HUDVertex v = m_aSprite[i]; if (0 == v.AtlasID) { uiFont.GetCharacterInfo(v.ch, ref tempCharInfo); v.RebuildCharUV(tempCharInfo); if (v.hudMesh != null) { v.hudMesh.VertexDirty(); } } } m_MeshRender.OnChangeFont(uiFont); }
void ShowTalk(string szTalk, int nColorIndex = 0) { if (nColorIndex < 0) { nColorIndex = 0; } else if (nColorIndex >= HudSetting.Instance.TalkTitle.Length) { nColorIndex = HudSetting.Instance.TalkTitle.Length - 1; } HudTitleAttribute titleAttrib = HudSetting.Instance.TalkTitle[nColorIndex]; int nTalkWidth = HudSetting.Instance.m_nTalkWidth; int nSpriteID = HudSetting.Instance.m_nTalkBk; UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(nSpriteID); int nAtlasID = sp != null ? sp.m_nAtlasID : 0; // 先分析文本 UIFont mFont = GetHUDTitleFont(); HUDTextParse hudParse = HUDTextParse.Instance; hudParse.ParseText(szTalk); mFont.PrepareQueryText(hudParse.m_szText); int nFontH = mFont.GetFontHeight(); m_szTalk = hudParse.m_szText; m_HyperlinkNode.Clear(); // 先搞背景 for (int i = 0; i < 9; ++i) { HUDVertex node = HUDVertex.QueryVertex(); node.WorldPos = m_vPos; node.ScreenPos = m_vScreenPos; node.SpriteID = nSpriteID; node.AtlasID = nAtlasID; node.Scale = 1f; node.Offset.Set(0f, 0f); node.Move.Set(0f, 0f); node.width = (short)nTalkWidth; node.height = (short)100; m_aSprite.Add(node); } int nCharGap = titleAttrib.CharGap; int nLineGap = titleAttrib.LineGap; HudTitleAttribute.Effect nStyle = titleAttrib.Style; float fShadowX = titleAttrib.OffsetX; float fShadowY = titleAttrib.OffsetY; Color32 clrLeftUp = titleAttrib.clrLeftUp; Color32 clrLeftDown = titleAttrib.clrLeftDown; Color32 clrRightUp = titleAttrib.clrRightUp; Color32 clrRightDown = titleAttrib.clrRightDown; Color32 clrShadow = titleAttrib.clrShadow; Color32 clrCustom; // 计算文本的行数 CharacterInfo tempCharInfo = new CharacterInfo(); HUDCharInfo[] Sprites = hudParse.m_Sprites; int nSpriteCount = hudParse.m_SpriteCount; int nX = 0; int nY = 0; char ch; int nCurLineHeight = nFontH; int nLines = 0; int nTalkHeight = 0; short[] LineHeight = hudParse.LineHeight; int nWidthMax = 0; int nSpaceWidth = 0; for (int i = 0; i < nSpriteCount; ++i) { if (Sprites[i].bChar) { ch = Sprites[i].ch; if (ch == ' ') { if (nSpaceWidth == 0) { mFont.GetCharacterInfo('o', ref tempCharInfo); nSpaceWidth = HUDVertex.GetCharWidth(tempCharInfo); } Sprites[i].SpriteWidth = (short)nSpaceWidth; Sprites[i].SpriteHeight = (short)nFontH; } else { mFont.GetCharacterInfo(ch, ref tempCharInfo); Sprites[i].SpriteWidth = (short)HUDVertex.GetCharWidth(tempCharInfo); Sprites[i].SpriteHeight = (short)tempCharInfo.glyphHeight; } } else { if (Sprites[i].CharType == UIFontUnitType.UnitType_Icon) { sp = CAtlasMng.instance.GetSafeSpriteByID(Sprites[i].SpriteID); if (sp != null) { Sprites[i].SpriteWidth = (short)(sp.outer.width + 0.5f); Sprites[i].SpriteHeight = (short)(sp.outer.height + 0.5f); } } else if (Sprites[i].CharType == UIFontUnitType.UnitType_Gif) { int nGifID = Sprites[i].SpriteID; Sprites[i].SpriteWidth = (short)UISpriteGifManager.Instance.GetSpriteGifWidth(nGifID); Sprites[i].SpriteHeight = (short)UISpriteGifManager.Instance.GetSpriteGifHeight(nGifID); } } if (nX + Sprites[i].SpriteWidth > nTalkWidth || Sprites[i].CharType == UIFontUnitType.UnitType_Enter) { LineHeight[nLines] = (short)nCurLineHeight; nTalkHeight += nCurLineHeight + nLineGap; nX = 0; nY = nTalkHeight; // 按下对齐 nCurLineHeight = nFontH; ++nLines; } Sprites[i].nX = nX; Sprites[i].nY = nY; Sprites[i].nLine = nLines; nX += Sprites[i].SpriteWidth + nCharGap; if (nCurLineHeight < Sprites[i].SpriteHeight) { nCurLineHeight = Sprites[i].SpriteHeight; } if (nX > nWidthMax) { nWidthMax = nX; } } LineHeight[nLines] = (short)nCurLineHeight; nTalkHeight += nCurLineHeight; nTalkWidth = nWidthMax; nY = nTalkHeight; // 需要倒过来 for (int i = 0; i < nSpriteCount; ++i) { Sprites[i].nY = nY - Sprites[i].nY - LineHeight[Sprites[i].nLine]; } // -------- 更新 for (int i = 0; i < nSpriteCount; ++i) { nX = Sprites[i].nX; nY = Sprites[i].nY; if (Sprites[i].bChar) { ch = Sprites[i].ch; mFont.GetCharacterInfo(ch, ref tempCharInfo); if (nStyle != HudTitleAttribute.Effect.None) { PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, fShadowX, fShadowY); if (nStyle == HudTitleAttribute.Effect.Outline) { PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, fShadowX, -fShadowY); PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, -fShadowX, fShadowY); PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, -fShadowX, -fShadowY); } } if (Sprites[i].bCustomColor) { clrCustom = Sprites[i].CustomColor; HUDVertex node = PushChar(ref tempCharInfo, ch, nX, nY, clrCustom, clrCustom, clrCustom, clrCustom); } else { HUDVertex node = PushChar(ref tempCharInfo, ch, nX, nY, clrLeftUp, clrLeftDown, clrRightUp, clrRightDown); } } else { // 图片 if (Sprites[i].CharType == UIFontUnitType.UnitType_Icon) { HUDVertex node = PushSprite(Sprites[i].SpriteID, Sprites[i].SpriteWidth, Sprites[i].SpriteHeight, nX, nY); } else if (Sprites[i].CharType == UIFontUnitType.UnitType_Gif) { m_bHaveHyperlink = true; HUDGif gif = new HUDGif(); gif.InitGif(Sprites[i].SpriteID); HUDVertex node = PushSprite(gif.GetSpriteID(), Sprites[i].SpriteWidth, Sprites[i].SpriteHeight, nX, nY); node.hudGif = gif; m_HyperlinkNode.Add(node); } } } int nTalkBkBorderWidth = HudSetting.Instance.TalkBorderWidth; int nTalkBkBorderHeight = HudSetting.Instance.TalkBorderHeight; // 填充背景气泡 int nTalkBkWidth = nTalkWidth + nTalkBkBorderWidth * 2; int nTalkBkHeight = nTalkHeight + nTalkBkBorderHeight * 2; for (int i = 0; i < 9; ++i) { m_aSprite[i].width = (short)nTalkBkWidth; m_aSprite[i].height = (short)nTalkBkHeight; } SlicedFill(nSpriteID, nTalkBkWidth, nTalkBkHeight, 0, 1.0f); Offset(0, 9, -nTalkBkBorderWidth - nTalkWidth / 2, -nTalkBkBorderHeight + HudSetting.Instance.m_nTalkBkOffsetY); // Y越小,越在屏幕下面 Offset(9, m_aSprite.size, -nTalkWidth / 2, 0.0f); for (int i = 0; i < m_aSprite.size; ++i) { HUDVertex v = m_aSprite[i]; if (v.hudMesh == null) { if (v.AtlasID != 0) { v.hudMesh = m_MeshRender.QueryMesh(v.AtlasID); } else { v.hudMesh = m_MeshRender.FontMesh(); } v.hudMesh.PushHUDVertex(v); } } }
protected void SlicedFill(int nSpriteID, int nWidth, int nHeight, int nStart, float fBloodPos) { UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(nSpriteID); if (sp == null) { return; } if (fBloodPos < 0.0) { fBloodPos = 0.0f; } if (fBloodPos > 1.0f) { fBloodPos = 1.0f; } int nBloodWidth = (int)(nWidth * fBloodPos + 0.5f); int nAtlasID = sp.m_nAtlasID; Rect mOuterUV = sp.outer; Rect mInnerUV = sp.inner; int nOuterW = (int)(mOuterUV.width + 0.5f); int nOuterH = (int)(mOuterUV.height + 0.5f); //int nInnerW = (int)(mInnerUV.width + 0.5f); //int nInnerH = (int)(mInnerUV.height + 0.5f); int nW1 = (int)(mInnerUV.xMin - mOuterUV.xMin + 0.5f); int nH1 = (int)(mInnerUV.yMin - mOuterUV.yMin + 0.5f); int nW2 = (int)(mOuterUV.xMax - mInnerUV.xMax + 0.5f); int nH2 = (int)(mOuterUV.yMax - mInnerUV.yMax + 0.5f); UITexAtlas texAtlas = CAtlasMng.instance.GetAtlasByID(sp.m_nAtlasID); if (texAtlas != null && texAtlas.coordinates == UITexAtlas.Coordinates.Pixels) { mOuterUV = HUDVertex.ConvertToTexCoords(mOuterUV, texAtlas.texWidth, texAtlas.texHeight); mInnerUV = HUDVertex.ConvertToTexCoords(mInnerUV, texAtlas.texWidth, texAtlas.texHeight); } if (nOuterW > 0 && nW1 + nW2 > nBloodWidth) { nW1 = nBloodWidth * nW1 / nOuterW; nW2 = nBloodWidth - nW1; } if (nOuterH > 0 && nH1 + nH2 > nHeight) { nH1 = nHeight * nH1 / nOuterH; nH2 = nHeight - nH1; } //if (nOuterW > 0) //{ // nW1 = nW1 * nBloodWidth / nOuterW; // nW2 = nW2 * nBloodWidth / nOuterW; //} //if (nOuterH > 0) //{ // nH1 = nH1 * nHeight / nOuterH; // nH2 = nH2 * nHeight / nOuterH; //} int nMW = nBloodWidth - nW1 - nW2; int nMH = nHeight - nH1 - nH2; HUDVertex v0 = m_aSprite[nStart]; HUDVertex v1 = m_aSprite[nStart + 1]; HUDVertex v2 = m_aSprite[nStart + 2]; HUDVertex v3 = m_aSprite[nStart + 3]; HUDVertex v4 = m_aSprite[nStart + 4]; HUDVertex v5 = m_aSprite[nStart + 5]; HUDVertex v6 = m_aSprite[nStart + 6]; HUDVertex v7 = m_aSprite[nStart + 7]; HUDVertex v8 = m_aSprite[nStart + 8]; // (mOuterUV.xMin, mOuterUV.yMin) // // (mInnerUV.xMin, mInnerUV.yMin) // (mInnerUV.yMin, mInnerUV.yMax) // // (mOuterUV.xMax, mOuterUV.yMax) // a6 a7 a8 a0 a1 a2 // a3 a4 a5 ==> a3 a4 a5 // a0 a1 a2 a6 a7 a8 float fIn_xMin = mInnerUV.xMin; float fIn_xMax = mInnerUV.xMax; float fIn_yMin = mInnerUV.yMin; float fIn_yMax = mInnerUV.yMax; float fOu_xMin = mOuterUV.xMin; float fOu_xMax = mOuterUV.xMax; float fOu_yMin = mOuterUV.yMin; float fOu_yMax = mOuterUV.yMax; float fX2 = nW1 + nMW; float fY2 = nH2 + nMH; v0.SlicedFill(nW1, nH2, 0f, 0f, fOu_xMin, fOu_yMin, fIn_xMin, fIn_yMin); v1.SlicedFill(nMW, nH2, nW1, 0f, fIn_xMin, fOu_yMin, fIn_xMax, fIn_yMin); v2.SlicedFill(nW2, nH2, fX2, 0f, fIn_xMax, fOu_yMin, fOu_xMax, fIn_yMin); v3.SlicedFill(nW1, nMH, 0f, nH2, fOu_xMin, fIn_yMin, fIn_xMin, fIn_yMax); v4.SlicedFill(nMW, nMH, nW1, nH2, fIn_xMin, fIn_yMin, fIn_xMax, fIn_yMax); v5.SlicedFill(nW2, nMH, fX2, nH2, fIn_xMax, fIn_yMin, fOu_xMax, fIn_yMax); v6.SlicedFill(nW1, nH1, 0f, fY2, fOu_xMin, fIn_yMax, fIn_xMin, fOu_yMax); v7.SlicedFill(nMW, nH1, nW1, fY2, fIn_xMin, fIn_yMax, fIn_xMax, fOu_yMax); v8.SlicedFill(nW2, nH1, fX2, fY2, fIn_xMax, fIn_yMax, fOu_xMax, fOu_yMax); v0.Scale = m_fScale; v1.Scale = m_fScale; v2.Scale = m_fScale; v3.Scale = m_fScale; v4.Scale = m_fScale; v5.Scale = m_fScale; v6.Scale = m_fScale; v7.Scale = m_fScale; v8.Scale = m_fScale; }
void FillVertex() { PrepareWrite(m_SpriteVertex.size * 4); Vector2 vOffset = Vector2.zero; float fScaleX = 1.0f, fScaleY = 1.0f; float fCameraScaleX = s_fCameraScaleX; float fCameraScaleY = s_fCameraScaleY; //if(m_bScaleByDist) //{ // fCameraScaleX = s_fScaleXByDist; // fCameraScaleY = s_fScaleYByDist; //} for (int i = 0, nSize = m_SpriteVertex.size; i < nSize; ++i) { HUDVertex v = m_SpriteVertex[i]; v.m_hudVertexIndex = i; mVerts.Add(v.WorldPos); mVerts.Add(v.WorldPos); mVerts.Add(v.WorldPos); mVerts.Add(v.WorldPos); //fScaleX = fCameraScaleX * v.Scale; //fScaleY = fCameraScaleY * v.Scale; fScaleX = fCameraScaleX * v.Scale; fScaleY = fCameraScaleY * v.Scale; vOffset = v.vecRU; vOffset += v.Offset; vOffset.x *= fScaleX; vOffset.y *= fScaleY; //vOffset += v.ScreenPos + v.Move; vOffset += v.Move; mOffset.Add(vOffset); vOffset = v.vecRD; vOffset += v.Offset; vOffset.x *= fScaleX; vOffset.y *= fScaleY; //vOffset += v.ScreenPos + v.Move; vOffset += v.Move; mOffset.Add(vOffset); vOffset = v.vecLD; vOffset += v.Offset; vOffset.x *= fScaleX; vOffset.y *= fScaleY; //vOffset += v.ScreenPos + v.Move; vOffset += v.Move; mOffset.Add(vOffset); vOffset = v.vecLU; vOffset += v.Offset; vOffset.x *= fScaleX; vOffset.y *= fScaleY; //vOffset += v.ScreenPos + v.Move; vOffset += v.Move; mOffset.Add(vOffset); mUvs.Add(v.uvRU); mUvs.Add(v.uvRD); mUvs.Add(v.uvLD); mUvs.Add(v.uvLU); mCols.Add(v.clrRD); mCols.Add(v.clrRU); mCols.Add(v.clrLU); mCols.Add(v.clrLD); } }
void UpdateMeridianNumber(int nMeridianNumb) { // 必须是在最后 if (0 == m_nMeridianIndex || m_nMeridianIndex != m_nTitleNumb - 1) { return; } // 先释放旧的吧 HUDTilteLine title = m_TitleLine[m_nMeridianIndex]; if (title.m_nType != HUDTilteType.HeadIcon) { return; } if (nMeridianNumb < 0) { nMeridianNumb = 0; } m_nMeridianNumb = nMeridianNumb; HudTitleAttribute titleAttrib = HudSetting.Instance.TitleSets[(int)HUDTilteType.HeadIcon].GetTitle(0); int nCharGap = titleAttrib.CharGap; int nPow = 1; while (nPow * 10 <= nMeridianNumb) { nPow *= 10; } int nWidth = 0; int nHeight = 0; int nMaxWidth = 0; int nMaxHeight = 0; int[] PicID = HudSetting.Instance.MeridianPic; int nSpriteID = 0; int nValue = nMeridianNumb; int nStart = title.m_nStart; int nEnd = title.m_nEnd; int nX = 0; while (nPow > 0) { int nIndex = nValue / nPow; nValue %= nPow; nPow /= 10; nSpriteID = PicID[nIndex]; UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(nSpriteID); nWidth = (int)sp.outer.width; nHeight = (int)sp.outer.height; nMaxWidth += nWidth + nCharGap; if (nMaxHeight < nHeight) { nMaxHeight = nHeight; } HUDVertex v = null; if (nStart < m_aSprite.size) { v = m_aSprite[nStart]; if (v.AtlasID != sp.m_nAtlasID) { if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } v.hudMesh = null; v.AtlasID = sp.m_nAtlasID; } v.SpriteID = nSpriteID; v.Offset.Set(nX, titleAttrib.SpriteOffsetY); v.InitSprite(nWidth, nHeight); } else { v = PushSprite(nSpriteID, nWidth, nHeight, nX, titleAttrib.SpriteOffsetY); } v.Scale = m_fScale; if (v.hudMesh == null) { if (m_bInitHUDMesh) { v.hudMesh = m_pBatcher.m_MeshRender.QueryMesh(sp.m_nAtlasID); v.hudMesh.PushHUDVertex(v); } } else { v.hudMesh.VertexDirty(); } nX = nMaxWidth; ++nStart; } title.m_nEnd = nStart; // 删除多余的 for (--nEnd; nEnd >= nStart; --nEnd) { HUDVertex v = m_aSprite[nEnd]; if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } v.hudMesh = null; m_aSprite.RemoveAt(nEnd); HUDVertex.ReleaseVertex(v); } nMaxWidth -= nCharGap; title.m_fWidth = nMaxWidth; title.m_nHeight = nMaxHeight; nMaxHeight += titleAttrib.SpriteReduceHeight; m_fCurLineWidth = nMaxWidth; m_fCurLineHeight = nMaxHeight; }
// 必须先有居中的 public void PushTitle(string szText, HUDTilteType titleType, int nColorIndex) { if (m_nTitleNumb >= m_TitleLine.Length) { return; } UIFont mFont = GetHUDTitleFont(); CharacterInfo tempCharInfo = new CharacterInfo(); HudTitleAttribute titleAttrib = HudSetting.Instance.TitleSets[(int)titleType].GetTitle(nColorIndex); int nLineGap = titleAttrib.LineGap; int nCharGap = titleAttrib.CharGap; HUDTextParse hudParse = HUDTextParse.Instance; hudParse.ParseText(szText); mFont.PrepareQueryText(hudParse.m_szText); HudTitleAttribute.Effect nStyle = titleAttrib.Style; int nSpriteCount = hudParse.m_SpriteCount; HUDCharInfo[] Sprites = hudParse.m_Sprites; char ch; float fShadowX = titleAttrib.OffsetX; float fShadowY = titleAttrib.OffsetY; float fx = 0.0f; Color32 clrLeftUp = titleAttrib.clrLeftUp; Color32 clrLeftDown = titleAttrib.clrLeftDown; Color32 clrRightUp = titleAttrib.clrRightUp; Color32 clrRightDown = titleAttrib.clrRightDown; Color32 clrShadow = titleAttrib.clrShadow; Color32 clrCustom; int nStart = m_aSprite.size; int nHeight = mFont.GetFontHeight(); int nFontH = titleAttrib.Height; int nFontOffsetY = titleAttrib.FontOffsetY; int nY = 0; for (int i = 0; i < nSpriteCount; ++i) { if (Sprites[i].bChar) { ch = Sprites[i].ch; mFont.GetCharacterInfo(ch, ref tempCharInfo); nY = (tempCharInfo.glyphHeight - nFontH) / 2 + nFontOffsetY; if (nStyle != HudTitleAttribute.Effect.None) { PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, fShadowX, fShadowY); if (nStyle == HudTitleAttribute.Effect.Outline) { PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, fShadowX, -fShadowY); PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, -fShadowX, fShadowY); PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, -fShadowX, -fShadowY); } } if (Sprites[i].bCustomColor) { clrCustom = Sprites[i].CustomColor; HUDVertex node = PushChar(ref tempCharInfo, ch, fx, nY, clrCustom, clrCustom, clrCustom, clrCustom); fx += node.width + nCharGap; } else { HUDVertex node = PushChar(ref tempCharInfo, ch, fx, nY, clrLeftUp, clrLeftDown, clrRightUp, clrRightDown); fx += node.width + nCharGap; } } else { // 图片 if (Sprites[i].CharType == UIFontUnitType.UnitType_Icon) { HUDVertex node = PushSprite(Sprites[i].SpriteID, Sprites[i].SpriteWidth, Sprites[i].SpriteHeight, fx, titleAttrib.SpriteOffsetY); fx += node.width + nCharGap; if (nHeight < node.height - titleAttrib.SpriteReduceHeight) { nHeight = node.height - titleAttrib.SpriteReduceHeight; } } } } if (m_TitleLine[m_nTitleNumb] == null) { m_TitleLine[m_nTitleNumb] = new HUDTilteLine(); } m_TitleLine[m_nTitleNumb].m_nType = titleType; m_TitleLine[m_nTitleNumb].m_fWidth = fx - nCharGap; m_TitleLine[m_nTitleNumb].m_nHeight = nHeight; m_TitleLine[m_nTitleNumb].m_nStart = nStart; m_TitleLine[m_nTitleNumb].m_nEnd = m_aSprite.size; m_TitleLine[m_nTitleNumb].m_szText = szText; m_TitleLine[m_nTitleNumb].m_szValidText = hudParse.m_szText; m_TitleLine[m_nTitleNumb].m_nColorIndex = nColorIndex; m_TitleLine[m_nTitleNumb].m_nLine = m_nLines; m_TitleLine[m_nTitleNumb].m_nSpriteID = 0; if (titleAttrib.AlignType == HUDAlignType.align_center) { m_fCurLineWidth = fx - nCharGap; } if (nHeight < titleAttrib.LockMaxHeight && titleAttrib.LockMaxHeight > 0) { nHeight = titleAttrib.LockMaxHeight; } if (m_fCurLineHeight < nHeight) { m_fCurLineHeight = nHeight; } ++m_nTitleNumb; }
// 功能:执行数字的动画效果 void PlayAnimation(HUDNumberEntry pNode, bool bFirst) { int nIndex = (int)pNode.m_nType; float currentDuration = (Time.time - pNode.m_fStartTime); if (m_bPuase) { currentDuration = m_currentDuration; } HudAnimAttibute attrib = m_aTtribute[nIndex]; bool bDirty = false; float fAlpha = attrib.AlphaCurve.Evaluate(currentDuration); //淡出效果; float fScale = attrib.ScaleCurve.Evaluate(currentDuration); //变大效果; float fPos = attrib.MoveCurve.Evaluate(currentDuration); //Y轴移动效果; float fOldAlpha = pNode.m_fAlpha; float fOldScale = pNode.m_fAniScale; float fOldMoveX = pNode.m_vMove.x; float fOldMoveY = pNode.m_vMove.y; pNode.m_fAlpha = fAlpha; pNode.m_fAniScale = fScale; if (attrib.ScreenAlign) { pNode.m_vMove.x = 0.0f; pNode.m_vMove.y = fPos * m_fScreenScaleY; } else { pNode.m_vMove.x = attrib.OffsetX * m_fScreenScaleX; pNode.m_vMove.y = (attrib.OffsetY + fPos) * m_fScreenScaleY; } pNode.m_bStop = currentDuration > m_fDurationTime; if (m_bPuase) { pNode.m_bStop = false; } int nAlpha = (int)(fAlpha * 255.0f + 0.5f); if (nAlpha < 0) { nAlpha = 0; } if (nAlpha > 255) { nAlpha = 255; } byte alpha = (byte)nAlpha; if (!bFirst) { bDirty = pNode.UpdateScreenPos(ref attrib); } else { bDirty = true; } if (!bDirty) { if (Mathf.Abs(fOldAlpha - pNode.m_fAlpha) > 0.0001f) { bDirty = true; } if (!bDirty && Mathf.Abs(fOldScale - pNode.m_fScale) > 0.0001f) { bDirty = true; } if (!bDirty && Mathf.Abs(fOldMoveX - pNode.m_vMove.x) > 0.0001f) { bDirty = true; } if (!bDirty && Mathf.Abs(fOldMoveY - pNode.m_vMove.y) > 0.0001f) { bDirty = true; } } if (!bDirty) { return; } fScale *= pNode.m_fScale; // 更新顶点数据 Vector2 vScreenPos = pNode.m_vScreenPos; Vector2 vMove = pNode.m_vMove; for (int i = pNode.m_aSprite.size - 1; i >= 0; --i) { HUDVertex v = pNode.m_aSprite[i]; v.Move = vMove; v.WorldPos = pNode.m_vPos; v.ScreenPos = vScreenPos; v.Scale = fScale; v.clrLU.a = alpha; v.clrLD.a = alpha; v.clrRU.a = alpha; v.clrRD.a = alpha; v.hudMesh.VertexDirty(); } }