Giter VIP home page Giter VIP logo

Comments (9)

R1nge avatar R1nge commented on May 27, 2024

Is it a good practice to do inject like that?

public class ShootingProvider : MonoProvider<ShootingComponent>
{
    [Inject] private BulletFactory _bulletFactory;

    protected override void Initialize()
    {
        Entity.GetComponent<ShootingComponent>().BulletFactory = _bulletFactory;
    }
}


public struct ShootingComponent : IComponent
{
    public BulletFactory BulletFactory;
}

from morpeh.

olegmrzv avatar olegmrzv commented on May 27, 2024

I think it’s worth leaving example until Morpeh version 2024.1 comes out.
What about injections, I recommend doing them inside systems, not providers.
Instead of Entity.GetComponent() you should use ref GetData() when you want to get provider component.

from morpeh.

R1nge avatar R1nge commented on May 27, 2024

Thanks for the explanation.
When will 2024.1 come out?

from morpeh.

olegmrzv avatar olegmrzv commented on May 27, 2024

No specific dates yet. I would potentially like to greatly rework the internal part of the framework, maybe it will even be 2025.1
We need deeper support for Burst/Jobs in the core, and this may lead to the abandonment of reference Entity and so on.
In fact, the current version has almost exhausted the limit of algorithmic optimizations that are available when using reference Entity and it all depends on what code generates IL2CPP.
At the same time, our games require performance increases, including at the kernel level of Morpeh, because we have a huge code base and each saved instruction is multiplied by tens, hundreds and thousands.
That’s why I’m still thinking about how to improve the current situation without breaking backward compatibility too much.

Let's not look that far yet, for now we need to finish 2023.1.1

from morpeh.

R1nge avatar R1nge commented on May 27, 2024

Well, that's a lot to cover.
Definitely will be waiting for it.
And would create another sample if I have time)
But for now, will continue working on a sample for the current version.
Don't close this issue please.
Will close when it's done.

from morpeh.

R1nge avatar R1nge commented on May 27, 2024

Almost finished the core of the game.
it was really fun and I got a couple of new questions.

In one of previous replies you mentioned that it's possible to get data from a provider, so the data should be in IComponent, and all Unity stuff should go into provider, am I correct?

How to inject into systems?
I don't remember if Zenject can inject into scriptables, but VContainer definitely can't.
So, I had to create my own version of installer and inject like this:

My_ecs_installer.cs is an inheritor of Installer

[SerializeField] private OnDamageGameOverSystem onDamageGameOverSystem;
[Inject] private GameStateMachine _gameStateMachine; 

 private void Start()
 {
     onDamageGameOverSystem.Inject(_gameStateMachine);
 }

onDamageGameOverSystem.cs

private GameStateMachine _gameStateMachine;
public void Inject(GameStateMachine gameStateMachine) => _gameStateMachine = gameStateMachine; 

from morpeh.

R1nge avatar R1nge commented on May 27, 2024

It's done,
I wanted to add some fancy graphics, SFX, etc.
But it would be a game, not an example.
Will create a pull request after your answers to my previous questions.

Untitled

from morpeh.

olegmrzv avatar olegmrzv commented on May 27, 2024

It is better to create an InjectableInstaller into which the entire container is injected, and through the container the injection is called for systems (all or specific ones)

from morpeh.

R1nge avatar R1nge commented on May 27, 2024

It's definitely a smarter solution than mine.
Just implemented and it looks much better.
Thanks for your time and help.

from morpeh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.