版本: Unity 6 (6000.0)
语言English
  • C#

ParticleSystem.TriggerModule.inside

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们确实会阅读用户提出的每个建议更改,并在适用时进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

切换到手册

描述

选择当粒子位于触发器体积内时要执行的操作。

系统在粒子位于触发器体积内的每一帧执行此操作。其他资源:MonoBehaviour.OnParticleTrigger

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine.EventSystems;

[RequireComponent(typeof(ParticleSystem))] public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public bool enter; public bool exit; public bool inside; public bool outside;

void Start() { ps = GetComponent<ParticleSystem>();

var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.parent = ps.transform; sphere.transform.localPosition = new Vector3(0.0f, 0.0f, 3.0f); sphere.transform.localScale = new Vector3(3.0f, 3.0f, 3.0f); sphere.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Particles/Standard Unlit"));

var shape = ps.shape; shape.enabled = false;

var trigger = ps.trigger; trigger.enabled = true; trigger.SetCollider(0, sphere.GetComponent<Collider>()); }

void Update() { var trigger = ps.trigger; trigger.enter = enter ? ParticleSystemOverlapAction.Callback : ParticleSystemOverlapAction.Ignore; trigger.exit = exit ? ParticleSystemOverlapAction.Callback : ParticleSystemOverlapAction.Ignore; trigger.inside = inside ? ParticleSystemOverlapAction.Callback : ParticleSystemOverlapAction.Ignore; trigger.outside = outside ? ParticleSystemOverlapAction.Callback : ParticleSystemOverlapAction.Ignore; }

void OnGUI() { enter = GUI.Toggle(new Rect(25, 40, 200, 30), enter, "Enter Callback"); exit = GUI.Toggle(new Rect(25, 80, 200, 30), exit, "Exit Callback"); inside = GUI.Toggle(new Rect(25, 120, 200, 30), inside, "Inside Callback"); outside = GUI.Toggle(new Rect(25, 160, 200, 30), outside, "Outside Callback"); }

void OnParticleTrigger() { if (enter) { List<ParticleSystem.Particle> enterList = new List<ParticleSystem.Particle>(); int numEnter = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enterList);

for (int i = 0; i < numEnter; i++) { ParticleSystem.Particle p = enterList[i]; p.startColor = new Color32(255, 0, 0, 255); enterList[i] = p; }

ps.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enterList); }

if (exit) { List<ParticleSystem.Particle> exitList = new List<ParticleSystem.Particle>(); int numExit = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Exit, exitList);

for (int i = 0; i < numExit; i++) { ParticleSystem.Particle p = exitList[i]; p.startColor = new Color32(0, 255, 0, 255); exitList[i] = p; }

ps.SetTriggerParticles(ParticleSystemTriggerEventType.Exit, exitList); }

if (inside) { List<ParticleSystem.Particle> insideList = new List<ParticleSystem.Particle>(); int numInside = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Inside, insideList);

for (int i = 0; i < numInside; i++) { ParticleSystem.Particle p = insideList[i]; p.startColor = new Color32(0, 0, 255, 255); insideList[i] = p; }

ps.SetTriggerParticles(ParticleSystemTriggerEventType.Inside, insideList); }

if (outside) { List<ParticleSystem.Particle> outsideList = new List<ParticleSystem.Particle>(); int numOutside = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Outside, outsideList);

for (int i = 0; i < numOutside; i++) { ParticleSystem.Particle p = outsideList[i]; p.startColor = new Color32(0, 255, 255, 255); outsideList[i] = p; }

ps.SetTriggerParticles(ParticleSystemTriggerEventType.Outside, outsideList); } } }