CharacterComponent.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <Source/AutoGen/CharacterComponent.AutoComponent.h>
  9. #include <Multiplayer/Components/NetBindComponent.h>
  10. namespace Physics
  11. {
  12. class Character;
  13. }
  14. namespace MultiplayerSample
  15. {
  16. class CharacterComponent
  17. : public CharacterComponentBase
  18. {
  19. friend class CharacterComponentController;
  20. public:
  21. AZ_MULTIPLAYER_COMPONENT(MultiplayerSample::CharacterComponent, s_characterComponentConcreteUuid, MultiplayerSample::CharacterComponentBase);
  22. static void Reflect(AZ::ReflectContext* context);
  23. CharacterComponent();
  24. void OnInit() override;
  25. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  26. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  27. private:
  28. void OnTranslationChangedEvent(const AZ::Vector3& translation);
  29. void OnSyncRewind();
  30. Physics::Character* m_physicsCharacter = nullptr;
  31. Multiplayer::EntitySyncRewindEvent::Handler m_syncRewindHandler = Multiplayer::EntitySyncRewindEvent::Handler([this]() { OnSyncRewind(); });
  32. AZ::Event<AZ::Vector3>::Handler m_translationEventHandler;
  33. };
  34. class CharacterComponentController
  35. : public CharacterComponentControllerBase
  36. {
  37. public:
  38. CharacterComponentController(CharacterComponent& parent);
  39. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  40. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  41. AZ::Vector3 TryMoveWithVelocity(const AZ::Vector3& velocity, float deltaTime);
  42. };
  43. }