Exemple #1
0
 internal void Dispatch(DispatchItem dispatchItem)
 {
     if (CanDispatch(dispatchItem))
     {
         dispatchItem.Player.Move(dispatchItem.DispatchDestination);
         player.ActionCounter.UseAction(dispatchItem.Cost);
     }
 }
Exemple #2
0
 private void pushItem(DispatchItem item)
 {
     item.Callback      = null;
     item.ParamCallback = null;
     item.TransParam1   = null;
     item.CanvasParam1  = null;
     item.GraphicParam1 = null;
     dispatchItemPool.Add(item);
 }
Exemple #3
0
 private DispatchItem popItem()
 {
     if (dispatchItemPool.Count > 0)
     {
         DispatchItem item = dispatchItemPool [0];
         dispatchItemPool.RemoveAt(0);
         return(item);
     }
     return(new DispatchItem());
 }
 public void Dispatch(Action action)
 {
     try
     {
         var workitem = new DispatchItem(action);
         _TaskQueue.Enqueue(workitem);
     }
     catch (Exception)
     {
         // ignored
     }
 }
Exemple #5
0
 public void Finish(object key)
 {
     for (int i = 0; i < dispatchItems.Count; i++)
     {
         DispatchItem item = dispatchItems [i];
         if (item != null && item.Key == key)
         {
             dispatchItems.RemoveAt(i--);
             item.Callback(1f);
             pushItem(item);
         }
     }
 }
Exemple #6
0
 public void Clear(object key)
 {
     for (int i = 0; i < dispatchItems.Count; i++)
     {
         DispatchItem item = dispatchItems [i];
         if (item != null && item.Key == key)
         {
             Debug.LogError("clear success" + key);
             dispatchItems.RemoveAt(i--);
             pushItem(item);
         }
     }
 }
 public void BeginInvoke(Action a)
 {
     if (mode == DispatcherMode.AppDispatcher)
     {
         Application.Current.Dispatcher.BeginInvoke(a);
     }
     else if (mode == DispatcherMode.CustomDispatcher)
     {
         var i = new DispatchItem {
             Action = a
         };
         queue.Enqueue(i);
     }
 }
Exemple #8
0
 // Update is called once per frame
 void Update()
 {
     if (dispatchItems.Count > 0)
     {
         for (int i = 0; i < dispatchItems.Count; i++)
         {
             DispatchItem item = dispatchItems[i];
             if (item.Delay > 0)
             {
                 item.Delay -= Time.deltaTime;
             }
             else
             {
                 item.Time     -= Time.deltaTime;
                 item.ValueSrc += item.ValueChangeSpd * Time.deltaTime;
                 if (item.Time < 0)
                 {
                     if (item.Callback != null)
                     {
                         item.Callback(item.ValueDst);
                     }
                     if (item.ParamCallback != null)
                     {
                         item.ParamCallback(item.ValueDst, item);
                     }
                     if (dispatchItems.Count > i)
                     {
                         dispatchItems.RemoveAt(i--);
                     }
                     pushItem(item);
                 }
                 else
                 {
                     if (!item.Once)
                     {
                         if (item.Callback != null)
                         {
                             item.Callback(item.ValueSrc);
                         }
                         if (item.ParamCallback != null)
                         {
                             item.ParamCallback(item.ValueSrc, item);
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #9
0
    public void Run(float from, float to, float duration, AniamtionSchedulerValueDelegate cb, object key = null, float delay = 0)
    {
        DispatchItem item = popItem();

        item.Time           = duration;
        item.ValueSrc       = from;
        item.ValueDst       = to;
        item.ValueChangeSpd = (to - from) / duration;
        item.Callback       = cb;
        item.ParamCallback  = null;
        item.Key            = key;
        item.Once           = false;
        item.Delay          = delay;
        dispatchItems.Add(item);
    }
Exemple #10
0
    public void RunAfter(AniamtionSchedulerValueDelegate cb, float delay = 0f, object key = null)
    {
        DispatchItem item = popItem();

        item.Time           = delay;
        item.ValueSrc       = 1;
        item.ValueDst       = 1;
        item.ValueChangeSpd = 1;
        item.Callback       = cb;
        item.ParamCallback  = null;
        item.Once           = true;
        item.Key            = key;
        item.Delay          = 0;
        dispatchItems.Add(item);
    }
 public void Invoke(Action a)
 {
     if (mode == DispatcherMode.AppDispatcher)
     {
         Application.Current.Dispatcher.Invoke(a);
     }
     else if (mode == DispatcherMode.CustomDispatcher)
     {
         var i = new DispatchItem {
             Action = a
         };
         queue.Enqueue(i);
         while (!i.Executed)
         {
             Thread.Sleep(0);
         }
     }
 }
Exemple #12
0
 internal bool CanDispatch(DispatchItem dispatchItem)
 {
     return(dispatchItem != null);
 }