Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        render = new MeshInstanceRenderer
        {
            castShadows    = ShadowCastingMode.On,
            receiveShadows = true,
            material       = new Material(material)
            {
                enableInstancing = true,
                mainTexture      = texture,
            },
            mesh    = mesh,
            subMesh = 0,
        };
        PlayerLoopManager.RegisterDomainUnload(DestroyAll, 10000);
        var world = World.Active = new World("x");

        World.Active.CreateManager(typeof(EndFrameTransformSystem));
        World.Active.CreateManager(typeof(CountUpSystem), GameObject.Find("Count").GetComponent <TMPro.TMP_Text>());
        World.Active.CreateManager <MeshInstanceRendererSystem>().ActiveCamera = GetComponent <Camera>();
        ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);

        manager   = world.GetExistingManager <EntityManager>();
        archetype = manager.CreateArchetype(ComponentType.Create <Position>(), ComponentType.Create <MeshInstanceRenderer>(), ComponentType.Create <Static>());
    }
Ejemplo n.º 2
0
        private static void Init()
        {
            if (initialized)
            {
                return;
            }

            initialized = true;
            PlayerLoopManager.RegisterDomainUnload(WorldsInitializationHelper.DomainUnloadShutdown, 1000);

            // Setup template to use for player on connecting client
            PlayerLifecycleConfig.CreatePlayerEntityTemplate = PlayerTemplate.CreatePlayerEntityTemplate;
        }
Ejemplo n.º 3
0
        private void Initialize()
        {
            _world = OnCreateWorld();
            if (SetWorldActive)
            {
                World.Active = _world;
            }

            PlayerLoopManager.RegisterDomainUnload(OnDomainUnloadShutdown, 10000);

            OnRegisterSystems();
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(_world);
        }
Ejemplo n.º 4
0
        private static void Init()
        {
            if (initialized)
            {
                return;
            }

            initialized = true;
            WorldsInitializationHelper.SetupInjectionHooks();
            PlayerLoopManager.RegisterDomainUnload(WorldsInitializationHelper.DomainUnloadShutdown, 1000);

            // Setup template to use for player on connecting client
            PlayerLifecycleConfig.CreatePlayerEntityTemplate   = FpsEntityTemplates.Player;
            PlayerLifecycleConfig.MaxNumFailedPlayerHeartbeats = 5;
        }
Ejemplo n.º 5
0
        static void BootWorld()
        {
            var world = new World("Demo World");

            world.CreateManager <SpawnBarrier> ();
            world.CreateManager <SpawnEntitySystem> ();
            world.CreateManager <OrbitSystem> ();
            world.CreateManager <TransformSystem> ();
            world.CreateManager <MeshInstanceRendererSystem> ();
            var worlds = new List <World> ();

            worlds.AddRange(World.AllWorlds);
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worlds.ToArray());
            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);
        }
Ejemplo n.º 6
0
        public void Awake()
        {
            // Taken from DefaultWorldInitalization.cs
            SetupInjectionHooks();                                               // Register hybrid injection hooks
            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); // Clean up worlds and player loop

            Application.targetFrameRate = targetFrameRate;
            Worker.OnConnect           += w => Debug.Log($"{w.WorkerId} is connecting");
            Worker.OnDisconnect        += w => Debug.Log($"{w.WorkerId} is disconnecting");

            // Setup template to use for player on connecting client
            PlayerLifecycleConfig.CreatePlayerEntityTemplate = PlayerTemplate.CreatePlayerEntityTemplate;

            if (Application.isEditor)
            {
                var config = new ReceptionistConfig
                {
                    WorkerType = SystemConfig.UnityGameLogic,
                };
                CreateWorker(config, new Vector3(500, 0, 0));
                config = new ReceptionistConfig
                {
                    WorkerType = SystemConfig.UnityClient,
                };
                CreateWorker(config, Vector3.zero);
            }
            else
            {
                var commandLineArguments = Environment.GetCommandLineArgs();
                Debug.LogFormat("Command line {0}", string.Join(" ", commandLineArguments.ToArray()));
                var commandLineArgs = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
                var config          = ConnectionUtility.CreateConnectionConfigFromCommandLine(commandLineArgs);
                CreateWorker(config, Vector3.zero);
            }

            if (World.AllWorlds.Count <= 0)
            {
                throw new InvalidConfigurationException(
                          "No worlds have been created, due to invalid worker types being specified. Check the config in" +
                          "Improbable -> Configure editor workers.");
            }

            var worlds = World.AllWorlds.ToArray();

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worlds);
            // Systems don't tick if World.Active isn't set
            World.Active = worlds[0];
        }
Ejemplo n.º 7
0
        private static void InitializeBeforeSceneLoad()
        {
            var world = new World("Terrain experiment");

            World.Active = world;

            _terrainSystemManager = new TerrainSystemManager(world);

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);
            world.CreateManager <EntityManager>();
            world.CreateManager <EndFrameBarrier>();
            world.CreateManager <RenderBoundsUpdateSystem>();
            world.CreateManager <RenderMeshSystemV2>();
            world.CreateManager <EndFrameTransformSystem>();
            world.CreateManager <CopyTransformFromGameObjectSystem>();
        }
Ejemplo n.º 8
0
        static void Initialize()
        {
            var worlds = new World[3];

            // もしもPure ECSではなくGameObjectEntityなどを使用してHybrid ECSを使いたいと言うならば、Hookする必要がある。
            // ただ、その場合Unity.Entities.GameObjectArrayInjectionHookインスタンスが必要だが、internalなクラスであるのでリフレクションが必須となる。
            // 参考までにここに書いておく。

            // var assembly = Assembly.GetAssembly(typeof(GameObjectEntity));
            // InjectionHookSupport.RegisterHook(Activator.CreateInstance(assembly.GetType("Unity.Entities.GameObjectArrayInjectionHook")) as InjectionHook);
            // InjectionHookSupport.RegisterHook(Activator.CreateInstance(assembly.GetType("Unity.Entities.TransformAccessArrayInjectionHook")) as InjectionHook);
            // InjectionHookSupport.RegisterHook(Activator.CreateInstance(assembly.GetType("Unity.Entities.ComponentArrayInjectionHook")) as InjectionHook);


            // ComponentSystemPatchAttributeというクラスに付く属性が存在する。
            // 用途はイマイチ不明であるが、ComponentSystemの動作の上書きでもするのだろうか?
            // ScriptBehaviourUpdateOrder.csで言及されている。要研究。

            // var AddComponentSystemPatch = typeof(World).GetMethod("AddComponentSystemPatch", BindingFlags.NonPublic | BindingFlags.Instance);
            // AddComponentSystemPatch.Invoke(world, new object[] { SpriteRenderSystem_DoubleBufferType });

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            var Bound = new float4(-50, -50, 50, 50);
            var MoveForwardSystemType = typeof(MoveForwardSystem);

            // 最低限必要なSystemだけに絞るべし。

            worlds[0] = World.Active = new World("world0");
            worlds[0].CreateManager <BoundReflectSystem>().Region = Bound;
            // 内部実装上ジェネリクスはTypeオブジェクトを引数に取るメソッドのラッパーでしかない。
            worlds[0].CreateManager(MoveForwardSystemType);
            worlds[0].CreateManager(typeof(SpriteRenderSystem));

            worlds[1] = new World("world1");
            worlds[1].CreateManager <BoundReflectSystem>().Region = Bound;
            worlds[1].CreateManager(MoveForwardSystemType);
            worlds[1].CreateManager(typeof(SpriteRenderSystem_DoubleBuffer));

            worlds[2] = new World("world2");
            worlds[2].CreateManager <BoundReflectSystem>().Region = Bound;
            worlds[2].CreateManager(MoveForwardSystemType);
            worlds[2].CreateManager(typeof(TransformSystem));
            worlds[2].CreateManager(typeof(MeshInstanceRendererSystem));

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worlds);
        }
Ejemplo n.º 9
0
        void Awake()
        {
            var world = new World("State Machine World");

            world.GetOrCreateManager <NavAgentSystem>();
            world.GetOrCreateManager <NavMeshQuerySystem>().UseCache = false;
            world.GetOrCreateManager <NavAgentToPositionSyncSystem>();
            world.GetOrCreateManager <NavAgentToRotationSyncSystem>();
            world.GetOrCreateManager <SyncStateMachineUnitTransforms>();
            world.GetOrCreateManager <ArcherDebugSystem>();

            AnimatorBootstrap.Create <Archer>(world, graphs[0]);
            AnimatorBootstrap.Create <Cerberus>(world, graphs[1]);
            AnimatorBootstrap.Create <Diablous>(world, graphs[2]);
            AnimatorBootstrap.Create <Knight>(world, graphs[3]);
            AnimatorBootstrap.Create <Mage>(world, graphs[4]);
            AnimatorBootstrap.Create <Sorceress>(world, graphs[5]);

            manager = world.GetOrCreateManager <EntityManager>();
            var allWorlds = new World[] { world };

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(allWorlds);
            World.Active = world;
            Unit         = manager.CreateArchetype(
                typeof(Position),
                typeof(Rotation),
                typeof(SyncPositionFromNavAgent),
                typeof(SyncRotationFromNavAgent),
                typeof(StateMachineUnit),
                typeof(NavAgent)
                );

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            for (int i = 0; i < 100; i++)
            {
                Spawn <Archer>();
                Spawn <Cerberus>();
                Spawn <Mage>();
                Spawn <Diablous>();
                Spawn <Sorceress>();
                Spawn <Knight>();
            }
        }
        static void Boot()
        {
            var world = new World("Example World");

            world.GetOrCreateManager <NavAgentSystem>();
            var query = world.GetOrCreateManager <NavMeshQuerySystem>();

            world.GetOrCreateManager <AnimatedRendererSystem>();
            world.GetOrCreateManager <NavAgentToPositionSyncSystem>();
            world.GetOrCreateManager <RecycleDeadSystem>();
            var targetSystem = world.GetOrCreateManager <SetTargetSystem>();

            spawner = world.GetOrCreateManager <SpawnerSystem>();
            world.GetOrCreateManager <UpdateMatrixSystem>();
            manager = world.GetOrCreateManager <EntityManager>();
            var allWorlds = new World[] { world };

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(allWorlds);
            World.Active = world;
            Unit         = manager.CreateArchetype(
                typeof(SyncPositionFromNavAgent),
                typeof(Position),
                typeof(TransformMatrix),
                typeof(Unit),
                typeof(Animated),
                typeof(AnimatedState),
                typeof(NavAgent)
                );

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            // setup navmesh query
            query.UseCache = false;
            // ArchetypeDeclarationStart - Do not remove
            // ArchetypeDeclarationStop - Do not remove
        }
Ejemplo n.º 11
0
        public void Awake()
        {
            InitializeWorkerTypes();
            // Taken from DefaultWorldInitalization.cs
            SetupInjectionHooks();                                               // Register hybrid injection hooks
            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); // Clean up worlds and player loop

            Application.targetFrameRate = TargetFrameRate;
            if (Application.isEditor)
            {
#if UNITY_EDITOR
                var workerConfigurations =
                    AssetDatabase.LoadAssetAtPath <ScriptableWorkerConfiguration>(ScriptableWorkerConfiguration
                                                                                  .AssetPath);
                foreach (var workerConfig in workerConfigurations.WorkerConfigurations)
                {
                    if (!workerConfig.IsEnabled)
                    {
                        continue;
                    }

                    var worker = WorkerRegistry.CreateWorker(workerConfig.Type, $"{workerConfig.Type}-{Guid.NewGuid()}",
                                                             workerConfig.Origin);
                    Workers.Add(worker);
                }

                connectionConfig = new ReceptionistConfig();
                connectionConfig.UseExternalIp = workerConfigurations.UseExternalIp;
#endif
            }
            else
            {
                var commandLineArguments = System.Environment.GetCommandLineArgs();
                Debug.LogFormat("Command line {0}", string.Join(" ", commandLineArguments.ToArray()));
                var commandLineArgs = CommandLineUtility.ParseCommandLineArgs(commandLineArguments);
                var workerType      =
                    CommandLineUtility.GetCommandLineValue(commandLineArgs, RuntimeConfigNames.WorkerType,
                                                           string.Empty);
                var workerId =
                    CommandLineUtility.GetCommandLineValue(commandLineArgs, RuntimeConfigNames.WorkerId,
                                                           string.Empty);

                // because the launcher does not pass in the worker type as an argument
                var worker = workerType.Equals(string.Empty)
                    ? WorkerRegistry.CreateWorker <UnityClient>(
                    workerId: null,     // The worker id for the UnityClient will be auto-generated.
                    origin: new Vector3(0, 0, 0))
                    : WorkerRegistry.CreateWorker(workerType, workerId, new Vector3(0, 0, 0));

                Workers.Add(worker);

                connectionConfig = ConnectionUtility.CreateConnectionConfigFromCommandLine(commandLineArgs);
            }

            if (World.AllWorlds.Count <= 0)
            {
                throw new InvalidConfigurationException(
                          "No worlds have been created, due to invalid worker types being specified. Check the config in" +
                          "Improbable -> Configure editor workers.");
            }

            var worlds = World.AllWorlds.ToArray();
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worlds);
            // Systems don't tick if World.Active isn't set
            World.Active = worlds[0];
        }
Ejemplo n.º 12
0
        private static void Initialize(string worldName, bool editorWorld)
        {
            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            var world = new World(worldName);

            World.Active = world;
            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

            if (systems == null)
            {
                world.Dispose();
                if (World.Active == world)
                {
                    World.Active = null;
                }
                return;
            }

            // create presentation system and simulation system
            var initializationSystemGroup = world.GetOrCreateSystem <InitializationSystemGroup>();
            var simulationSystemGroup     = world.GetOrCreateSystem <SimulationSystemGroup>();
            var presentationSystemGroup   = world.GetOrCreateSystem <PresentationSystemGroup>();
            var fixedUpdateSystemGroup    = world.GetOrCreateSystem <FixedUpdateGroup>();

            // Add systems to their groups, based on the [UpdateInGroup] attribute.
            foreach (var type in systems)
            {
                // Skip the built-in root-level systems
                if (type == typeof(InitializationSystemGroup) ||
                    type == typeof(SimulationSystemGroup) ||
                    type == typeof(PresentationSystemGroup) ||
                    type == typeof(FixedUpdateGroup))
                {
                    continue;
                }
                if (editorWorld)
                {
                    if (Attribute.IsDefined(type, typeof(ExecuteInEditMode)))
                    {
                        Debug.LogError(
                            $"{type} is decorated with {typeof(ExecuteInEditMode)}. Support for this attribute will be deprecated. Please use {typeof(ExecuteAlways)} instead.");
                    }
                    if (!Attribute.IsDefined(type, typeof(ExecuteAlways)))
                    {
                        continue;
                    }
                }

                var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
                if (groups.Length == 0)
                {
                    simulationSystemGroup.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type));
                }

                foreach (var g in groups)
                {
                    var group = g as UpdateInGroupAttribute;
                    if (group == null)
                    {
                        continue;
                    }

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

                    var groupMgr = GetOrCreateManagerAndLogException(world, group.GroupType);
                    if (groupMgr == null)
                    {
                        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(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase);
                    }
                }
            }

            // Update player loop
            initializationSystemGroup.SortSystemUpdateList();
            simulationSystemGroup.SortSystemUpdateList();
            presentationSystemGroup.SortSystemUpdateList();
            fixedUpdateSystemGroup.SortSystemUpdateList();
            UpdatePlayerLoop(world);
        }
Ejemplo n.º 13
0
 static void Initialize() => PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);
Ejemplo n.º 14
0
 static void Preload() => PlayerLoopManager.RegisterDomainUnload(DestroyAll, 10000);