// 功能:添加一个显示的数字 public void AddHudNumber(Transform tf, HUDNumberRenderType nType, int nNumber, bool bShowHead, bool bShowAdd, bool bShowSub) { if (m_bOpenUI || m_bStartDark || m_bStartMovie) { return; } Vector3 vPos = tf.position; int nIndex = (int)nType; //if (nIndex < 0 || nIndex > (int)HUDNumberRenderType.HUD_SHOW_NUMBER) // return; Camera caMain = HUDMesh.GetHUDMainCamera(); if (caMain == null) { return; } if (!m_bInit) { m_bInit = true; InitHUD(); } if (!m_bAddUpdateLogic) { m_bMeshDirty = true; UpdateManager.AddLateUpdate(null, 0, UpdateLogic); } HudAnimAttibute attrib = m_aTtribute[nIndex]; HUDNumberEntry pNode = QueryHudNumber(nType); pNode.m_nType = nType; pNode.m_pNext = m_ValidList; m_ValidList = pNode; if (nNumber < 0) { bShowSub = true; nNumber = -nNumber; } pNode.reset(); // 初始化 pNode.m_nSpriteGap = attrib.SpriteGap; pNode.m_fStartTime = Time.time; pNode.m_tf = tf; pNode.m_vPos = vPos; if (caMain != null) { // 如果按屏幕对齐 if (attrib.ScreenAlign) { Vector3 v1 = caMain.WorldToScreenPoint(vPos); v1.x = attrib.OffsetX; v1.y = attrib.OffsetY; float fScaleX = (float)Screen.width / 1280.0f; float fScaleY = (float)Screen.height / 1280.0f; if (attrib.ScreenAlignType == HUDAlignType.align_left) { v1.x = attrib.OffsetX; v1.y = attrib.OffsetY; } else if (attrib.ScreenAlignType == HUDAlignType.align_right) { v1.x = 1280.0f - attrib.OffsetX; v1.y = attrib.OffsetY; } else { v1.x = Screen.width / 2.0f + attrib.OffsetX; v1.y = attrib.OffsetY; } v1.x *= fScaleX; v1.y *= fScaleY; pNode.m_vScreenPos = v1; vPos = caMain.ScreenToWorldPoint(v1); pNode.m_vPos = vPos; Vector3 vCameraPos = caMain.transform.position; pNode.CaleCameraScale(vCameraPos); } else { pNode.m_vScreenPos = caMain.WorldToScreenPoint(vPos); Vector3 vCameraPos = caMain.transform.position; pNode.CaleCameraScale(vCameraPos); } } float y = 0.0f; HUDSprtieSetting pSetting = m_Settings[nIndex]; if (bShowHead && pSetting.m_nHeadID != 0) { pNode.PushSprite(y, pSetting.m_nHeadID); } bool bHaveNumber = true; if (nType == HUDNumberRenderType.HUD_SHOW_ABSORB || nType == HUDNumberRenderType.HUB_SHOW_DODGE) { bHaveNumber = false; } if (bHaveNumber) { if (bShowAdd && pSetting.m_nAddID != 0) { pNode.PushSprite(y, pSetting.m_nAddID); } else if (bShowSub && pSetting.m_nSubID != 0) { pNode.PushSprite(y, pSetting.m_nSubID); } m_tempNumb.Clear(); int nI = 0; do { nI = nNumber % 10; nNumber /= 10; m_tempNumb.Add(nI); } while (nNumber > 0); // 反转数组 m_tempNumb.Reverse(); for (int i = 0, nSize = m_tempNumb.size; i < nSize; ++i) { nI = m_tempNumb[i]; pNode.PushSprite(y, pSetting.m_NumberID[nI]); } } // 居中处理吧 switch (attrib.AlignType) { case HUDAlignType.align_right: pNode.MakeRight(); break; case HUDAlignType.align_center: pNode.MakeCenter(); break; default: pNode.MakeLeft(); break; } // 申请纹理 OnPush(pNode); if (!m_bCaleScreenScale) { CaleScreenScale(); } PlayAnimation(pNode, true); }