Skip to main content
deleted 9 characters in body
Source Link
BCdotWEB
  • 11.4k
  • 2
  • 28
  • 45

In my loading scene I want to run multiple functions (IO from the disk) and start the app after they are completed.

This is in my loading class. (Note: This is unity 3d and the public variables to get access to other objects is based on Unity best practices).

public Logger MyLogger;
public Parser MyParser;
// ... more

private int coroutineCount = 0;

void Start()
{
    MyLogger.LogLastMonth(Callback);
    coroutineCount++;

    MyParser.ParseFiles(Callback);
    coroutineCount++;
}

public void Callback()
{
    coroutineCount--;

    if (coroutineCount <= 0)
    {
        SceneManager.LoadScene("GameScene");
    }
}

I do something similar in both Logger and Parser (counting coroutines and decrementing when they finish before invoking the callback received). Is there a better way to do this when I need to expand the number of functions I'm calling?

Thanks!

In my loading scene I want to run multiple functions (IO from the disk) and start the app after they are completed.

This is in my loading class. (Note: This is unity 3d and the public variables to get access to other objects is based on Unity best practices).

public Logger MyLogger;
public Parser MyParser;
// ... more

private int coroutineCount = 0;

void Start()
{
    MyLogger.LogLastMonth(Callback);
    coroutineCount++;

    MyParser.ParseFiles(Callback);
    coroutineCount++;
}

public void Callback()
{
    coroutineCount--;

    if (coroutineCount <= 0)
    {
        SceneManager.LoadScene("GameScene");
    }
}

I do something similar in both Logger and Parser (counting coroutines and decrementing when they finish before invoking the callback received). Is there a better way to do this when I need to expand the number of functions I'm calling?

Thanks!

In my loading scene I want to run multiple functions (IO from the disk) and start the app after they are completed.

This is in my loading class. (Note: This is unity 3d and the public variables to get access to other objects is based on Unity best practices).

public Logger MyLogger;
public Parser MyParser;
// ... more

private int coroutineCount = 0;

void Start()
{
    MyLogger.LogLastMonth(Callback);
    coroutineCount++;

    MyParser.ParseFiles(Callback);
    coroutineCount++;
}

public void Callback()
{
    coroutineCount--;

    if (coroutineCount <= 0)
    {
        SceneManager.LoadScene("GameScene");
    }
}

I do something similar in both Logger and Parser (counting coroutines and decrementing when they finish before invoking the callback received). Is there a better way to do this when I need to expand the number of functions I'm calling?

Source Link

Wait for multiple functions to run

In my loading scene I want to run multiple functions (IO from the disk) and start the app after they are completed.

This is in my loading class. (Note: This is unity 3d and the public variables to get access to other objects is based on Unity best practices).

public Logger MyLogger;
public Parser MyParser;
// ... more

private int coroutineCount = 0;

void Start()
{
    MyLogger.LogLastMonth(Callback);
    coroutineCount++;

    MyParser.ParseFiles(Callback);
    coroutineCount++;
}

public void Callback()
{
    coroutineCount--;

    if (coroutineCount <= 0)
    {
        SceneManager.LoadScene("GameScene");
    }
}

I do something similar in both Logger and Parser (counting coroutines and decrementing when they finish before invoking the callback received). Is there a better way to do this when I need to expand the number of functions I'm calling?

Thanks!