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

[FEATURE] RentWithState #19

Open
mackysoft opened this issue Feb 23, 2022 · 1 comment
Open

[FEATURE] RentWithState #19

mackysoft opened this issue Feb 23, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mackysoft
Copy link
Owner

mackysoft commented Feb 23, 2022

Before

public struct ProjectileRequest {
    public int power;
    public float speed;
}

public void Shoot (ProjectileRequest request) {
    var projectile = m_ProjectilePool.Rent(position,rotation);
    projectile.Power = request.power;
    projectile.Speed = request.speed;
}

After

public class ProjectilePool : PoolWithStateBase<Projectile,ProjectileRequest> {
    protected override void OnRent (Projectile instance,ProjectileRequest state) {
        instance.Power = state.power;
        instance.Speed = state.speed;
    }
}

public void Shoot (ProjectileRequest request) {
    var projectile = m_ProjectilePool.Rent(request,position,rotation);
}
@mackysoft mackysoft self-assigned this Feb 23, 2022
@mackysoft mackysoft added the enhancement New feature or request label Feb 23, 2022
@mackysoft
Copy link
Owner Author

  • Basically, pool is not public and is used internally.
  • Methods such as Shoot use Rent internally.
  • Methods such as Shoot may have multiple arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant