void CheckPos(bool bCameraDirty, Vector3 vCameraPos) { if (m_tf == null) { m_fEndTime = 0.0f; return; } Vector3 vPos = m_tf.position; vPos.y += m_fOffsetY; if (!bCameraDirty) { Vector3 v = vPos - m_vPos; if (v.x * v.x + v.y * v.y + v.z * v.z < 0.000001f) { return; } } m_vPos = vPos; CaleCameraScale(vCameraPos); Camera caMain = HUDMesh.GetHUDMainCamera(); if (caMain != null) { m_vScreenPos = caMain.WorldToScreenPoint(vPos); OnChangeScreenPos(); } }
bool m_bHideAllTalk = false; // 是不是隐藏所有气泡 // 一个对象的头顶只能一个气泡对话 public void ShowTalk(Transform tf, string szTalk, float fOffsetY, float fShowTime, int nColorIndex = 0) { EraseTalk(tf); Camera caMain = HUDMesh.GetHUDMainCamera(); if (fShowTime < 1f) { fShowTime = HudSetting.Instance.m_fTalkShowTime; } fOffsetY += HudSetting.Instance.m_fTalkOffsetY; Vector3 vPos = tf.position; HUDTalk talk = new HUDTalk(); talk.m_tf = tf; talk.m_vPos = vPos; talk.m_fOffsetY = fOffsetY; talk.m_fStartTime = Time.time; talk.m_fEndTime = talk.m_fStartTime + fShowTime; vPos.y += fOffsetY; talk.m_vScreenPos = caMain.WorldToScreenPoint(vPos); talk.CaleCameraScale(caMain.transform.position); talk.ShowTalk(szTalk, nColorIndex); m_TalkList.Add(talk); m_bMeshDirty = true; }
// 功能:更新屏幕位置 public bool UpdateScreenPos(ref HudAnimAttibute attrib) { if (attrib.ScreenAlign) { return(false); } if (m_tf != null) { Vector3 vPos = m_tf.position; Vector3 v = vPos - m_vPos; if (v.x * v.x + v.y * v.y + v.z * v.z > 0.00001f) { Camera caMain = HUDMesh.GetHUDMainCamera(); if (caMain != null) { m_vPos = vPos; m_vScreenPos = caMain.WorldToScreenPoint(vPos); Vector3 vCameraPos = caMain.transform.position; CaleCameraScale(vCameraPos); return(true); } } } return(false); }
public int RegisterTitle(Transform tf, float fOffsetY, bool bIsMain) { Camera caMain = HUDMesh.GetHUDMainCamera(); if (bIsMain) { m_tfMain = tf; } Vector3 vPos = tf.position; HUDTitleInfo title = new HUDTitleInfo(); title.m_tf = tf; title.m_bIsMain = bIsMain; title.m_vPos = vPos; title.m_fOffsetY = fOffsetY; if (caMain != null) { vPos.y += fOffsetY + HudSetting.Instance.m_fTitleOffsetY; title.m_vScreenPos = caMain.WorldToScreenPoint(vPos); title.CaleCameraScale(caMain.transform.position); } int nID = ++m_nHudID; title.m_nTitleID = nID; m_HudTitles[nID] = title; if (bIsMain) { title.m_pBatcher = m_StaticBatcher; } else { title.m_pBatcher = m_DynamicBatcher; } title.m_fLastMoveTime = Time.time; title.m_pBatcher.PushTitle(title); if (!m_bAddUpdate) { m_bAddUpdate = true; UpdateManager.AddLateUpdate(null, 0, UpdateLogic); } if (!m_bInitFontCallback) { m_bInitFontCallback = true; UIFont uiFont = HUDTitleInfo.GetHUDTitleFont(); Font.textureRebuilt += OnAllFontChanged; } return(nID); }
void FillMeshRender() { Camera caMain = HUDMesh.GetHUDMainCamera(); if (m_cmdBuffer == null) { m_cmdBuffer = new CommandBuffer(); } else { if (m_renderCameara != null) { m_renderCameara.RemoveCommandBuffer(CameraEvent.AfterImageEffects, m_cmdBuffer); } } m_cmdBuffer.Clear(); m_renderCameara = null; if (m_bOpenUI || m_bStartDark) { return; } if (!m_bHideAllTitle) { m_DynamicBatcher.m_MeshRender.RenderTo(m_cmdBuffer); m_StaticBatcher.m_MeshRender.RenderTo(m_cmdBuffer); } else { m_DynamicBatcher.m_MeshRender.OnCacelRender(); m_StaticBatcher.m_MeshRender.OnCacelRender(); } // 添加对话 HUDTalk.HUDTalkRender.Instance.TryRenderTalk(m_cmdBuffer); if (m_cmdBuffer.sizeInBytes > 0) { m_renderCameara = caMain; caMain.AddCommandBuffer(CameraEvent.AfterImageEffects, m_cmdBuffer); } }
void FillMeshRender() { m_MeshRender.FillMesh(); if (m_MeshRender.m_bMeshDirty) { m_bMeshDirty = true; } if (!m_bMeshDirty) { Camera caMain = HUDMesh.GetHUDMainCamera(); if (caMain != m_oldCamera) { m_oldCamera = caMain; m_bMeshDirty = true; } } if (m_bMeshDirty) { m_bMeshDirty = false; if (m_renderCamera != null) { m_renderCamera.RemoveCommandBuffer(CameraEvent.AfterImageEffects, s_cmdBuffer); m_renderCamera = null; m_bAddCommandBuffer = false; } Camera caMain = HUDMesh.GetHUDMainCamera(); s_cmdBuffer.Clear(); if (caMain == null || m_bOpenUI || m_bStartDark || m_bStartMovie) { return; } m_MeshRender.RenderTo(s_cmdBuffer); if (s_cmdBuffer.sizeInBytes > 0 && caMain != null) { m_renderCamera = caMain; caMain.AddCommandBuffer(CameraEvent.AfterImageEffects, s_cmdBuffer); m_bAddCommandBuffer = true; } } }
void ApplyMove(bool bCameraDirty, Vector3 vCameraPos) { Camera caMain = HUDMesh.GetHUDMainCamera(); Vector3 vPos = m_tf.position; Vector3 vScale = m_tf.localScale; vPos.y += (m_fOffsetY + HudSetting.Instance.m_fTitleOffsetY) * vScale.y; if (!bCameraDirty && !m_bDirty) { float dx = vPos.x - m_vPos.x; float dz = vPos.z - m_vPos.z; float dy = vPos.y - m_vPos.y; bool bDirty = !m_bInitHUDMesh; if (dx * dx + dz * dz + dy * dy > 0.00001f) { bDirty = true; } if (!bDirty) { return; } if (m_pBatcher != null) { m_pBatcher.m_bTitleMove = true; } m_fLastMoveTime = Time.time; } m_bDirty = false; m_vPos = vPos; m_vScreenPos = caMain.WorldToScreenPoint(vPos); m_fDistToCamera = Vector3.Distance(vCameraPos, m_vPos); if (m_bIsMain) { m_fDistToCamera -= 1000.0f; } CaleCameraScale(vCameraPos); OnChangeScreenPos(); }
void BaseUpdateLogic(float delta) { m_nBaseUpdateVer++; Camera caMain = HUDMesh.GetHUDMainCamera(); if (caMain == null) { return; } HUDTalk.HUDTalkRender talkRender = HUDTalk.HUDTalkRender.Instance; Vector3 vCameraPos = caMain.transform.position; Vector3 vOffset = vCameraPos - m_vLastCameraPos; bool bCameraDirty = vOffset.x * vOffset.x + vOffset.y * vOffset.y + vOffset.z * vOffset.z > 0.000001f; if (!bCameraDirty) { vOffset = caMain.transform.localEulerAngles - m_vLastEulerAngles; if (vOffset.x * vOffset.x + vOffset.y * vOffset.y + vOffset.z * vOffset.z > 0.000001f) { bCameraDirty = true; } } bool bMeshDirty = m_bMeshDirty; if (caMain != m_oldCamera) { m_oldCamera = caMain; bCameraDirty = true; bMeshDirty = true; } if (bCameraDirty) { m_vLastCameraPos = vCameraPos; m_vLastEulerAngles = caMain.transform.localEulerAngles; m_fLastCheckMoveTime = Time.time; float fScaleX = Screen.width / 1280.0f; float fScaleY = Screen.height / 720.0f; float fScale = fScaleX > fScaleY ? fScaleX : fScaleY; HUDMesh.s_fCameraScaleX = HUDMesh.s_fCameraScale * fScale; HUDMesh.s_fCameraScaleY = HUDMesh.s_fCameraScale * fScale; CaleNumberScale(vCameraPos); } else { // 切换 float fNow = Time.time; if (m_fLastCheckMoveTime + 2.0f < fNow) { m_fLastCheckMoveTime = fNow; SwitchDynamieStatic(); // 这个不可以转换是什么鬼,有BUG } } // NPC对话 talkRender.UpdateLogic(bCameraDirty, vCameraPos); if (talkRender.IsMeshDirty()) { bMeshDirty = true; } if (m_bHideAllTitle != HudSetting.Instance.HideAllTitle) { m_bHideAllTitle = HudSetting.Instance.HideAllTitle; bMeshDirty = true; } // 静态批 m_StaticBatcher.UpdateLogic(bCameraDirty, vCameraPos); if (m_StaticBatcher.m_MeshRender.m_bMeshDirty) { bMeshDirty = true; } // 动态批 m_DynamicBatcher.UpdateLogic(bCameraDirty, vCameraPos); if (m_DynamicBatcher.m_MeshRender.m_bMeshDirty) { bMeshDirty = true; } // 处理二级面板开启 if (m_bOpenUI != m_bOldOpenUI) { m_bOldOpenUI = m_bOpenUI; bMeshDirty = true; } else if (m_bOpenUI) { //if (caMain.cullingMask != 0) //{ // m_bNpcTalk = false; // 强制隐藏(界面上层的错误) //} } // 屏幕变黑后的处理 if (m_bStartDark != m_bOldStartDark) { m_bOldStartDark = m_bStartDark; bMeshDirty = true; } else if (m_bStartDark) { if (m_fStartDarkTime + m_fDarkTime < Time.time) { m_bStartDark = false; } } if (m_bMeshDirty) { m_bMeshDirty = false; bMeshDirty = true; } // 写和缓冲BUFF if (bMeshDirty) { FillMeshRender(); } }
// 功能:添加一个显示的数字 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); }