Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "proxyentity.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "materialsystem/imaterialvar.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. // $sineVar : name of variable that controls the alpha level (float)
  14. class CAlphaMaterialProxy : public CEntityMaterialProxy
  15. {
  16. public:
  17. CAlphaMaterialProxy();
  18. virtual ~CAlphaMaterialProxy();
  19. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  20. virtual void OnBind( C_BaseEntity *pEntity );
  21. virtual IMaterial *GetMaterial();
  22. private:
  23. IMaterialVar *m_AlphaVar;
  24. };
  25. CAlphaMaterialProxy::CAlphaMaterialProxy()
  26. {
  27. m_AlphaVar = NULL;
  28. }
  29. CAlphaMaterialProxy::~CAlphaMaterialProxy()
  30. {
  31. }
  32. bool CAlphaMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  33. {
  34. bool foundVar;
  35. m_AlphaVar = pMaterial->FindVar( "$alpha", &foundVar, false );
  36. return foundVar;
  37. }
  38. void CAlphaMaterialProxy::OnBind( C_BaseEntity *pEnt )
  39. {
  40. if (m_AlphaVar)
  41. {
  42. m_AlphaVar->SetFloatValue( pEnt->m_clrRender->a );
  43. }
  44. }
  45. IMaterial *CAlphaMaterialProxy::GetMaterial()
  46. {
  47. if ( !m_AlphaVar )
  48. return NULL;
  49. return m_AlphaVar->GetOwningMaterial();
  50. }
  51. EXPOSE_INTERFACE( CAlphaMaterialProxy, IMaterialProxy, "Alpha" IMATERIAL_PROXY_INTERFACE_VERSION );