PrefabComponent.h 1001 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. Node* GetPrefabNode() { return prefabNode_; }
  21. protected:
  22. /// Handle scene node being assigned at creation.
  23. virtual void OnNodeSet(Node* node);
  24. private:
  25. void HandlePrefabChanged(StringHash eventType, VariantMap& eventData);
  26. void LoadPrefabNode();
  27. SharedPtr<Node> prefabNode_;
  28. String prefabGUID_;
  29. };
  30. }