Version: 2021.3

MonoBehaviour.OnParticleUpdateJobScheduled()

切换到手册

描述

调度粒子系统的内置更新作业时,会调用 OnParticleUpdateJobScheduled。

这可以用于附加自定义托管作业,以便在默认粒子更新之后运行。

using UnityEngine;
using UnityEngine.ParticleSystemJobs;

public class JobScript : MonoBehaviour { void OnParticleUpdateJobScheduled() { ParticleSystem ps = GetComponent<ParticleSystem>(); new UpdateParticlesJob { m_DeltaTime = Time.deltaTime }.Schedule(ps); }

struct UpdateParticlesJob : IJobParticleSystem { public float m_DeltaTime;

public void Execute(ParticleSystemJobData particles) { var positionsY = particles.positions.x;

for (int i = 0; i < particles.count; i++) { positionsY[i] += 3.0f * m_DeltaTime; } } } }

要检索 ParticleSystem 造成的所有碰撞的详细信息,必须使用 ParticlePhysicsExtensions.GetTriggerParticles 检索 Particle 的数组。