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创建。这些建议不适用于早期版本。


该视频显示了如何在UNIGINE中使用物理触发器。 物理触发器 (Physical 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 Physical : Component
{
	vec4 color;

	void enter_event_handler(Body body)
	{
		// Remember the material's color and set it to black
		color = body.Object.GetMaterialInherit(0).GetParameterFloat4("albedo_color");
		body.Object.GetMaterialInherit(0).SetParameterFloat4("albedo_color", vec4.BLACK);
	}

	void leave_event_handler(Body body)
	{
		// Restore the previous material's color
		body.Object.GetMaterialInherit(0).SetParameterFloat4("albedo_color", color);
	}

	PhysicalTrigger physicalTrigger;
	void Init()
	{
		// Cast Node to PhysicalTrigger
		physicalTrigger = node as PhysicalTrigger;

		if(physicalTrigger){
			// Subscribe for Enter and Leave events to perform actions 
			// when a body enters or leaves the trigger
			physicalTrigger.EventEnter.Connect(enter_event_handler);
			physicalTrigger.EventLeave.Connect(leave_event_handler);
		}
		
	}
	
	void Update()
	{
		// Render the trigger's volume
		Visualizer.RenderNodeBoundSphere(node, vec4.BLUE);
		
	}
}

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

源代码 (C#)
// Enable Visualizer
Visualizer.Enabled = true;
最新更新: 2025-03-04
Build: ()