Skip to content

Scripting API

Victor edited this page Jan 17, 2023 · 3 revisions

C# API

Components

Components are structs that can only contain variables.

Example

[Component]
public struct PlayerComp 
{
    public float Speed;
    public bool Grounded;
}

Behaviour

Behaviours is the base class for a scriptable system.

Methods

Called at the start of the game

void Awake(){}

Called at the after Awake

void Init(){}

Called every frame

void Update(){}

Returns a reference of a given component for the current entity

public ref T GetComponent<T>()

Adds and returns a reference of a given component for the current entity

public ref T AddComponent<T>()

Applys a given system for the current entity

public void ApplySystem<T>()

Destroys the current entity

public void DestroyEntity()

Creates a new entity and returns it's Id

public EntityId CreateEntity()

Adds the mesh component for a give entity

 public static void AddMesh(EntityId eid, string model, string material)

Example

[Component]
public struct PingPongComp
{
    public float speed;
    public float turnTime;
    public float turnTimer;
    public int direction;
}
class MovePingpong : Behaviour
{
    void Update()
    {
        ref Transform3D t3d = ref GetComponent<Transform3D>();
        ref PingPongComp ppc = ref GetComponent<PingPongComp>();

        ppc.turnTimer += Time.DeltaTime();

        Vector3 forward = Math.CalculateForward(ref t3d);

        if(ppc.turnTimer >= ppc.turnTime)
        {
            ppc.turnTimer = 0.0f;

            ppc.direction *= -1;
        }

        t3d.LocalPosition += forward * ppc.speed * Time.DeltaTime() * ppc.direction;
    }
}

Input

Standart input class to get input from the user

Methods

Returns true if a the given keycode is pressed

public static bool IsKeyDown(KeyCode keyCode)

Returns true if a the given mouse button is pressed

  • 0 LMB
  • 1 MMB
  • 2 RMB
public static bool IsMouseKeyDown(int button)

Returns the position of the mouse in X

public static float GetMouseX()

Returns the position of the mouse in Y

public static float GetMouseY()

Returns the X axis movement of the mouse

public static float GetMouseXDelta()

Returns the Y axis movement of the mouse

public static float GetMouseYDelta()

Math

Standart math class

Variables

Vector3 forward a vector reference for {0, 0, 1} Vector3 up a vector reference for {1, 0, 0} Vector3 right a vector reference for {0, 1, 0}

Structs

Vector3 A vector in 3D space Vector2 A vector in 2D space Quaternion A representation of a rotation in 3D space

Methods

Trigonometry

public static T Clamp<T>(this T val, T min, T max)
public static double Radians(double degrees)
public static double Cos(double value)
public static double Sqrt(double value)
public static double Atan2(double x, double y)
public static Vector3 Normalize(Vector3 A)
public static Vector3 CrossProduct(Vector3 v1, Vector3 v2)
public static float DegToRad(float deg)
public static float RadToDeg(float rad)

Transforms

public static Vector3 CalculateUp(ref Transform3D t3d)
public static Vector3 CalculateForward(ref Transform3D t3d)
public static Vector3 CalculateRight(ref Transform3D t3d)
public static void Translate(ref Transform3D transform, Vector3 pos)
public static Vector3 ToEuler(Quaternion q)

Resources

Methods

public static ulong LoadModel(string str)

Time

Standart time class

Methods

public static float GetTime()
public static float DeltaTimeMS()
public static float DeltaTime()

Clone this wiki locally