interactableComponent.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "T3D/components/game/interactableComponent.h"
  23. //////////////////////////////////////////////////////////////////////////
  24. // Constructor/Destructor
  25. //////////////////////////////////////////////////////////////////////////
  26. InteractableComponent::InteractableComponent() : Component(),
  27. mInteractableWeight(1)
  28. {
  29. mFriendlyName = "Interactable";
  30. mComponentType = "Game";
  31. mDescription = getDescriptionText("Allows owner entity to be interacted with.");
  32. }
  33. InteractableComponent::~InteractableComponent()
  34. {
  35. }
  36. IMPLEMENT_CO_NETOBJECT_V1(InteractableComponent);
  37. bool InteractableComponent::onAdd()
  38. {
  39. if (!Parent::onAdd())
  40. return false;
  41. return true;
  42. }
  43. void InteractableComponent::onRemove()
  44. {
  45. Parent::onRemove();
  46. }
  47. //This is mostly a catch for situations where the behavior is re-added to the object and the like and we may need to force an update to the behavior
  48. void InteractableComponent::onComponentAdd()
  49. {
  50. Parent::onComponentAdd();
  51. }
  52. void InteractableComponent::onComponentRemove()
  53. {
  54. Parent::onComponentRemove();
  55. }
  56. void InteractableComponent::initPersistFields()
  57. {
  58. Parent::initPersistFields();
  59. addField("interactableWeight", TypeF32, Offset(mInteractableWeight, InteractableComponent), "Controls importance values when using radius mode for interaction");
  60. }
  61. void InteractableComponent::interact(InteractComponent* interactor)
  62. {
  63. if (interactor != nullptr)
  64. {
  65. mOwner->notifyComponents("onInteract", interactor->getIdString());
  66. if(isMethod("onInteract"))
  67. Con::executef(this, "onInteract", interactor);
  68. }
  69. }
  70. void InteractableComponent::interact(InteractComponent* interactor, RayInfo rayInfo)
  71. {
  72. if (interactor != nullptr)
  73. {
  74. mOwner->notifyComponents("onInteract", interactor->getIdString());
  75. if (isMethod("onInteract"))
  76. Con::executef(this, "onInteract", interactor);
  77. }
  78. }