-
Notifications
You must be signed in to change notification settings - Fork 12
Starting scripting
Era Engine supports .NET 8.0 Native AOT compilation for user scripting libraries.
First of all every user script must be a public class inharited from Script
class.
For example:
using EraEngine;
using EraEngine.Core;
namespace EraScriptingProjectTemplate;
public class TestScript : Script
{
public override void Start()
{
Debug.Log("User script");
}
}
Working with the script you can override the void Start()
and void Update(float dt)
methods.
To detect collision from the script class you can override this methods:
void OnCollisionEnter(EEntity collision);
void OnTriggerEnter(EEntity trigger);
Soon other collision state callbacks will be part on scripting. Now it's only core engine features.
To signal the scene about something you can call void Signal(string signal)
and bool IsSignaled(string signal)
methods.
If you want to wait for a signal you can do it like this:
using EraEngine;
using EraEngine.Core;
namespace EraScriptingProjectTemplate;
public class WaitScript : Script
{
public override void Start()
{
while(!IsSignaled("Game_Launched"));
// Do some critical logic
}
}
public class SignalScript : Script
{
public override void Start()
{
// Do some critical logic
Signal("Game_Launched");
}
}
Every Script
class also implements EComponent
abstract class. That's why you can use EEntity Entity
field to
get current entity. All components are run concurrently.
EEntity
objects is a central objects, which owns components and represents a single game entity on the scene (or prefab).
By default, every EEntity
has a TransformComponent
in ComponentsContainer Components
.