NetGlobal.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. using System.Threading;
  6. using CScript.Utilities;
  7. namespace CScript.Net
  8. {
  9. public class NetGlobal : Singleton<NetGlobal>
  10. {
  11. public List<Action> list_action = new List<Action>();
  12. private List<Action> list_actiondream = new List<Action>();
  13. private Mutex mutex_actionList = new Mutex();
  14. public string serverIP;
  15. public int udpSendPort;
  16. public int userUid;
  17. public void AddAction(Action _action)
  18. {
  19. //Debug.Log("AddAction");
  20. mutex_actionList.WaitOne();
  21. list_action.Add(_action);
  22. mutex_actionList.ReleaseMutex();
  23. }
  24. public void AddActionDream(Action _action)
  25. {
  26. mutex_actionList.WaitOne();
  27. list_actiondream.Add(_action);
  28. Debug.Log("Action Dream "+ list_actiondream.Count);
  29. mutex_actionList.ReleaseMutex();
  30. }
  31. public void DoForAction()
  32. {
  33. mutex_actionList.WaitOne();
  34. for (int i = 0; i < list_action.Count; i++)
  35. {
  36. list_action[i]();
  37. }
  38. //for (int i = 0; i < 1; i++)
  39. //{
  40. // list_actiondream[i]();
  41. //}
  42. // list_actiondream.Clear();
  43. list_action.Clear();
  44. mutex_actionList.ReleaseMutex();
  45. }
  46. }
  47. }