GObjectFromPackageAsync.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using FairyGUI;
  2. using XGame.Framework.Asyncs;
  3. namespace XGame.Framework.FGUI
  4. {
  5. public class GObjectFromPackageAsync : Async, IGObjectLoadAsync
  6. {
  7. private bool _isRemoveAll;
  8. public string PackageName { get; private set; }
  9. public string ObjectName { get; private set; }
  10. public GObject Result { get; private set; }
  11. public GObjectFromPackageAsync(string pkgName, string objName)
  12. {
  13. PackageName = pkgName;
  14. ObjectName = objName;
  15. _isRemoveAll = false;
  16. }
  17. protected override void OnRemoveAll()
  18. {
  19. _isRemoveAll = true;
  20. Result = null;
  21. }
  22. public void Start()
  23. {
  24. if (UIPackage.GetByName(PackageName) == null)
  25. {
  26. Log.Error($"UIViewLoadFromPackageAsync.Start UIPackage is null. Paqckage:{PackageName} Object:{ObjectName}");
  27. Completed();
  28. return;
  29. }
  30. UIPackage.CreateObjectAsync(PackageName, ObjectName, (GObject result) =>
  31. {
  32. if (result == null)
  33. {
  34. Log.Error($"UIPackage.CreateObjectAsync result is null. Paqckage:{PackageName} Object:{ObjectName}");
  35. }
  36. else if (_isRemoveAll)
  37. {
  38. // 该异步已结束
  39. Log.Info($"UIPackage.CreateObjectAsync Callback, Async is Stopped. Paqckage:{PackageName} Object:{ObjectName}");
  40. result.Dispose();
  41. }
  42. else
  43. {
  44. Result = result;
  45. }
  46. Completed();
  47. });
  48. }
  49. }
  50. }