The ScriptableObject class provides a template for objects that need scripting capabilities within the Unified Engine. A ScriptableObject is intended to be inherited by other classes to allow them to attach to a game object and be updated in sync with the game loop.
Key Features:
Inherits from ObjectComponent, making it part of the hierarchical tree structure of the engine.
Designed for extensibility to enable scripting features for game objects.
Components:
Constructors:
ScriptableObject(ObjectComponent* Parent): Constructs a ScriptableObject attached to a specified parent component.
Sample Implementation: Camera Controller
class CameraControl : public UnifiedEngine::ScriptableObject{
public:
GameObject* OBJ;
CameraControl(GameObject* Par, UnifiedEngine::ObjectComponent* Camera)
: UnifiedEngine::ScriptableObject(Par)
{
OBJ = Part;
OBJ = Par;
OBJ->Name = "CamCam";
instantiate(OBJ);
this->OBJ->Children.push_back(Camera);
Camera->Parent = OBJ;
}
int Update(){
//Player Movement
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->Input->Keyboard.KeyPressed(UnifiedEngine::Key_W))
this->OBJ->transform.Position += 0.002f*UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->front/UnifiedEngine::Time.DeltaTime;
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->Input->Keyboard.KeyPressed(UnifiedEngine::Key_A))
this->OBJ->transform.Position -= 0.002f*UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->right/UnifiedEngine::Time.DeltaTime;
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->Input->Keyboard.KeyPressed(UnifiedEngine::Key_S))
this->OBJ->transform.Position -= 0.002f*UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->front/UnifiedEngine::Time.DeltaTime;
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->Input->Keyboard.KeyPressed(UnifiedEngine::Key_D))
this->OBJ->transform.Position += 0.002f*UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->right/UnifiedEngine::Time.DeltaTime;
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->Input->Keyboard.KeyPressed(UnifiedEngine::Key_SPACE))
this->OBJ->transform.Position += 0.002f*UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->up/UnifiedEngine::Time.DeltaTime;
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->Input->Keyboard.KeyPressed(UnifiedEngine::Key_LEFT_SHIFT))
this->OBJ->transform.Position -= 0.002f*UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->up/UnifiedEngine::Time.DeltaTime;
//Player Rotation
glm::vec2 mPos = UnifiedEngine::__GAME__GLOBAL__INSTANCE__->Input->Mouse.GetPosition();
//Update pitch yaw and roll
UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.x += static_cast<GLfloat>(mPos.y) * (0.004 / UnifiedEngine::Time.DeltaTime);
UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.y += static_cast<GLfloat>(mPos.x) * (0.004 / UnifiedEngine::Time.DeltaTime);
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.x > 89.f)
UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.x = 89.f;
else if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.x < -89.f)
UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.x = -89.f;
if (UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.y > 360.f || UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.y < -360.f)
UnifiedEngine::__GAME__GLOBAL__INSTANCE__->GetMainCamera()->transform.Rotation.y = 0.f;
return 0;
}
};