UIModuleBuilder.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using XGame.Framework.Asset;
  3. using XGame.Framework.Quality;
  4. using XGame.Framework.Time;
  5. namespace XGame.Framework.UI
  6. {
  7. public class UIModuleBuilder
  8. {
  9. protected IUIModule product;
  10. public IUIModule Product => product;
  11. protected IUITree uiTree;
  12. protected IAssetModule assetModule;
  13. public void Build(IQualityModule qualityModule, ITimeModule timeModule)
  14. {
  15. assetModule = new AssetModule();
  16. CreateUITree();
  17. CreateProduct();
  18. var context = new UIContext(qualityModule, timeModule, product);
  19. (product as IUIContextSetter).Context = context;
  20. }
  21. protected virtual void CreateUITree()
  22. {
  23. const string uiTreeName = "UITree";
  24. var instance = Object.Instantiate(Resources.Load<UITree>(uiTreeName));
  25. Assert.IsNotNull(instance, "UITree不能为空.");
  26. instance.gameObject.name = uiTreeName;
  27. instance.transform.SetParent(AppManager.Root, false);
  28. uiTree = instance;
  29. }
  30. protected virtual void CreateProduct()
  31. {
  32. product = new UIModule(assetModule, uiTree);
  33. }
  34. }
  35. }