Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill out ParticleSystem a little #38

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 66 additions & 8 deletions code/GameEngine/Components/Effects/ParticleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,31 @@
public class ParticleSystem : BaseComponent, BaseComponent.ExecuteInEditor
{
Sandbox.ParticleSystem _particles;

[Property] public bool Looped { get; set; } = false;

[Range( 0, 2.0f )]
[Property] public float PlaybackSpeed { get; set; } = 1.0f;

private bool _emission = true;

/// <summary>
/// Turn on or off particle emission.
/// Useful for particles with intermittent or permanent durations.
/// </summary>
[Property]
public bool Emission
{
get => _emission;
set
{
_emission = value;

if (_sceneObject is not null)
_sceneObject.EmissionStopped = !value;
}
}

[Property] public Sandbox.ParticleSystem Particles
{
get => _particles;
Expand All @@ -26,9 +45,9 @@ [Property] public Sandbox.ParticleSystem Particles
}
}

[Property] public GameObject ControlPoint0 { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do this, it'll break everything that currently uses it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's not ideal but if there was ever a time to break it it'd be now. This feels like something that'd be potentially confusing for newer users later down the line if it isn't changed.

[Property] public GameObject ControlPoint1 { get; set; }
[Property] public GameObject ControlPoint2 { get; set; }
[Property] public GameObject ControlPoint3 { get; set; }

SceneParticles _sceneObject;
public SceneParticles SceneObject => _sceneObject;
Expand Down Expand Up @@ -60,6 +79,45 @@ void RecreateSceneObject()

_sceneObject = new SceneParticles( Scene.SceneWorld, _particles );
_sceneObject.Transform = Transform.World;
_sceneObject.EmissionStopped = !_emission;
}

public void PlayEffect()
{
RecreateSceneObject();
}

public void Set( int i, float value )
{
_sceneObject?.SetControlPoint( i, value );
}

public void Set( int i, Vector3 position )
{
_sceneObject?.SetControlPoint( i, position );
}

public void Set( int i, Transform transform )
{
_sceneObject?.SetControlPoint( i, transform );
}

public void Set( int i, Rotation rotation )
{
_sceneObject?.SetControlPoint( i, rotation );
}

public Vector3 GetControlPointPosition( int i )
{
if ( !_sceneObject.IsValid() )
return Vector3.Zero;

return _sceneObject.GetControlPointPosition( i );
}

public void Set( string name, Vector3 position )
{
_sceneObject?.SetNamedValue( name, position );
}

public override void Update()
Expand All @@ -74,13 +132,13 @@ public override void Update()
if ( !_sceneObject.IsValid() )
return;
}

_sceneObject.SetControlPoint( 0, ControlPoint1.IsValid() ? ControlPoint1.Transform.World : Transform.World );
_sceneObject.SetControlPoint( 1, ControlPoint2.IsValid() ? ControlPoint2.Transform.World : Transform.World );
_sceneObject.SetControlPoint( 2, ControlPoint3.IsValid() ? ControlPoint3.Transform.World : Transform.World );

_sceneObject.SetControlPoint( 0, ControlPoint0.IsValid() ? ControlPoint0.Transform.World : Transform.World );
_sceneObject.SetControlPoint( 1, ControlPoint1.IsValid() ? ControlPoint1.Transform.World : Transform.World );
_sceneObject.SetControlPoint( 2, ControlPoint2.IsValid() ? ControlPoint2.Transform.World : Transform.World );
_sceneObject.Simulate( Time.Delta * PlaybackSpeed );

if ( _sceneObject.Finished )
{
_sceneObject?.Delete();
Expand Down