-
Notifications
You must be signed in to change notification settings - Fork 0
Scripting
This is going to be a pretty quick overview and documentation of all of the scripting elements of the ShibaEngine.
LogMessage displays a message in the engine's console, these messages won't be visible when called in a compiled executable.
ShibaEngineCore.Console.LogMessage("Hello World!");
Displays an error message in the engine's console, similar to LogMessage.
This field is the entity id of the instance, this is used mostly by the engine itself.
This is the name of the instance, assigned in the scene.
T in this method should derive from CoreComponent, this method obtains the core component object from the instance it's called from.
public class Example : Component
{
public Instance instance;
public void Start()
{
var transform = instance.GetCoreComponent<Transform>();
transform.position = new Vector3(0.0f, 5.0f, 0.0f);
}
}
T in this method should derive from Component, this method obtains the object of the attached script to an instance.
public class Example : Component
{
public int otherField;
public Instance instance;
public void Start()
{
var otherExample = instance.GetComponent<Example>();
ShibaEngineCore.Console.LogMessage(otherExample.otherField.ToString());
}
}
T in this method should derive from Component, this method adds a new component of a script to the instance.
public class Example : Component
{
public Instance instance;
public void Start()
{
instance.AddComponent<Example>();
}
}
T in this method should derive from Component, this method finds all of the specified components in the children of the instance.
public class Example : Component
{
public int otherField;
public Instance instance;
public void Start()
{
foreach(var example : instance.FindComponentsInChildren<Example>())
{
ShibaEngineCore.Console.LogMessage(example.otherField.ToString());
}
}
}
This is directly copied from the GLFW keycodes, this is just used to determine which key to check.
Checks whether the selected key had been pressed.
Time since the last frame, mostly used to make things framerate-independent.
The current frame count of the program, the same as glfwGetTime().
A behaviour is a static class that isn't attached to any instance, it runs an updates method at either a set interval or each frame.
It is created by using the Behaviour attribute on any static class.
[Behaviour(3.5f)]
public static class ExampleBehaviour
{
public static void Update()
{
// gets called every 3.5 seconds
ShibaEngineCore.Console.LogMessage("Behaviour Update");
}
}
Creates a new entity and returns it's id.
The T in this method needs to derive from Component, this returns all the ids of entities that have the specified component attached.
public class Example : Component
{
public int otherField;
public Instance instance;
public void Start()
{
foreach(var example : Scene.FindComponentsInScene<Example>())
{
var instance = GetInstance(example);
ShibaEngineCore.Console.LogMessage(instance.name);
}
}
}
Gets the instance object for the specified entity id.
public class Example : Component
{
public int otherField;
public Instance instance;
public void Start()
{
foreach(var example : Scene.FindComponentsInScene<Example>())
{
var instance = GetInstance(example);
ShibaEngineCore.Console.LogMessage(instance.name);
}
}
}
public class VerticalMovement : Component
{
public float speed;
public void Update()
{
if (Input.GetKeyDown(KeyCode.KEY_SPACE))
{
transform.position += Vector3.UnitY * speed * Time.deltaTime;
}
}
}
public class SpinningObject : Component
{
public Instance otherObject;
private Transform otherTransform;
public float radius;
public float speed;
public void Start()
{
otherTransform = otherObject.GetCoreComponent<Transform>();
}
public void Update()
{
var circlePosition = new Vector3(MathF.Sin(Time.currentTime * speed) * radius, transform.position.y, MathF.Cos(Time.currentTime * speed) * radius);
transform.position = circlePosition + otherTransform.position;
}
}