public void StartLoop(GameLoopType startType) { _playerActor = GetPlayerActor(); _bananaTreeGenerator = new BananaTreeGenerator(_playerActor.GameObject.transform, _gameSettings, _audioPlayer); // HACK. 面倒なので全オブジェクト拾ってきてinterfaceを対象に初期化していく. var objs = Object.FindObjectsOfType <GameObject>(); foreach (var obj in objs) { // Presenterを初期化. foreach (var presenter in obj.GetComponents <IPresenter>()) { presenter.Initialize(this); } // ECS利用箇所にPresenterを流し込む foreach (var usable in obj.GetComponents <IECSProviderUsable>()) { usable.SetProvider(_ecsProvider); } } SetLoop(startType); }
public async void SetLoop(GameLoopType type) { _currentLoop?.LoopOut(); _isUpdatable = false; _currentLoop = _gameLoops[(int)type]; await _currentLoop.LoopIn(); _isUpdatable = true; }
/// <summary>Sets the system.</summary> /// <param name="systemType">Type of the system.</param> /// <param name="system">The system.</param> /// <param name="gameLoopType">Type of the game loop.</param> /// <param name="layer">The layer.</param> /// <param name="executionType">Type of the execution.</param> /// <returns>The EntitySystem.</returns> private EntitySystem SetSystem(Type systemType, EntitySystem system, GameLoopType gameLoopType, int layer = 0, ExecutionType executionType = ExecutionType.Synchronous) { system.EntityWorld = this.entityWorld; if (this.systems.ContainsKey(systemType)) { this.systems[systemType].Add(system); } else { Type genericType = typeof(List <>); Type listType = genericType.MakeGenericType(systemType); this.systems[systemType] = (IList)Activator.CreateInstance(listType); this.systems[systemType].Add(system); } switch (gameLoopType) { case GameLoopType.Draw: { SetSystem(ref this.drawLayers, system, layer, executionType); } break; case GameLoopType.Update: { SetSystem(ref this.updateLayers, system, layer, executionType); } break; } if (!this.mergedBag.Contains(system)) { this.mergedBag.Add(system); } system.Bit = this.systemBitManager.GetBitFor(system); return(system); }
private EntitySystem AddSystem(Type systemType, EntitySystem system, GameLoopType gameLoopType, int layer, SystemExecutionType executionType) { Debug.Assert(systemType != null); Debug.Assert(system != null); if (Systems.Contains(system)) { throw new InvalidOperationException($"System '{systemType}' has already been added."); } system.Manager = _manager; Systems.Add(system); var processingSystem = system as EntityProcessingSystem; if (processingSystem != null) { processingSystem.Index = ProcessingSystems.Count; ProcessingSystems.Add(processingSystem); } switch (gameLoopType) { case GameLoopType.Draw: AddSystemTo(ref _drawLayers, system, layer, executionType); break; case GameLoopType.Update: AddSystemTo(ref _updateLayers, system, layer, executionType); break; default: throw new ArgumentOutOfRangeException(nameof(gameLoopType), gameLoopType, null); } return(system); }
protected EntitySystem(Type[] componentTypes, GameLoopType loopType = GameLoopType.Update) { ComponentTypes = componentTypes; GameLoopType = loopType; }
/// <summary>Sets the system.</summary> /// <typeparam name="T">The <see langword="Type" /> T.</typeparam> /// <param name="system">The system.</param> /// <param name="gameLoopType">Type of the game loop.</param> /// <param name="layer">The layer.</param> /// <param name="executionType">Type of the execution.</param> /// <returns>The set system.</returns> public T SetSystem <T>(T system, GameLoopType gameLoopType, int layer = 0, ExecutionType executionType = ExecutionType.Synchronous) where T : EntitySystem { return((T)this.SetSystem(system.GetType(), system, gameLoopType, layer, executionType)); }
//// ReSharper disable once ParameterTypeCanBeEnumerable.Local //private static void ProcessSystemsAsynchronous(Bag<System> systems) //{ // // block // // does not garantee async... // Parallel.ForEach(systems, system => system.ProcessInternal()); //} internal T AddSystem <T>(T system, GameLoopType gameLoopType, int layer, SystemExecutionType executionType) where T : EntitySystem { Debug.Assert(system != null); return((T)AddSystem(system.GetType(), system, gameLoopType, layer, executionType)); }
public EntitySystem(EntityWorld entityWorld, Type[] types, GameLoopType gameLoopType) { this.entityWorld = entityWorld; this.Types = types; this.GameLoopType = gameLoopType; }
public EntitySystemAttribute(GameLoopType gameLoopType) { GameLoopType = gameLoopType; Layer = 0; }