コード例 #1
0
        public T Spawn(Entity.State state)
        {
            _cachedMember = _members.Dequeue();
            _cachedMember.OnSpawned(state);

            return(_cachedMember);
        }
コード例 #2
0
        public void Tick()
        {
            var count = (int)(_settings.enemyMaxCount * _settings.enemyCount.Evaluate(Timer.Value / _settings.maxDuration)) - _activeEntities.Count(e => e.GetType() == typeof(Enemy));

            if (count <= 0)
            {
                return;
            }

            var state = new Entity.State();

            var rnd    = Random.Range(0f, 1f);
            var radius = Mathf.Lerp(_settings.enemyMinRadius, _settings.enemyMaxRadius, rnd);
            var offset = Mathf.Lerp(0f, 360f, rnd);
            var angle  = 0f;

            for (int i = 0; i < count; i++)
            {
                angle = (i * 360f / count + offset) * Mathf.Deg2Rad;

                state.Position.x = radius * Mathf.Cos(angle);
                state.Position.y = radius * Mathf.Sin(angle);
                state.Rotation   = Quaternion.LookRotation(Vector3.forward, (Vector2)_player.Transform.position - state.Position);

                state.Color = Random.Range(0f, 1f) > 0.5f ? Color.red : Color.blue;

                _activeEntities.Add(_enemyPool.Spawn(state));
            }
        }
コード例 #3
0
        public Pool(int capacity, SceneEntity prefab, Entity.State state, Events events, Settings settings, bool membersGenerateCollisionEvents = true)
        {
            _members = new Queue <T>(capacity);
            _parent  = new GameObject($"{typeof(T)}Pool").GetComponent <Transform>();

            var args = new object[] { prefab, state, events, settings };

            for (var i = 0; i < capacity; i++)
            {
                _cachedMember = (T)Activator.CreateInstance(typeof(T), args);
                _members.Enqueue(_cachedMember);
                _cachedMember.OnInstantiated(_parent);
            }
        }
コード例 #4
0
        public EntitiesManager(Events events, Settings settings, List <Entity> activeEntities)
        {
            _settings       = settings;
            _activeEntities = activeEntities;

            var initialState = new Entity.State()
            {
                Position = Vector2.zero,
                Rotation = Quaternion.identity,
                Color    = Color.cyan,
            };

            _enemyPool      = new Pool <Enemy>(_settings.enemyMaxCount, _settings.enemyPrefab, initialState, events, _settings);
            _projectilePool = new Pool <Projectile>(30, _settings.projectilePrefab, initialState, events, _settings);
            _player         = new Player(_settings.playerPrefab, initialState, events, _settings);
            _activeEntities.Add(_player);
        }
コード例 #5
0
 public void ShootProjectile(Entity.State state)
 {
     _activeEntities.Add(_projectilePool.Spawn(state));
 }