浏览代码

Add feature controlling number of landing particles based on fall distance

/main
David Henshaw 4 年前
当前提交
61abd62c
共有 2 个文件被更改,包括 50 次插入1 次删除
  1. 18
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/PlayLandParticlesActionSO.cs
  2. 33
      UOP1_Project/Assets/Scripts/Effects/DustParticlesController.cs

18
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/PlayLandParticlesActionSO.cs


{
//Component references
private DustParticlesController _dustController;
private Transform _transform;
private float _fallStartY = 0;
private float _fallEndY = 0;
private float _maxFallDistance = 4; //Used to adjust particle emission intensity
_transform = stateMachine.transform;
}
public override void OnStateEnter()
{
_fallStartY = _transform.position.y;
_fallEndY = _transform.position.y;
float dY = _fallStartY - _fallEndY;
float fallIntensity = Mathf.InverseLerp(0, _maxFallDistance, dY);
_dustController.PlayLandParticles();
//_dustController.PlayLandParticles();
_dustController.PlayLandParticles(fallIntensity);
t = Time.time;
}
}

33
UOP1_Project/Assets/Scripts/Effects/DustParticlesController.cs


{
_landParticles.Play();
}
public void PlayLandParticles(float intensity)
{
// make sure intensity is always between 0 and 1
intensity = Mathf.Clamp01(intensity);
var main = _landParticles.main;
var origCurve = main.startSize; //save original curve to be assigned back to particle system
ParticleSystem.MinMaxCurve newCurve = main.startSize; //Make a new minMax curve and make our changes to the new copy
float minSize = newCurve.constantMin;
float maxSize = newCurve.constantMax;
// use the intensity to change the maximum size of the particle curve
newCurve.constantMax = Mathf.Lerp(minSize, maxSize, intensity);
main.startSize = newCurve;
_landParticles.Play();
// Put the original startSize back where you found it
StartCoroutine(ResetMinMaxCurve(_landParticles, origCurve));
}
private IEnumerator ResetMinMaxCurve(ParticleSystem ps, ParticleSystem.MinMaxCurve curve)
{
while (ps.isEmitting)
{
yield return null;
}
var main = ps.main;
main.startSize = curve;
}
}
正在加载...
取消
保存