Ejemplo n.º 1
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }

        DontDestroyOnLoad(gameObject);

        queue = new InitQueue(() =>
        {
            //On complete
            for (int i = 0; i < callbacks.Count; i++)
            {
                callbacks[i]();
            }
            callbacks = null;
        });

        for (int i = 0; i < persistentObjects.Count; i++)
        {
            if (persistentObjects[i] == null)
            {
                continue;
            }

            IPersistent manager = persistentObjects[i] as IPersistent;
            if (manager != null)
            {
                persistentObjects[i] = manager.DuplicationBehavior();
                manager = persistentObjects[i] as IPersistent;

                //Init
                manager.Init(queue.Register());
            }
        }
        queue.MarkEnd();
    }
Ejemplo n.º 2
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }

        DontDestroyOnLoad(gameObject);

        queue = new InitQueue(() =>
        {
            //On complete
            for (int i = 0; i < callbacks.Count; i++)
            {
                callbacks[i]();
            }
            callbacks = null;
        });

        for (int i = 0; i < persistentObjects.Count; i++)
        {
            if (persistentObjects[i] == null)
            {
                continue;
            }

            IPersistent manager = persistentObjects[i] as IPersistent;
            if (manager != null)
            {
                string name = persistentObjects[i].name;
                pendingObjects.Add(name);

                persistentObjects[i] = manager.DuplicationBehavior();
                manager = persistentObjects[i] as IPersistent;

                Action registeration = queue.Register();

                //Init
                manager.Init(() =>
                {
                    pendingObjects.Remove(name);
                    registeration();
                });
            }
        }
        queue.MarkEnd();

        this.DelayedCall(() =>
        {
            if (!queue.IsOver)
            {
                Debug.Log("A manager is taking an abnormally long time to initialize.");
                for (int i = 0; i < pendingObjects.Count; i++)
                {
                    Debug.Log(pendingObjects[i] + " has not called 'onComplete' yet.");
                }
            }
        }, 2);
    }