Beispiel #1
0
 void  OnPush(HUDNumberEntry pNode)
 {
     for (int i = 0; i < pNode.m_aSprite.size; ++i)
     {
         HUDMesh hudMesh = m_MeshRender.QueryMesh(pNode.m_aSprite[i].AtlasID);
         pNode.m_aSprite[i].hudMesh = hudMesh;
         hudMesh.PushHUDVertex(pNode.m_aSprite[i]);
     }
 }
Beispiel #2
0
 void  ReleaseHudNumber(HUDNumberEntry pNode)
 {
     if (pNode != null)
     {
         int nIndex = (int)pNode.m_nType;
         pNode.m_pNext = m_aInvalid;
         m_aInvalid    = pNode;
     }
 }
Beispiel #3
0
 void CleanCurrentNumber()
 {
     while (m_ValidList != null)
     {
         HUDNumberEntry pDel = m_ValidList;
         m_ValidList  = m_ValidList.m_pNext;
         pDel.m_pNext = null;
         OnErase(pDel);
     }
     m_bMeshDirty = true;
 }
Beispiel #4
0
 public void OnLeaveGame()
 {
     while (m_ValidList != null)
     {
         HUDNumberEntry pDel = m_ValidList;
         m_ValidList = m_ValidList.m_pNext;
         OnErase(pDel);
     }
     ReleaseCmmmandBuffer();
     m_MeshRender.Release();
 }
Beispiel #5
0
    HUDNumberEntry  QueryHudNumber(HUDNumberRenderType nType)
    {
        int            nIndex = (int)nType;
        HUDNumberEntry pNode  = m_aInvalid;

        if (pNode != null)
        {
            m_aInvalid    = pNode.m_pNext;
            pNode.m_pNext = null;
        }
        if (pNode == null)
        {
            pNode         = new HUDNumberEntry();
            pNode.m_nType = nType;
        }
        return(pNode);
    }
Beispiel #6
0
    // 功能:添加一个显示的数字
    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);
    }
Beispiel #7
0
    void  UpdateLogic(float delta)
    {
        // 计算屏幕的缩放
        CaleScreenScale();

        HUDNumberEntry pNode = m_ValidList;
        HUDNumberEntry pLast = m_ValidList;

        while (pNode != null)
        {
            PlayAnimation(pNode, false);
            if (pNode.m_bStop)
            {
                HUDNumberEntry pDel = pNode;
                if (pNode == m_ValidList)
                {
                    m_ValidList = m_ValidList.m_pNext;
                    pLast       = m_ValidList;
                }
                else
                {
                    pLast.m_pNext = pNode.m_pNext;
                }
                pNode = pNode.m_pNext;
                OnErase(pDel);
                continue;
            }
            pLast = pNode;
            pNode = pNode.m_pNext;
        }
        if (m_ValidList == null)
        {
            m_bMeshDirty = true;
        }

        // 处理二级面板开启
        // 屏幕变黑后的处理
        if (m_bStartDark != m_bOldStartDark)
        {
            m_bOldStartDark = m_bStartDark;
            m_bMeshDirty    = true;
        }
        else if (m_bStartDark)
        {
            if (m_fStartDarkTime + m_fDarkTime < Time.time)
            {
                m_bStartDark = false;
            }
        }
        bool bOpenUI = m_bOpenUI || m_bStartDark || m_bStartMovie;

        if (m_bOldOpenUI != bOpenUI)
        {
            m_bOldOpenUI = bOpenUI;
            m_bMeshDirty = true;
        }

        FillMeshRender();
        if (m_ValidList == null)
        {
            if (m_fLastUpdateLogicTime + 5.0f < Time.time)
            {
                m_bAddUpdateLogic = false;
                UpdateManager.DelUpdate(UpdateLogic);
            }
            CleanAllMeshRender();
        }
        else
        {
            m_fLastUpdateLogicTime = Time.time;
        }
    }
Beispiel #8
0
 void  OnErase(HUDNumberEntry pNode)
 {
     // 释放模型的数据吧
     pNode.ReleaseVertex();
     ReleaseHudNumber(pNode);
 }
Beispiel #9
0
    // 功能:执行数字的动画效果
    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();
        }
    }