コード例 #1
0
    private IEnumerator LoadStaticAssets()
    {
        if (!LoadedStatic)
        {
            LoadedStatic = false;

            List <KeyValuePair <string, Run> > actions = new List <KeyValuePair <string, Run> >();
            actions.Add(new KeyValuePair <string, Run>("Loading Projectiles...", () => { ProjectileData.LoadProjectiles(); }));
            actions.Add(new KeyValuePair <string, Run>("Loading Effects...", () => { TempEffect.LoadAll(); }));
            actions.Add(new KeyValuePair <string, Run>("Loading Attachments...", () => { Attachment.Load(); }));
            actions.Add(new KeyValuePair <string, Run>("Registering Projectiles...", () => { Projectile.NetRegister(); }));
            actions.Add(new KeyValuePair <string, Run>("Registering Attachments...", () => { Attachment.NetRegister(); }));

            int total = actions.Count;

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            // Loop and execute...
            for (int i = 0; i < total; i++)
            {
                var pair = actions[i];
                // Execute...
                UI.Title      = pair.Key;
                UI.Percentage = i / total;
                yield return(null);

                watch.Restart();
                try
                {
                    pair.Value.Invoke();
                }
                catch (Exception e)
                {
                    Debug.LogError("Exception when loading on step #{0} - '{1}':\n{2}".Form(i, pair.Key, e));
                }
                watch.Stop();
                Debug.Log("'{0}' - Took {1} milliseconds.".Form(pair.Key, watch.ElapsedMilliseconds));
            }

            LoadedStatic = true;
            StartCoroutine(LoadScene());
        }
    }