Example #1
0
        async Task <UIComponent> AddWindow(string winName, GameObject go = null)
        {
            var type = World.Instance.GetComponentType($"View_{winName}Component");

            if (type == null)
            {
                Debug.LogError($"找不到对应类型---View_{winName}Component");
                return(null);
            }

            //生成窗口
            var component =
                World.Main.GetComponent <UIManagerComponent>().Entity
                .AddChild(type, IDGenerater.GetID(winName)) as UIComponent;

            if (component == null)
            {
                return(null);
            }

            component.Connect <UIComponent>();

            if (go == null)
            {
                go = await Create(winName);
            }

            //初始化窗口
            component.rectTransform = go.transform as RectTransform;

            //如果有动画组件就挂载动画组件
            if (go.TryGetComponent <UISetting>(out var uiSetting))
            {
                component.Entity.AddComponent <UIAnimaComponent>().From(uiSetting);
                component.ModuleUI = uiSetting.ModuleUI;
                go.SetActive(uiSetting.Active);
                Object.Destroy(uiSetting);
            }

            component.ViewName = winName;

            UiItems.Add(winName, component);
            UiItemsType.Add(type, component);

            if (BaseIndex == -1)
            {
                BaseIndex = go.transform.GetSiblingIndex();
            }

            //调用这个窗口的初始化系统
            World.Instance.RunSystemOfTagType(SystemType.UICreate, component.Entity);

            return(component);
        }
 public virtual void LoadToUi(ViewModelBase viewModel)
 {
     ApplicationController.DoOnMainThread(() => UiItems.Add(viewModel));
 }