This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口(API)参考
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

视频教程: 如何使用节点触发器来检测节点状态的变化

注意
每个视频都有英文,俄文和中文字幕。
警告
本教程使用SDK版本2.18创建。这些建议不适用于早期版本。


该视频介绍了如何使用节点触发器来检测节点状态的变化。节点触发器 (Node Trigger) 是没有视觉表示的节点。启用/禁用此节点或更改其转换时,将启用回调。

为了方便您使用,本视频中展示的组件代码如下:

Trigger.cs
using System.Collections;
using System.Collections.Generic;
using Unigine;

[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class Trigger : Component
{
	public AssetLink explosion;

	void position_event_handler(NodeTrigger trigger)
	{
		Log.Message("Object position has been changed. New position is: {0}\n\n", trigger.WorldPosition.ToString());
	}


	void enabled_event_handler(NodeTrigger trigger)
	{
		SoundSource soundSource = new SoundSource(explosion.Path);
		soundSource.WorldPosition = trigger.WorldPosition;
		soundSource.MaxDistance = 100.0f;
		soundSource.Play();
	}

	NodeTrigger nodeTrigger;
	void Init()
	{
		// Cast Node to NodeTrigger
		nodeTrigger = node as NodeTrigger;

		if(nodeTrigger){
			// Subscribe for Enabled and Position events to perform actions 
			// when a node is enabled/disabled or changes its position
			nodeTrigger.EventEnabled.Connect(enabled_event_handler);
			nodeTrigger.EventPosition.Connect(position_event_handler);
		}
	}
	
	void Update()
	{
		// Disable the parent object when it is below the plane z = 2.0f
		if(node.Parent.WorldPosition.z < 2.0f)
			node.Parent.Enabled = false;
		
	}
}

要启用可视化工具并显示控制台消息,请在AppWorldLogic.cpp或任何合适的组件中的Init()方法中添加以下代码:

源代码 (C#)
// Enable Visualizer
Visualizer.Enabled = true;

// Display console messages on the screen
Unigine.Console.Onscreen = true;
最新更新: 2025-03-04
Build: ()