PrefabComponent.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "../Scene/Component.h"
  3. namespace Atomic
  4. {
  5. /// Helper base class for user-defined game logic components that hooks up to update events and forwards them to virtual functions similar to ScriptInstance class.
  6. class PrefabComponent : public Component
  7. {
  8. OBJECT(PrefabComponent);
  9. public:
  10. /// Construct.
  11. PrefabComponent(Context* context);
  12. /// Destruct.
  13. virtual ~PrefabComponent();
  14. /// Register object factory.
  15. static void RegisterObject(Context* context);
  16. void SetPrefabGUID(const String& guid);
  17. const String& GetPrefabGUID() const { return prefabGUID_; }
  18. bool SavePrefab();
  19. void UndoPrefab();
  20. void BreakPrefab();
  21. Node* GetPrefabNode() { return prefabNode_; }
  22. protected:
  23. /// Handle scene node being assigned at creation.
  24. virtual void OnNodeSet(Node* node);
  25. private:
  26. void HandlePrefabChanged(StringHash eventType, VariantMap& eventData);
  27. void LoadPrefabNode();
  28. SharedPtr<Node> prefabNode_;
  29. String prefabGUID_;
  30. };
  31. }