LuaLauncher.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEngine;
  2. using System;
  3. using System.Threading;
  4. using LuaInterface;
  5. using System.Collections;
  6. public class LuaLauncher : LuaClient
  7. {
  8. private volatile float precent;
  9. new void Awake()
  10. {
  11. base.Awake();
  12. }
  13. public override void Destroy()
  14. {
  15. StopAsync();
  16. base.Destroy();
  17. }
  18. protected override LuaFileUtils InitLoader()
  19. {
  20. return new LuaResLoader();
  21. }
  22. protected override void OnLoadFinished()
  23. {
  24. luaState.Start();
  25. StartMain();
  26. }
  27. protected override void CallMain()
  28. {
  29. StartLooper();
  30. LuaMgr.Instance.CallMain();
  31. }
  32. protected override void StartMain()
  33. {
  34. if (LaunchThread.HasInstance())
  35. {
  36. LaunchThread.Instance.Start(LaunchThread.AsyncLaunchState.LuaInit, LuaMgr.Instance.StartMain, CallMain, UpdateTimer);
  37. }
  38. }
  39. private void UpdateTimer()
  40. {
  41. EventMgr.DispatchEvent<bool, float>(new CoreEvent<bool, float>(ECoreEventType.EID_LOAD_LUA_OK, false, precent));
  42. }
  43. public void StartMainPrecent(float precent)
  44. {
  45. this.precent = precent;
  46. }
  47. public void StartMainComplete()
  48. {
  49. EventMgr.DispatchEvent<bool, float>(new CoreEvent<bool, float>(ECoreEventType.EID_LOAD_LUA_OK, true, 1));
  50. }
  51. public void StopAsync()
  52. {
  53. if (LaunchThread.HasInstance())
  54. {
  55. LaunchThread.Instance.Stop(LaunchThread.AsyncLaunchState.LuaInit);
  56. }
  57. }
  58. }