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

ParticleSystemRenderer.sortMode

提出建议

成功!

感谢您帮助提高 Unity 文档质量。虽然我们无法接受所有提交的建议,但我们会阅读用户提出的每项建议并在相关位置进行更新。

关闭

提交失败

由于某种原因,我们无法提交您的建议。请在几分钟后<a>重试</a>。感谢您抽出时间帮助我们改善 Unity 文档质量。

关闭

取消

public ParticleSystemSortMode sortMode;

描述

指定在一个系统中对粒子的排序方式。

using UnityEngine;
using UnityEditor;
using System.Collections;

[RequireComponent(typeof(ParticleSystem))] public class ExampleClass : MonoBehaviour {

private ParticleSystem ps; private ParticleSystemRenderer psr; public ParticleSystemSortMode sortMode;

void Start() {

ps = GetComponent<ParticleSystem>(); psr = GetComponent<ParticleSystemRenderer>();

// set a slow start speed and high emission rate, to cause more overlap, to show sorting var main = ps.main; main.startSpeedMultiplier = 0.2f; var emission = ps.emission; emission.rateOverTimeMultiplier = 100.0f;

// set color over life, so we can see the sorting more easily var colorOverLifetime = ps.colorOverLifetime; colorOverLifetime.enabled = true;

Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) } );

colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient); }

void Update() {

psr.sortMode = sortMode; }

void OnGUI() {

sortMode = (ParticleSystemSortMode)GUI.SelectionGrid(new Rect(25, 25, 900, 30), (int)sortMode, new GUIContent[] { new GUIContent("None"), new GUIContent("Distance"), new GUIContent("OldestInFront"), new GUIContent("YoungestInFront"), new GUIContent("Depth"), new GUIContent("DistanceReverse"), new GUIContent("DepthReverse") }, 7); } }