GithubHelp home page GithubHelp logo

Comments (3)

vovgou avatar vovgou commented on July 24, 2024

Hi,IServiceBundle cannot solve your needs, it is just a service container similar to IoC/DI.
You can use Addressable Asset System or Loxodon.Framework.Bundle to load assets asynchronously.

Can you speak Chinese? If you have QQ, please add my QQ group 622321589

from loxodon-framework.

heshuimu avatar heshuimu commented on July 24, 2024

Hi,IServiceBundle cannot solve your needs, it is just a service container similar to IoC/DI.

I think I am now aware of that. But, it seems to me that I can make a service bundle class that does not implement the interface and can still properly set up and tear down services. My sense is that I would not lose any extra functionalities if I don't implement the interface, but I wanted to confirm.

Here's what I ended up with:

using UnityEngine;
using Loxodon.Framework.Services;
using Loxodon.Framework.Asynchronous;

#nullable enable

// Does not implement IServiceBundle
public class GameDriverServiceBundle
{
	private readonly IServiceContainer serviceContainer;

	public GameDriverServiceBundle(IServiceContainer serviceContainer)
	{
		this.serviceContainer = serviceContainer;
	}

	public async Task Start()
	{
		GameObject? original = await LoadAsync<GameObject>("GameDriverSupportingComponents");
		GameObject newInstance = Object.Instantiate(original!);

		// Set up example:
		serviceContainer.Register("GameCamera", newInstance.GetComponentInChildren<Camera>());
	}

	public void Stop()
	{
		// Tear down
		serviceContainer.Unregister("GameCamera");
	}

	private static async Task<T?> LoadAsync<T>(string path) where T : Object
	{
		return await Resources.LoadAsync<T>(path) as T;
	}
}

from loxodon-framework.

vovgou avatar vovgou commented on July 24, 2024

Yes, you are right.

But please do not store GameObject in ServiceContainer, it is an IoC container, storing business logic services or basic components in the container, such as network components, role backpack services, etc.

Maybe you can store your game object in PlayerContext or ApplicationContext.

from loxodon-framework.

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.