예제 #1
0
 // 异步更新
 private async void AsyncUpdate(TimeDownObject timeDownObject)
 {
     Task task = Task.Run(() =>
     {
         timeDownObject.Run();
     });
     await task;
 }
예제 #2
0
    //开启更新
    public void OnUpdate()
    {
        if (delayedObjects.ContainsKey(TimeDownType.UnityTimeLineImpact))
        {
            for (int i = 0; i < delayedObjects[TimeDownType.UnityTimeLineImpact].Count; i++)
            {
                TimeDownObject timeDownObject = delayedObjects[TimeDownType.UnityTimeLineImpact][i];
                if (timeDownObject.InTime(Time.deltaTime))
                {
                    timeDownObject.Run();
                }
            }
        }


        float timeDir = Time.realtimeSinceStartup - timeNow;

        if (delayedObjects.ContainsKey(TimeDownType.NoUnityTimeLineImpact))
        {
            for (int i = 0; i < delayedObjects[TimeDownType.NoUnityTimeLineImpact].Count; i++)
            {
                TimeDownObject timeDownObject = delayedObjects[TimeDownType.NoUnityTimeLineImpact][i];
                if (timeDownObject.InTime(timeDir))
                {
                    timeDownObject.Run();
                }
            }
        }
        timeNow = Time.realtimeSinceStartup;


        if (delayedObjects.ContainsKey(TimeDownType.Async))
        {
            for (int i = 0; i < delayedObjects[TimeDownType.Async].Count; i++)
            {
                TimeDownObject timeDownObject = delayedObjects[TimeDownType.Async][i];
                bool           b = timeDownObject.InTime(timeDir);
                if (b)
                {
                    AsyncUpdate(timeDownObject);
                }
            }
        }
        if (delayedObjects.ContainsKey(TimeDownType.Thread))
        {
            for (int i = 0; i < delayedObjects[TimeDownType.Thread].Count; i++)
            {
                TimeDownObject timeDownObject = delayedObjects[TimeDownType.Thread][i];
                if (timeDownObject.InTime(timeDir))
                {
                    ThreadUpdate(timeDownObject);
                }
            }
        }
    }
예제 #3
0
 // 线程更新
 private void ThreadUpdate(TimeDownObject timeDownObject)
 {
     thread = new Thread(new ThreadStart(() =>
     {
         Thread _thread = thread;
         timeDownObject.Run();
         threads.Remove(_thread);
     }));
     thread.Start();
     threads.Add(thread);
 }