Exemplo n.º 1
0
        public void Start()
        {
            ECS_ClientWorld = new World("ClientWorld");
            var systems = WorldCreator.GetSystemsFromAssemblies(ECS_ClientWorld, "FNZ.Client", "FNZ.Shared");

            var initializationSystemGroup = ECS_ClientWorld.GetOrCreateSystem <InitializationSystemGroup>();
            var simulationSystemGroup     = ECS_ClientWorld.GetOrCreateSystem <SimulationSystemGroup>();
            var presentationSystemGroup   = ECS_ClientWorld.GetOrCreateSystem <PresentationSystemGroup>();

            foreach (var type in systems)
            {
                var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);

                if (groups.Length == 0)
                {
                    simulationSystemGroup.AddSystemToUpdateList(WorldCreator.GetBehaviourManagerAndLogException(ECS_ClientWorld, type) as ComponentSystemBase);
                }

                foreach (var g in groups)
                {
                    var group = g as UpdateInGroupAttribute;

                    if (group == null)
                    {
                        continue;
                    }

                    if (!(typeof(ComponentSystemGroup)).IsAssignableFrom(group.GroupType))
                    {
                        UnityEngine.Debug.LogError($"Invalid [UpdateInGroup] attribute for {type}: {group.GroupType} must be derived from ComponentSystemGroup.");
                        continue;
                    }

                    var groupMgr = WorldCreator.GetBehaviourManagerAndLogException(ECS_ClientWorld, group.GroupType);

                    if (groupMgr == null)
                    {
                        UnityEngine.Debug.LogWarning(
                            $"Skipping creation of {type} due to errors creating the group {group.GroupType}. Fix these errors before continuing.");
                        continue;
                    }

                    var groupSys = groupMgr as ComponentSystemGroup;

                    if (groupSys != null)
                    {
                        groupSys.AddSystemToUpdateList(WorldCreator.GetBehaviourManagerAndLogException(ECS_ClientWorld, type) as ComponentSystemBase);
                    }
                }
            }

            initializationSystemGroup.SortSystemUpdateList();
            simulationSystemGroup.SortSystemUpdateList();
            presentationSystemGroup.SortSystemUpdateList();

            WorldCreator.UpdatePlayerLoop(ECS_ClientWorld);
        }
Exemplo n.º 2
0
        public void Start()
        {
            ECS_ServerWorld = new World("ServerWorld");
            var systems = WorldCreator.GetSystemsFromAssemblies(ECS_ServerWorld, "FNZ.Server", "FNZ.Shared");

            var initializationSystemGroup = ECS_ServerWorld.GetOrCreateSystem <InitializationSystemGroup>();
            var simulationSystemGroup     = ECS_ServerWorld.GetOrCreateSystem <SimulationSystemGroup>();
            var presentationSystemGroup   = ECS_ServerWorld.GetOrCreateSystem <PresentationSystemGroup>();

            foreach (var type in systems)
            {
                var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);

                if (groups.Length == 0)
                {
                    simulationSystemGroup.AddSystemToUpdateList(ECS_ServerWorld.GetOrCreateSystem(type) as ComponentSystemBase);
                }

                foreach (var g in groups)
                {
                    var group = g as UpdateInGroupAttribute;

                    if (group == null)
                    {
                        continue;
                    }
                    var groupMgr = ECS_ServerWorld.GetOrCreateSystem(group.GroupType);
                    var groupSys = groupMgr as ComponentSystemGroup;

                    if (groupSys != null)
                    {
                        groupSys.AddSystemToUpdateList(ECS_ServerWorld.GetOrCreateSystem(type) as ComponentSystemBase);
                    }
                }
            }

            initializationSystemGroup.SortSystemUpdateList();
            simulationSystemGroup.SortSystemUpdateList();
            presentationSystemGroup.SortSystemUpdateList();
            WorldCreator.UpdatePlayerLoop(ECS_ServerWorld);
        }