Class Script
- Namespace
- LunyScript
- Assembly
- LunyScript.dll
Abstract base class for all LunyScripts. Provides the API interface for beginner-friendly block-based scripting in C#. Inherit from this class and implement its Build() method to construct script logic.
public abstract class Script
- Inheritance
-
objectScript
- Derived
Remarks
Minimal example script:
public class Example : LunyScript.Script
{
public override void Build(ScriptContext context)
{
// Define behaviour using declarative LunyScript API here ...
On.Ready(Debug.Log("Hello, LunyScript!"));
}
}
To run this script, create a GameObject in the scene and name it 'Example' - same as the script. In the future alternative script assignment options will be provided.
Constructors
Script()
protected Script()
Properties
Component
public ComponentApi Component { get; }
Property Value
Debug
public DebugApi Debug { get; }
Property Value
Editor
public EditorApi Editor { get; }
Property Value
GVar
Global variables
public VarAccessor GVar { get; }
Property Value
Input
public InputBuilder Input { get; }
Property Value
IsEditor
True if the script currently runs within the engine's editor (play mode). False in builds.
public bool IsEditor { get; }
Property Value
- bool
Name
public string Name { get; }
Property Value
- string
Object
public ObjectBuilder Object { get; }
Property Value
On
public OnObjectEventBuilder On { get; }
Property Value
Owner
Reference to proxy for engine object.
protected ILunyObject Owner { get; }
Property Value
Prefab
public PrefabBuilder Prefab { get; }
Property Value
Scene
public SceneApi Scene { get; }
Property Value
Time
public TimeApi Time { get; }
Property Value
Transform
public TransformBuilder Transform { get; }
Property Value
Var
Instance variables (unique per script/object)
public VarAccessor Var { get; }
Property Value
When
public WhenGlobalEventBuilder When { get; }
Property Value
Methods
AND(params ScriptConditionBlock[])
Logical AND: Returns true if all conditions are true.
public ScriptConditionBlock AND(params ScriptConditionBlock[] conditions)
Parameters
conditionsScriptConditionBlock[]
Returns
Build(ScriptContext)
Called once when the script is initialized. Users construct their blocks (sequences, statemachines, behaviors) for execution here. Users can use regular C# syntax (ie call methods, use loops) to construct complex and/or reusable blocks.
public abstract void Build(ScriptContext context)
Parameters
contextScriptContext
Check(Func<IScriptRuntimeContext, bool>)
Executes a System.Func<IScriptRuntimeContext, bool> (lambda) or method taking a IScriptRuntimeContext parameter and returns bool.
public ScriptConditionBlock Check(Func<IScriptRuntimeContext, bool> func)
Parameters
funcFunc<IScriptRuntimeContext, bool>
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Check" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
Check(Func<bool>)
Executes a System.Func<bool> (lambda) or parameterless method returning bool.
public ScriptConditionBlock Check(Func<bool> func)
Parameters
funcFunc<bool>
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Check" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
Coroutine(string)
Creates a named coroutine. Usage: Coroutine("name").Duration(3).Seconds().OnUpdate(blocks).Elapsed(blocks);
public CoroutineBuilder Coroutine(string name)
Parameters
namestring
Returns
~Script()
protected ~Script()
For(int)
For loop (1-based index): For(numberOfTimes).Do(blocks); Starts at 1 and increments by 1 until limit is reached (inclusive).
public ForBlockBuilder For(int numberOfTimes)
Parameters
numberOfTimesint
Returns
For(int, int)
For loop (1-based index): For(limit, step).Do(blocks); If step is positive: starts at 1 and increments by step until limit is reached. If step is negative: starts at limit and decrements by step until 1 is reached.
public ForBlockBuilder For(int numberOfTimes, int step)
Parameters
numberOfTimesintstepint
Returns
If(params ScriptConditionBlock[])
Conditional execution: If(conditions).Then(blocks).ElseIf(conditions).Then(blocks).Else(blocks); Multiple conditions are implicitly AND combined.
public IfBlock If(params ScriptConditionBlock[] conditions)
Parameters
conditionsScriptConditionBlock[]
Returns
NOT(ScriptConditionBlock)
Logical NOT: Returns the inverse of the condition.
public ScriptConditionBlock NOT(ScriptConditionBlock condition)
Parameters
conditionScriptConditionBlock
Returns
OR(params ScriptConditionBlock[])
Logical OR: Returns true if at least one condition is true.
public ScriptConditionBlock OR(params ScriptConditionBlock[] conditions)
Parameters
conditionsScriptConditionBlock[]
Returns
Run(Action)
Executes a System.Action (lambda) or parameterless method returning void.
public ScriptActionBlock Run(Action action)
Parameters
actionAction
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Run" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
Run(Action<IScriptRuntimeContext>)
Executes a System.Action (lambda) or a method that takes a IScriptRuntimeContext parameter and returns void.
public ScriptActionBlock Run(Action<IScriptRuntimeContext> action)
Parameters
actionAction<IScriptRuntimeContext>
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Run" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
ToString()
public override string ToString()
Returns
- string
While(params ScriptConditionBlock[])
Loop execution: While(conditions).Do(blocks); Multiple conditions are implicitly AND combined.
public WhileBlockBuilder While(params ScriptConditionBlock[] conditions)
Parameters
conditionsScriptConditionBlock[]