Advertisement
Guest User

Untitled

a guest
May 31st, 2011
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System;
  4.  
  5. public class Invoker : MonoBehaviour {
  6.    
  7.     Queue<Action> work;
  8.     public static Invoker ST;
  9.     public Invoker ()
  10.     {
  11.         work = new Queue<Action>();
  12.         ST = this;
  13.     }
  14.    
  15.     public void Add(Action a)
  16.     {
  17.         lock (work)
  18.         {
  19.             work.Enqueue(a);
  20.         }
  21.     }
  22.    
  23.    
  24.     void FixedUpdate()
  25.     {
  26.         if (work.Count > 0)
  27.         {
  28.             lock (work)
  29.             {
  30.                 foreach (var a in work)
  31.                 {
  32.                     a();
  33.                 }
  34.                 work.Clear();
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement