/// <summary>
        /// 对每个Mod的系统根据运行于的世界和时间分类
        /// </summary>
        private void SortModSystem(Type system, NativeModSystems mod)
        {
            //获得系统运行于的世界
            var worldtype = GetSystemWorldType(system);

            if (worldtype == WorldTypes.DefaultWorld)
            {
                //是默认状态则添加到DefaultSystem中,由于默认状态的int为0所以要直接用=比较
                mod.DefaultWorldSystem.Add(system);
                //如果所属系统组为Presentation组,加入列表,将在服务端禁用
                var attr = TypeManager.GetSystemAttributes(system, typeof(UpdateInGroupAttribute));
                if (attr.Length != 0 && (attr[0] as UpdateInGroupAttribute).GroupType.Equals(typeof(PresentationSystemGroup)))
                {
                    mod.DefaultPresentationSystems.Add(system);
                }
                return;//且不需要继续比较
            }
            if ((worldtype & WorldTypes.ClientWorld) == WorldTypes.ClientWorld)
            {
                //添加到客户端世界
                mod.ClientSystems.Add(system);
            }
            if ((worldtype & WorldTypes.ServerWorld) == WorldTypes.ServerWorld)
            {
                //添加到服务端世界
                mod.ServerSystems.Add(system);
            }
            if ((worldtype & WorldTypes.ExplicitDefaultWorld) == WorldTypes.ExplicitDefaultWorld)
            {
                //添加到默认世界
                ExplicitDefaultWorldSystems.Add(system);
            }
        }
Example #2
0
        protected internal static void GenerateSystemLists(IReadOnlyList <Type> systems)
        {
            s_State.DefaultWorldSystems         = new List <Type>();
            s_State.ExplicitDefaultWorldSystems = new List <Type>();
            s_State.ClientInitializationSystems = new List <Type>();
            s_State.ClientSimulationSystems     = new List <Type>();
            s_State.ClientPresentationSystems   = new List <Type>();
            s_State.ClientChildSystems          = new List <Tuple <Type, Type> >();
            s_State.ServerInitializationSystems = new List <Type>();
            s_State.ServerSimulationSystems     = new List <Type>();
            s_State.ServerChildSystems          = new List <Tuple <Type, Type> >();

            foreach (var type in systems)
            {
                var targetWorld = GetSystemAttribute <UpdateInWorld>(type);
                if ((targetWorld != null && targetWorld.World == UpdateInWorld.TargetWorld.Default) ||
#if !UNITY_DOTSRUNTIME
                    type == typeof(ConvertToEntitySystem) ||
#endif
                    type == typeof(InitializationSystemGroup) ||
                    type == typeof(SimulationSystemGroup) ||
                    type == typeof(PresentationSystemGroup))
                {
                    DefaultWorldSystems.Add(type);
                    ExplicitDefaultWorldSystems.Add(type);
                    continue;
                }

                var groups = TypeManager.GetSystemAttributes(type, typeof(UpdateInGroupAttribute));;
                if (groups.Length == 0)
                {
                    groups = new Attribute[] { new UpdateInGroupAttribute(typeof(SimulationSystemGroup)) };
                }

                foreach (var grp in groups)
                {
                    var group = grp as UpdateInGroupAttribute;
                    if (group.GroupType == typeof(ClientAndServerSimulationSystemGroup) ||
                        group.GroupType == typeof(SimulationSystemGroup))
                    {
                        if (group.GroupType == typeof(ClientAndServerSimulationSystemGroup) && targetWorld != null && targetWorld.World == UpdateInWorld.TargetWorld.Default)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use [UpdateInWorld(UpdateInWorld.TargetWorld.Default)] when using [UpdateInGroup(typeof(ClientAndServerSimulationSystemGroup)] {0}",
                                                             type));
                        }
                        if (group.GroupType == typeof(SimulationSystemGroup) &&
                            (targetWorld == null || targetWorld.World == UpdateInWorld.TargetWorld.Default))
                        {
                            DefaultWorldSystems.Add(type);
                            if (targetWorld != null)
                            {
                                ExplicitDefaultWorldSystems.Add(type);
                            }
                        }
                        if (targetWorld == null || (targetWorld.World & UpdateInWorld.TargetWorld.Server) != 0)
                        {
                            s_State.ServerSimulationSystems.Add(type);
                        }
                        if (targetWorld == null || (targetWorld.World & UpdateInWorld.TargetWorld.Client) != 0)
                        {
                            s_State.ClientSimulationSystems.Add(type);
                        }
                    }
                    else if (group.GroupType == typeof(ClientAndServerInitializationSystemGroup) ||
                             group.GroupType == typeof(InitializationSystemGroup))
                    {
                        if (group.GroupType == typeof(ClientAndServerInitializationSystemGroup) && targetWorld != null && targetWorld.World == UpdateInWorld.TargetWorld.Default)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use [UpdateInWorld(UpdateInWorld.TargetWorld.Default)] when using [UpdateInGroup(typeof(ClientAndServerInitializationSystemGroup)] {0}",
                                                             type));
                        }
                        if (group.GroupType == typeof(InitializationSystemGroup) &&
                            (targetWorld == null || targetWorld.World == UpdateInWorld.TargetWorld.Default))
                        {
                            DefaultWorldSystems.Add(type);
                            if (targetWorld != null)
                            {
                                ExplicitDefaultWorldSystems.Add(type);
                            }
                        }
                        if (targetWorld == null || (targetWorld.World & UpdateInWorld.TargetWorld.Server) != 0)
                        {
                            s_State.ServerInitializationSystems.Add(type);
                        }
                        if (targetWorld == null || (targetWorld.World & UpdateInWorld.TargetWorld.Client) != 0)
                        {
                            s_State.ClientInitializationSystems.Add(type);
                        }
                    }
                    else if (group.GroupType == typeof(ServerInitializationSystemGroup))
                    {
                        if (targetWorld != null)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use [UpdateInWorld] when using [UpdateInGroup(typeof(ServerInitializationSystemGroup)] {0}",
                                                             type));
                        }
                        s_State.ServerInitializationSystems.Add(type);
                    }
                    else if (group.GroupType == typeof(ClientInitializationSystemGroup))
                    {
                        if (targetWorld != null)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use [UpdateInWorld] when using [UpdateInGroup(typeof(ClientInitializationSystemGroup)] {0}",
                                                             type));
                        }
                        s_State.ClientInitializationSystems.Add(type);
                    }
                    else if (group.GroupType == typeof(ServerSimulationSystemGroup))
                    {
                        if (targetWorld != null)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use [UpdateInWorld] when using [UpdateInGroup(typeof(ServerSimulationSystemGroup)] {0}",
                                                             type));
                        }
                        s_State.ServerSimulationSystems.Add(type);
                    }
                    else if (group.GroupType == typeof(ClientSimulationSystemGroup))
                    {
                        if (targetWorld != null)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use [UpdateInWorld] when using [UpdateInGroup(typeof(ClientSimulationSystemGroup)] {0}",
                                                             type));
                        }
                        s_State.ClientSimulationSystems.Add(type);
                    }
                    else if (group.GroupType == typeof(ClientPresentationSystemGroup) ||
                             group.GroupType == typeof(PresentationSystemGroup))
                    {
                        if (group.GroupType == typeof(ClientPresentationSystemGroup) && targetWorld != null)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use [UpdateInWorld] when using [UpdateInGroup(typeof(ClientPresentationSystemGroup)] {0}",
                                                             type));
                        }
                        if (targetWorld != null && (targetWorld.World & UpdateInWorld.TargetWorld.Server) != 0)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot use presentation systems on the server {0}",
                                                             type));
                        }
                        if (group.GroupType == typeof(PresentationSystemGroup) &&
                            (targetWorld == null || targetWorld.World == UpdateInWorld.TargetWorld.Default))
                        {
                            DefaultWorldSystems.Add(type);
                            if (targetWorld != null)
                            {
                                ExplicitDefaultWorldSystems.Add(type);
                            }
                        }
                        if (targetWorld == null || (targetWorld.World & UpdateInWorld.TargetWorld.Client) != 0)
                        {
                            s_State.ClientPresentationSystems.Add(type);
                        }
                    }
                    else
                    {
                        var mask = GetTopLevelWorldMask(group.GroupType);
                        if (targetWorld != null && targetWorld.World == UpdateInWorld.TargetWorld.Default &&
                            (mask & WorldType.DefaultWorld) == 0)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot update in default world when parent is not in the default world {0}", type));
                        }
                        if ((targetWorld != null && (targetWorld.World & UpdateInWorld.TargetWorld.Client) != 0) &&
                            (mask & WorldType.ClientWorld) == 0)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot update in client world when parent is not in the client world {0}", type));
                        }
                        if ((targetWorld != null && (targetWorld.World & UpdateInWorld.TargetWorld.Server) != 0) &&
                            (mask & WorldType.ServerWorld) == 0)
                        {
                            UnityEngine.Debug.LogWarning(String.Format(
                                                             "Cannot update in server world when parent is not in the server world {0}", type));
                        }
                        if ((mask & WorldType.DefaultWorld) != 0 &&
                            (targetWorld == null || targetWorld.World == UpdateInWorld.TargetWorld.Default))
                        {
                            DefaultWorldSystems.Add(type);
                            if (targetWorld != null || (mask & WorldType.ExplicitWorld) != 0)
                            {
                                ExplicitDefaultWorldSystems.Add(type);
                            }
                        }
                        if ((mask & WorldType.ClientWorld) != 0 &&
                            (targetWorld == null || (targetWorld.World & UpdateInWorld.TargetWorld.Client) != 0))
                        {
                            s_State.ClientChildSystems.Add(new Tuple <Type, Type>(type, group.GroupType));
                        }
                        if ((mask & WorldType.ServerWorld) != 0 &&
                            (targetWorld == null || (targetWorld.World & UpdateInWorld.TargetWorld.Server) != 0))
                        {
                            s_State.ServerChildSystems.Add(new Tuple <Type, Type>(type, group.GroupType));
                        }
                    }
                }
            }
        }