BsScriptLight.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "BsScriptLight.h"
  2. #include "BsScriptSceneObject.h"
  3. #include "BsSceneObject.h"
  4. #include "BsScriptSceneObject.h"
  5. #include "BsSceneManager.h"
  6. namespace BansheeEngine
  7. {
  8. ScriptLight::ScriptLight(MonoObject* managedInstance, const HSceneObject& parentSO)
  9. :ScriptObject(managedInstance), mLight(nullptr), mLastUpdateHash(0)
  10. {
  11. mLight = Light::create();
  12. gSceneManager()._registerLight(mLight, parentSO);
  13. }
  14. ScriptLight::~ScriptLight()
  15. { }
  16. void ScriptLight::initRuntimeData()
  17. {
  18. metaData.scriptClass->addInternalCall("Internal_Create", &ScriptLight::internal_create);
  19. metaData.scriptClass->addInternalCall("Internal_GetType", &ScriptLight::internal_getType);
  20. metaData.scriptClass->addInternalCall("Internal_SetType", &ScriptLight::internal_setType);
  21. metaData.scriptClass->addInternalCall("Internal_GetCastsShadow", &ScriptLight::internal_getCastsShadow);
  22. metaData.scriptClass->addInternalCall("Internal_SetCastsShadow", &ScriptLight::internal_setCastsShadow);
  23. metaData.scriptClass->addInternalCall("Internal_GetColor", &ScriptLight::internal_getColor);
  24. metaData.scriptClass->addInternalCall("Internal_SetColor", &ScriptLight::internal_setColor);
  25. metaData.scriptClass->addInternalCall("Internal_GetRange", &ScriptLight::internal_getRange);
  26. metaData.scriptClass->addInternalCall("Internal_SetRange", &ScriptLight::internal_setRange);
  27. metaData.scriptClass->addInternalCall("Internal_GetIntensity", &ScriptLight::internal_getIntensity);
  28. metaData.scriptClass->addInternalCall("Internal_SetIntensity", &ScriptLight::internal_setIntensity);
  29. metaData.scriptClass->addInternalCall("Internal_GetSpotAngle", &ScriptLight::internal_getSpotAngle);
  30. metaData.scriptClass->addInternalCall("Internal_SetSpotAngle", &ScriptLight::internal_setSpotAngle);
  31. metaData.scriptClass->addInternalCall("Internal_GetSpotFalloffAngle", &ScriptLight::internal_getSpotFalloffAngle);
  32. metaData.scriptClass->addInternalCall("Internal_SetSpotFalloffAngle", &ScriptLight::internal_setSpotFalloffAngle);
  33. metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptLight::internal_getBounds);
  34. metaData.scriptClass->addInternalCall("Internal_UpdateTransform", &ScriptLight::internal_updateTransform);
  35. metaData.scriptClass->addInternalCall("Internal_OnDestroy", &ScriptLight::internal_onDestroy);
  36. }
  37. void ScriptLight::internal_create(MonoObject* managedInstance, ScriptSceneObject* parentSO)
  38. {
  39. HSceneObject so;
  40. if (parentSO != nullptr)
  41. so = parentSO->getNativeHandle();
  42. ScriptLight* nativeInstance = new (bs_alloc<ScriptLight>()) ScriptLight(managedInstance, so);
  43. }
  44. LightType ScriptLight::internal_getType(ScriptLight* thisPtr)
  45. {
  46. return thisPtr->getInternal()->getType();
  47. }
  48. void ScriptLight::internal_setType(ScriptLight* thisPtr, LightType type)
  49. {
  50. thisPtr->getInternal()->setType(type);
  51. }
  52. bool ScriptLight::internal_getCastsShadow(ScriptLight* thisPtr)
  53. {
  54. return thisPtr->getInternal()->getCastsShadow();
  55. }
  56. void ScriptLight::internal_setCastsShadow(ScriptLight* thisPtr, bool castsShadow)
  57. {
  58. thisPtr->getInternal()->setCastsShadow(castsShadow);
  59. }
  60. void ScriptLight::internal_getColor(ScriptLight* thisPtr, Color* color)
  61. {
  62. *color = thisPtr->getInternal()->getColor();
  63. }
  64. void ScriptLight::internal_setColor(ScriptLight* thisPtr, Color color)
  65. {
  66. thisPtr->getInternal()->setColor(color);
  67. }
  68. float ScriptLight::internal_getRange(ScriptLight* thisPtr)
  69. {
  70. return thisPtr->getInternal()->getRange();
  71. }
  72. void ScriptLight::internal_setRange(ScriptLight* thisPtr, float range)
  73. {
  74. thisPtr->getInternal()->setRange(range);
  75. }
  76. float ScriptLight::internal_getIntensity(ScriptLight* thisPtr)
  77. {
  78. return thisPtr->getInternal()->getIntensity();
  79. }
  80. void ScriptLight::internal_setIntensity(ScriptLight* thisPtr, float intensity)
  81. {
  82. thisPtr->getInternal()->setIntensity(intensity);
  83. }
  84. float ScriptLight::internal_getSpotAngle(ScriptLight* thisPtr)
  85. {
  86. return thisPtr->getInternal()->getSpotAngle().valueDegrees();
  87. }
  88. void ScriptLight::internal_setSpotAngle(ScriptLight* thisPtr, float spotAngle)
  89. {
  90. thisPtr->getInternal()->setSpotAngle(Degree(spotAngle));
  91. }
  92. float ScriptLight::internal_getSpotFalloffAngle(ScriptLight* thisPtr)
  93. {
  94. return thisPtr->getInternal()->getSpotFalloffAngle().valueDegrees();
  95. }
  96. void ScriptLight::internal_setSpotFalloffAngle(ScriptLight* thisPtr, float spotFalloffAngle)
  97. {
  98. thisPtr->getInternal()->setSpotFalloffAngle(Degree(spotFalloffAngle));
  99. }
  100. void ScriptLight::internal_getBounds(ScriptLight* thisPtr, Sphere* bounds)
  101. {
  102. *bounds = thisPtr->getInternal()->getBounds();
  103. }
  104. void ScriptLight::internal_updateTransform(ScriptLight* thisPtr, ScriptSceneObject* parent)
  105. {
  106. HSceneObject parentSO = parent->getNativeSceneObject();
  107. if (!parentSO.isDestroyed())
  108. {
  109. thisPtr->getInternal()->_updateTransform(parentSO);
  110. if (parentSO->getActive() != thisPtr->getInternal()->getIsActive())
  111. {
  112. thisPtr->getInternal()->setIsActive(parentSO->getActive());
  113. }
  114. }
  115. }
  116. void ScriptLight::internal_onDestroy(ScriptLight* instance)
  117. {
  118. instance->destroy();
  119. }
  120. void ScriptLight::destroy()
  121. {
  122. if (mLight->isDestroyed())
  123. return;
  124. gSceneManager()._unregisterLight(mLight);
  125. mLight->destroy();
  126. }
  127. void ScriptLight::_onManagedInstanceDeleted()
  128. {
  129. destroy();
  130. ScriptObject::_onManagedInstanceDeleted();
  131. }
  132. }