Runtime::Scene
- Last UpdatedSep 05, 2024
- 3 minute read
The Runtime::Scene class provides useful functionalities for accessing and modifying nodes in the scene.
Code example
This is a code example for Runtime::Scene.
List<string> a=Runtime::Scene.EnumerateFields("Player0_Avatar,all");
List<string> a=Runtime::Scene.EnumerateGroups("all");
List<string> a=Runtime::Scene.EnumerateNodes("items");
Runtime::Scene.ExecuteSFunction("viewport_DEFAULT_VIEWPORT.getSceneLayerCamera","hello");
Runtime::Scene.ExecuteSFunction("viewport_DEFAULT_VIEWPORT.getSceneLayerCamera");
bool b= Runtime::Scene.ExistsDefine("system.platform"); //b= True if system.platform node exists
bool b= Runtime::Scene.ExistsNode("Player0_Avatar"); //b= True if Player0_Avatar node exists
string s= Runtime::Scene.GetDefine("system.platforms"); //s=win64;
double v=Runtime::Scene.GetFieldValue("Player0_Avatar.behindFov"); //v=85;
var avatar= Runtime::Scene.GetNode("Player0_Avatar"); //s=Player0_Avatar
Runtime::Environment.Print("@def:system.debug@: "+Runtime::Scene.Resolve("@def:system.debug@")); //@def:system.debug@: true
Runtime::Scene.SetFieldValue("testVar.value", “hello world”); //here testVar is a Var of type sstring in the Graphics Context
Runtime::Scene.SetFieldValue("testVar.value", value); //here testVar is a Var of type sdouble in the Graphics Context and string value = "9.3";
In regards to Runtime::Scene.GetNode, when a node is retrieved, it is possible to access its fields by using the syntax: nodeName.fieldName as shown in the following example:
var avatar = Runtime::Scene.GetNode("Player0_Avatar");
avatar.behindFov = 50;
double v = avatar.behindFov; //v=85; avatar.behindFov=85
v = 34; //v=34; avatar.behindFov=85
avatar.behindFov = v; //v=34; avatar.behindFov=34
Node fields can be used for variable assignment, as shown in the previous example.
However, they cannot be used inside of methods or statement calls. The following example code will raise an error.
Incorrect example—Node fields cannot be used inside methods
var clipNode= Runtime::Scene.GetNode("clipping_node");
if(clipNode.enabled==true) //Raises an error
{
Runtime::Environment.Print("clip enabled");
}
Correct example—Use this approach instead
var clipNode= Runtime::Scene.GetNode("clipping_node");
bool clipNodeEnabled= clipNode.enabled;
if(clipNodeEnabled ==true) //Doesn’t’ raise an error
{
Runtime::Environment.Print("clip enabled");
}
Methods
The following table shows the currently implemented methods.
|
Method |
Return type |
Parameters |
Description |
|---|---|---|---|
|
EnumerateFields |
List<string> |
string value |
Gets a List<string> of field names. The value string is composed by two comma-separated parameters: the first parameter is the node name and the second parameter is used to restrict the fields. For the second parameter, the possible options are:
|
|
EnumerateGroups |
List<string> |
string value |
Gets a List<string> of group names. value string can be:
|
|
EnumerateNodes |
List<string> |
string value |
Gets a List<string> of node names. The value string can be:
|
|
ExecuteSFunction |
string |
string sFunctionName, string par |
Executes a field sFunction (sFunctionName) passing a parameter par (optional) at a specific moment. |
|
ExistsDefine |
bool |
string defineName |
Returns true if a define defineName exists. |
|
ExistsNode |
bool |
string nodeName |
Returns true if a node nodeName exists. |
|
GetDefine |
string |
string defineName |
Returns the define value corresponding to defineName, if one exists; otherwise, throws an exception. |
|
GetFieldValue |
type |
string fieldName |
Returns the value of the field node corresponding to fieldName, if one exists; otherwise, throws an exception. The fieldName string uses the syntax nodeName.fieldName. Return type depends on the field type. |
|
GetNode |
var |
string nodeName |
Returns the node corresponding to nodeName, if one exists; otherwise, throws an exception. |
|
Resolve |
string |
string value |
Resolves the string value using the engine internal resolve system used by XML script. |
|
SetFieldValue |
|
string fieldName, type value |
Sets the value of the field of a node corresponding to fieldname to value. If fieldName does not exist, it throws an exception. The fieldName string uses the syntax nodeName.fieldName. The type of value depends on the field type. It can be the same type or one that can be cast to that type. |