This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资源工作流程
版本控制
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Unigine.Expression Class

This class allows you to execute a given code fragment at run-time. There can be up to 4 arguments of any type passed to the Expression. The setVariable() function sets values of such arguments. For example:

Source code (C#)
Expression e0 = new Expression(Engine.get().getWorldInterpreter(), "133.0 * 133.0");
if (e0.isCompiled() == 1)
{
    Log.Message("{0}\n", e0.run().getFloat());
}

Expression e1 = new Expression(Engine.get().getWorldInterpreter(), @"
	{
    int a,b,c,d;
    return a + b + c + d;
	}
");

e1.setVariable("a", new Variable(1));
e1.setVariable("b", new Variable(2));
e1.setVariable("c", new Variable(3));
e1.setVariable("d", new Variable(4));

if(e1.isCompiled() == 1) {
	Log.Message("{0}\n",e1.run().getInt());
}

Expression e2 = new Expression(Engine.get().getWorldInterpreter(), @"
	{

        string name;
		File file = new File(name," + "\"rb\"" + @");

		int size = file.getSize();
		file.close();
		delete file;
		return size;
	}
");

e2.setVariable("name", new Variable("test.cpp"));
if(e2.isCompiled() == 1) {
		Log.Message("{0}\n", e2.run().getInt());
}

Output
double: 17689
int: 10
int: 1302

Expression Class

Members


Expression ( IntPtr interpreter, string src, int scope = 0 ) #

Constructor. Creates the expression from the specified source buffer.

Arguments

  • IntPtr interpreter - Interpreter pointer.
  • string src - Source buffer. Source buffer is a string containing expression's source code.
  • int scope - 1 to treat the expression namespace as the global; otherwise, 0 (by default).

variable run ( ) #

Runs the given expression.

Return value

Argument value.

bool saveState ( Stream stream ) #

Saves the expression data (all its parameters) to the specified binary stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize an expression and set its state
//...//

// save state
Blob blob_state = new Blob();
expression1.SaveState(blob_state);

// change the node state
//...//

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
expression1.RestoreState(blob_state);

Arguments

  • Stream stream - Stream to which the expression data will be saved.

Return value

true if the expression data is saved successfully; otherwise, false.

bool restoreState ( Stream stream ) #

Restores the data of the expression (all its parameters) from the specified binary stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize an expression and set its state
//...//

// save state
Blob blob_state = new Blob();
expression1.SaveState(blob_state);

// change the node state
//...//

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
expression1.RestoreState(blob_state);

Arguments

  • Stream stream - Stream in which the saved expression data is stored.

Return value

true if the expression data is restored successfully; otherwise, false.
Last update: 2024-04-19
Build: ()