You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
4.5 KiB
116 lines
4.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace UnityEditor.VFX
|
|
{
|
|
class VFXSpawnerBurstVariantCollection : VariantProvider
|
|
{
|
|
public override IEnumerable<Variant> GetVariants()
|
|
{
|
|
foreach (var mode in Enum.GetValues(typeof(VFXSpawnerBurst.RepeatMode)).Cast<VFXSpawnerBurst.RepeatMode>())
|
|
{
|
|
yield return new Variant(
|
|
$"{mode} Burst",
|
|
"Spawn",
|
|
typeof(VFXSpawnerBurst),
|
|
new[] { new KeyValuePair<string, object>("repeat", mode) });
|
|
}
|
|
}
|
|
}
|
|
|
|
[VFXHelpURL("Block-Burst")]
|
|
[VFXInfo(variantProvider = typeof(VFXSpawnerBurstVariantCollection))]
|
|
class VFXSpawnerBurst : VFXAbstractSpawner
|
|
{
|
|
public enum RepeatMode
|
|
{
|
|
Single,
|
|
Periodic
|
|
}
|
|
|
|
public enum RandomMode
|
|
{
|
|
Constant,
|
|
Random,
|
|
}
|
|
|
|
|
|
[VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField]
|
|
private RepeatMode repeat = RepeatMode.Single;
|
|
|
|
[VFXSetting, SerializeField, Tooltip("Specifies whether a constant number of particles is spawned, or a random number within the chosen range.")]
|
|
private RandomMode spawnMode = RandomMode.Constant;
|
|
|
|
[VFXSetting, SerializeField, Tooltip("Specifies whether a constant delay is applied between bursts, or a random one within the chosen range.")]
|
|
private RandomMode delayMode = RandomMode.Constant;
|
|
|
|
public override string name { get { return repeat.ToString() + " Burst"; } }
|
|
public override VFXTaskType spawnerType { get { return repeat == RepeatMode.Periodic ? VFXTaskType.PeriodicBurstSpawner : VFXTaskType.BurstSpawner; } }
|
|
|
|
public class AdvancedInputProperties
|
|
{
|
|
[Tooltip("Sets the minimum and maximum number of particles to be spawned with each burst."), Min(0)]
|
|
public Vector2 Count = new Vector2(0, 10);
|
|
[Tooltip("Sets the minimum and maximum delay in seconds between each burst."), Min(0)]
|
|
public Vector2 Delay = new Vector2(0, 1);
|
|
}
|
|
|
|
public class SimpleInputProperties
|
|
{
|
|
[Tooltip("Sets the number of particles to be spawned with each burst."), Min(0)]
|
|
public float Count = 0.0f;
|
|
[Tooltip("Sets the delay in seconds between each burst."), Min(0)]
|
|
public float Delay = 0.0f;
|
|
}
|
|
|
|
protected override IEnumerable<VFXPropertyWithValue> inputProperties
|
|
{
|
|
get
|
|
{
|
|
var simple = PropertiesFromType("SimpleInputProperties");
|
|
var advanced = PropertiesFromType("AdvancedInputProperties");
|
|
|
|
if (spawnMode == RandomMode.Constant)
|
|
yield return simple.FirstOrDefault(o => o.property.name == "Count");
|
|
else
|
|
yield return advanced.FirstOrDefault(o => o.property.name == "Count");
|
|
|
|
if (delayMode == RandomMode.Constant)
|
|
yield return simple.FirstOrDefault(o => o.property.name == "Delay");
|
|
else
|
|
yield return advanced.FirstOrDefault(o => o.property.name == "Delay");
|
|
}
|
|
}
|
|
|
|
public override IEnumerable<VFXNamedExpression> parameters
|
|
{
|
|
get
|
|
{
|
|
// Get InputProperties
|
|
var namedExpressions = GetExpressionsFromSlots(this);
|
|
|
|
// Map Expressions based on Task Type (TODO: Fix names on C++ side)
|
|
string countName = repeat == RepeatMode.Periodic ? "nb" : "Count";
|
|
string delayName = repeat == RepeatMode.Periodic ? "period" : "Delay";
|
|
|
|
// Process Counts
|
|
var countExp = namedExpressions.First(e => e.name == "Count").exp;
|
|
|
|
if (spawnMode == RandomMode.Random)
|
|
yield return new VFXNamedExpression(countExp, countName);
|
|
else
|
|
yield return new VFXNamedExpression(new VFXExpressionCombine(countExp, countExp), countName);
|
|
|
|
// Process Delay
|
|
var delayExp = namedExpressions.First(e => e.name == "Delay").exp;
|
|
|
|
if (delayMode == RandomMode.Random)
|
|
yield return new VFXNamedExpression(delayExp, delayName);
|
|
else
|
|
yield return new VFXNamedExpression(new VFXExpressionCombine(delayExp, delayExp), delayName);
|
|
}
|
|
}
|
|
}
|
|
}
|