// Copyright (c) Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Level/SceneObject.h"
#include "ScriptingObject.h"
///
/// Base class for all scripts.
///
API_CLASS(Abstract) class FLAXENGINE_API Script : public SceneObject
{
DECLARE_SCRIPTING_TYPE(Script);
friend Actor;
friend SceneTicking;
friend class PrefabInstanceData;
protected:
uint16 _enabled : 1;
uint16 _tickFixedUpdate : 1;
uint16 _tickUpdate : 1;
uint16 _tickLateUpdate : 1;
uint16 _tickLateFixedUpdate : 1;
uint16 _wasAwakeCalled : 1;
uint16 _wasStartCalled : 1;
uint16 _wasEnableCalled : 1;
#if USE_EDITOR
uint16 _executeInEditor : 1;
#endif
public:
///
/// Gets value indicating if script is active.
///
API_PROPERTY(Attributes="HideInEditor")
FORCE_INLINE bool GetEnabled() const
{
return _enabled != 0;
}
///
/// Sets enabled state if this script.
///
API_PROPERTY() void SetEnabled(bool value);
///
/// Gets value indicating if script is enabled and active in the scene graph. It must be active as well as all it's parents.
///
API_PROPERTY(Attributes="HideInEditor, NoSerialize") bool IsEnabledInHierarchy() const;
///
/// Gets the actor owning that script.
///
API_PROPERTY(Attributes="HideInEditor, NoAnimate")
Actor* GetActor() const;
///
/// Sets the actor owning that script.
///
API_PROPERTY() void SetActor(Actor* value);
public:
///
/// Called after the object is loaded.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnAwake()
{
}
///
/// Called when object becomes enabled and active.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnEnable()
{
}
///
/// Called when object becomes disabled and inactive.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnDisable()
{
}
///
/// Called before the object will be destroyed.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnDestroy()
{
}
///
/// Called when a script is enabled just before any of the Update methods is called for the first time.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnStart()
{
}
///
/// Called every frame if object is enabled.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnUpdate()
{
}
///
/// Called every frame (after gameplay Update) if object is enabled.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnLateUpdate()
{
}
///
/// Called every fixed framerate frame if object is enabled.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnFixedUpdate()
{
}
///
/// Called every fixed framerate frame (after FixedUpdate) if object is enabled.
///
API_FUNCTION(Attributes = "NoAnimate") virtual void OnLateFixedUpdate()
{
}
///
/// Called during drawing debug shapes in editor. Use to draw debug shapes and other visualization.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnDebugDraw()
{
}
///
/// Called during drawing debug shapes in editor when object is selected. Use to draw debug shapes and other visualization.
///
API_FUNCTION(Attributes="NoAnimate") virtual void OnDebugDrawSelected()
{
}
private:
void SetupType();
void Start();
void Enable();
void Disable();
public:
// [ScriptingObject]
String ToString() const override;
void OnDeleteObject() override;
// [SceneObject]
const Guid& GetSceneObjectId() const override;
void SetParent(Actor* value, bool canBreakPrefabLink = true) override;
int32 GetOrderInParent() const override;
void SetOrderInParent(int32 index) override;
void Initialize() override;
void BeginPlay(SceneBeginData* data) override;
void EndPlay() override;
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
};