Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public YuoEntity()
        {
            Components      = new Dictionary <Type, YuoComponent>();
            ChildComponents = new MultiMap <Type, YuoComponent>();
            Children        = new List <Main.Ecs.YuoEntity>();
            //EntityComponent为基础组件,无法移除,不会显示在组件列表中,但当销毁时会自动移除
            //可以通过获取EntityComponent是否为null来判断Entity是否释放
            EntityData        = new EntityComponent();
            EntityData.Entity = this;
            EntityData.Id     = IDGenerater.GetID(this);

            World.Instance.AddComponet(this, EntityData);
            World.Instance.RegisterEntity(this);
        }
Ejemplo n.º 3
0
        protected Component()
        {
            InstanceID = IDGenerater.GenerateInstanceID();
#if !SERVER
            if (!this.GetType().IsDefined(typeof(HideInInspector), true))
            {
                GameObject       = new GameObject();
                GameObject.name  = GetType().Name;
                GameObject.layer = LayerNames.GetLayerInt(LayerNames.HIDDEN);
                GameObject.transform.SetParent(Global.transform, false);
                GameObject.AddComponent <ComponentView>().Component = this;
            }
#endif
        }
Ejemplo n.º 4
0
        public void Awake()
        {
            _allSystem = new();
            if (Instance != null)
            {
                _dontInit = true;
                Destroy(gameObject);
                return;
            }

            _entities          = new();
            components         = new();
            systemsOfTag       = new();
            systemsOfComponent = new();

            Instance = this;

            DontDestroyOnLoad(gameObject);

            //系统初始化必须放在所有初始化之前
            Initialization();

            //基本核心组件挂载的实体
            Main = new YuoEntity(0);

            Main.EntityName = "核心组件";

            AddComponet(Main, IDGenerater.Instance);

            //添加一个场景实体
            var scene = new YuoEntity(IDGenerater.GetID(IDGenerater.IDType.Scene, 0));

            scene.EntityName = "默认场景";
            AllScenes.Add(scene);
            scene.AddComponent <SceneComponent>();
        }
Ejemplo n.º 5
0
 protected Component()
 {
     InstanceId = IDGenerater.GenerateId();
     //Game.EventSystem.Add(this);
 }