Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. // GameObject.h
  2. #pragma once
  3.  
  4. class CGameObject : public CAVEvents
  5. {
  6. public:
  7.     std::string name;
  8.    
  9.     std::string tag;
  10.  
  11.     int id;
  12.  
  13.     NativeArray<CComponent>* components;
  14.  
  15.     CGameObject* gameObject;
  16.  
  17. public:
  18.     CGameObject();
  19.  
  20.     void OnUpdate() override;
  21.  
  22.     ~CGameObject();
  23.  
  24. public:
  25. };
  26.  
  27. // GameObject.cpp
  28.  
  29. #include "AVEvents.h"
  30. #include <string>
  31. #include "AVEM.h"
  32. #include "Component.h"
  33. #include "GameObject.h"
  34.  
  35. CGameObject::CGameObject()
  36. {
  37.     name = "Obejct";
  38.     tag = "Default";
  39.     gameObject = this;
  40.     components = new NativeArray<CComponent>();
  41.     id = 0;
  42. }
  43.  
  44. void CGameObject::OnUpdate()
  45. {
  46. }
  47.  
  48. CGameObject::~CGameObject()
  49. {
  50. }
  51.  
  52. // Component.h
  53.  
  54. #pragma once
  55.  
  56. class CComponent
  57. {
  58. public:
  59.     CGameObject* gameObject;
  60.  
  61. public:
  62.     CComponent()
  63.     {
  64.     }
  65.  
  66.     template<class T>
  67.     static T* AddComponent();
  68.  
  69.     ~CComponent()
  70.     {
  71.  
  72.     }
  73.  
  74. };
  75.  
  76. // Component.cpp
  77.  
  78. #include "GameObject.h"
  79. #include "Component.h"
  80.  
  81. template <class T>
  82. T* CComponent::AddComponent()
  83. {
  84.     T* ptr = new (T);
  85.     return ptr;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement