最小值-最大值曲线的脚本接口。
最小值-最大值曲线描述的函数采用最小值和最大值之间的值,并基于 ParticleSystem.MinMaxCurve.mode 返回值。根据模式,可能返回随机值。
对于需要曲线的模式,返回值取决于在 ParticleSystem Inspector 中设计的一条或两条曲线,这些曲线可以计算得到介于 -n 与 n 之间的单个值,其中 n 是也在 Inspector 中设置的常量。请参阅 ParticleSystemCurveMode 以了解更多信息。
另请参阅:ParticleSystem。
using UnityEngine;
// This example shows setting a constant rate value. public class ConstantRateExample : MonoBehaviour { ParticleSystem myParticleSystem; ParticleSystem.EmissionModule emissionModule;
void Start() { // Get the system and the emission module. myParticleSystem = GetComponent<ParticleSystem>(); emissionModule = myParticleSystem.emission;
GetValue(); SetValue(); }
void GetValue() { print("The constant value is " + emissionModule.rateOverTime.constant); }
void SetValue() { emissionModule.rateOverTime = 10.0f; } }
using UnityEngine;
// This example shows using 2 constants to drive the rate. public class TwoConstantsRateExample : MonoBehaviour { ParticleSystem myParticleSystem; ParticleSystem.EmissionModule emissionModule;
void Start() { // Get the system and the emission module. myParticleSystem = GetComponent<ParticleSystem>(); emissionModule = myParticleSystem.emission;
GetValue(); SetValue(); }
void GetValue() { print(string.Format("The constant values are: min {0} max {1}.", emissionModule.rateOverTime.constantMin, emissionModule.rateOverTime.constantMax)); }
void SetValue() { emissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(0.0f, 10.0f); } }
using UnityEngine;
// This example shows using a curve to drive the rate. public class CurveRateExample : MonoBehaviour { ParticleSystem myParticleSystem; ParticleSystem.EmissionModule emissionModule;
// We can "scale" the curve with this value. It gets multiplied by the curve. public float scalar = 1.0f;
AnimationCurve ourCurve;
void Start() { // Get the system and the emission module. myParticleSystem = GetComponent<ParticleSystem>(); emissionModule = myParticleSystem.emission;
// A simple linear curve. ourCurve = new AnimationCurve(); ourCurve.AddKey(0.0f, 0.0f); ourCurve.AddKey(1.0f, 1.0f);
// Apply the curve. emissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(scalar, ourCurve);
// In 5 seconds we will modify the curve. Invoke("ModifyCurve", 5.0f); }
void ModifyCurve() { // Add a key to the current curve. ourCurve.AddKey(0.5f, 0.0f);
// Apply the changed curve. emissionModule.rate = new ParticleSystem.MinMaxCurve(scalar, ourCurve); } }
using UnityEngine;
// This example shows using 2 curves to drive the rate. public class TwoCurveRateExample : MonoBehaviour { ParticleSystem myParticleSystem; ParticleSystem.EmissionModule emissionModule;
AnimationCurve ourCurveMin; AnimationCurve ourCurveMax;
// We can "scale" the curves with this value. It gets multiplied by the curves. public float scalar = 1.0f;
void Start() { // Get the system and the emission module. myParticleSystem = GetComponent<ParticleSystem>(); emissionModule = myParticleSystem.emission;
// A horizontal straight line at value 1. ourCurveMin = new AnimationCurve(); ourCurveMin.AddKey(0.0f, 1.0f); ourCurveMin.AddKey(1.0f, 1.0f);
// A horizontal straight line at value 0.5. ourCurveMax = new AnimationCurve(); ourCurveMax.AddKey(0.0f, 0.5f); ourCurveMax.AddKey(1.0f, 0.5f);
// Apply the curves. emissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(scalar, ourCurveMin, ourCurveMax);
// In 5 seconds we will modify the curve. Invoke("ModifyCurve", 5.0f); }
void ModifyCurve() { // Create a "pinch" point. ourCurveMin.AddKey(0.5f, 0.7f); ourCurveMax.AddKey(0.5f, 0.6f);
// Apply the changed curve. emissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(scalar, ourCurveMin, ourCurveMax); } }
using UnityEngine;
// This example shows how to retrieve existing keys from a MinMaxCurve public class ReadCurveExample : MonoBehaviour { void Start() { // Get the system and the emission module. var myParticleSystem = GetComponent<ParticleSystem>(); var emissionModule = myParticleSystem.emission;
// Get the curve (assuming the MinMaxCurve is in Curve mode) AnimationCurve curve = emissionModule.rateOverTime.curve;
// Get the keys Keyframe[] keys = curve.keys; } }
constant | 设置常量值。 |
constantMax | 为上限设置常量。 |
constantMin | 为下限设置常量。 |
curve | 设置曲线。 |
curveMax | 为上限设置曲线。 |
curveMin | 为下限设置曲线。 |
curveMultiplier | 设置要应用于曲线的乘数。 |
mode | 设置模式,最小值-最大值曲线使用该模式计算值。 |
ParticleSystem.MinMaxCurve | 用于整个曲线的单个常量值。 |
Evaluate | 手动查询曲线以基于所处模式计算值。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.