Skip to content

Conversation

@tanitaka-tech
Copy link

@tanitaka-tech tanitaka-tech commented Nov 11, 2023

Pin.LoadScene can be used to Bind the type to the scene to be loaded.

InjectOptional allows null to be injected without throwing an exception if the interface is not Bind.

Usage Example

The main use case is to pass initial values to the Scene.
However, when initial values are received in Inject, an error occurs if the initial values are not assigned, making it impossible to check the Scene alone from the Editor.
InjectOptional is used in such cases.
If the initial value is not Bind, the initial value for testing can be passed, and thus can be checked by Scene alone.

   public class SceneLoader : MonoBehaviour,
        IHogeSceneLoader
    {
        [SerializeField] private string _sceneName;

        async UniTask IHogeSceneLoader.LoadSceneAsync(HogeSceneConfig config, CancellationToken cancellationToken)
        {
            await Pin.LoadSceneAsync(_sceneName, LoadSceneMode.Additive, (binder) => binder.Bind(config))
                .ToUniTask(cancellationToken: cancellationToken);
        }
    }
public class HogeSceneInstaller : MonoBehaviour, IInjectionContext
{  
    [InjectOptional] private HogeSceneConfig _config;  
  
    void IInjectionContext.Configure(DependencyBinder binder)  
    {       
         _config ??= new HogeSceneConfig("TestValue");
        ... 
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant