示例#1
0
        public void OnContextInitialized <T>(T contextHolder)
        {
            // Create engine root.
            _submissionScheduler = new SimpleEntitiesSubmissionScheduler();
            _enginesRoot         = new EnginesRoot(_submissionScheduler);

            // Initialize UECS.
            _world = new World("SveltoWorld");
            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(_world, systems);
            World.DefaultGameObjectInjectionWorld = _world;

            var syncGroup = new SyncSveltoToUECSGroup();

            _world.AddSystem(syncGroup);
            AddTickEngine(syncGroup);

            var uecsTickGroup = new PureUECSSystemsGroup(_world);

            AddTickEngine(uecsTickGroup);

            // Initialize SECS
            var entityFactory = _enginesRoot.GenerateEntityFactory();
        }
        public bool Initialize(string defaultWorldName)
        {
            //            Physics.autoSimulation = false;
            QualitySettings.vSyncCount = -1;

            _simpleSubmitScheduler = new SimpleEntitiesSubmissionScheduler();
            _enginesRoot           = new EnginesRoot(_simpleSubmitScheduler);
            _enginesToTick         = new FasterList <IJobifiedEngine>();

            _world = new World("Custom world");

            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(_world, systems);

            World.DefaultGameObjectInjectionWorld = _world;

            var copySveltoToUecsEnginesGroup = new SyncSveltoToUECSGroup();

            _world.AddSystem(copySveltoToUecsEnginesGroup);
            AddSveltoEngineToTick(copySveltoToUecsEnginesGroup);

            var tickUECSSystemsGroup = new PureUECSSystemsGroup(_world);

            AddSveltoEngineToTick(tickUECSSystemsGroup);

            ///Svelto will tick the UECS engines, We need control over everything
            //ScriptBehaviourUpdateOrder.UpdatePlayerLoop(_world);

            //add the engines we are going to use
            var generateEntityFactory = _enginesRoot.GenerateEntityFactory();

            var redfoodEntity =
                GameObjectConversionUtility.ConvertGameObjectHierarchy(Resources.Load("Sphere") as GameObject,
                                                                       new GameObjectConversionSettings()
            {
                DestinationWorld = _world
            });
            var bluefoodEntity =
                GameObjectConversionUtility.ConvertGameObjectHierarchy(Resources.Load("Sphereblue") as GameObject,
                                                                       new GameObjectConversionSettings()
            {
                DestinationWorld = _world
            });
            var redDoofusEntity =
                GameObjectConversionUtility.ConvertGameObjectHierarchy(Resources.Load("RedCapsule") as GameObject,
                                                                       new GameObjectConversionSettings()
            {
                DestinationWorld = _world
            });
            var blueDoofusEntity =
                GameObjectConversionUtility.ConvertGameObjectHierarchy(Resources.Load("BlueCapsule") as GameObject,
                                                                       new GameObjectConversionSettings()
            {
                DestinationWorld = _world
            });

            AddSveltoEngineToTick(new PlaceFoodOnClickEngine(redfoodEntity, bluefoodEntity, generateEntityFactory));
            AddSveltoEngineToTick(new SpawningDoofusEngine(redDoofusEntity, blueDoofusEntity, generateEntityFactory));
            var generateEntityFunctions = _enginesRoot.GenerateEntityFunctions();

            AddSveltoEngineToTick(new ConsumingFoodEngine(generateEntityFunctions));
            AddSveltoEngineToTick(new LookingForFoodDoofusesEngine(generateEntityFunctions));
            AddSveltoEngineToTick(new VelocityToPositionDoofusesEngine());

            AddSveltoCallbackEngine(new SpawnUnityEntityOnSveltoEntityEngine(_world));

            AddSveltoUECSEngine(new RenderingUECSDataSynchronizationEngine());

            StartTicking(_enginesToTick);

            return(true);
        }