示例#1
0
    void CreateDust()
    {
        PoolableObject dust = EffectManager.Instance.GetDust(DustType.WALK);

        dust.transform.position   = transform.position;
        dust.transform.localScale = transform.lossyScale;
        float duration = dust.GetComponent <SimpleAnimation>().duration;

        dust.gameObject.SetActive(true);
        dust.GetComponent <Effector>().Scale(duration, transform.lossyScale * 1.2f).Then().Disable().Play();
    }
    private void DoSpawnEnemy(int SpawnIndex)
    {
        PoolableObject poolableObject = EnemyObjectPools[SpawnIndex].GetObject();

        if (poolableObject != null)
        {
            Enemy enemy = poolableObject.GetComponent <Enemy>();
            Enemies[SpawnIndex].SetupEnemy(enemy);

            int VertexIndex = Random.Range(0, Triangulation.vertices.Length);

            NavMeshHit Hit;
            if (NavMesh.SamplePosition(Triangulation.vertices[VertexIndex], out Hit, 2f, -1))
            {
                enemy.Agent.Warp(Hit.position);
                // enemy needs to get enabled and start chasing now.
                enemy.Movement.Player = Player;
                enemy.Agent.enabled   = true;
                enemy.Movement.StartChasing();
            }
            else
            {
                Debug.LogError($"Unable to place NavMeshAgent on NavMesh. Tried to use {Triangulation.vertices[VertexIndex]}");
            }
        }
        else
        {
            Debug.LogError($"Unable to fetch enemy of type {SpawnIndex} from object pool. Out of objects?");
        }
    }
示例#3
0
    public T GetPooledObject <T>() where T : PoolableObject
    {
        PoolableObject poolObj = GetPooledObject();
        T component            = poolObj.GetComponent <T>();

        return(component);
    }
示例#4
0
    public void MakeVirius(ViriusBrain[] _virusBrains)
    {
        VirusBorn += 1;
        PoolableObject poolableObject = m_ViriusPool.GetObject();

        poolableObject.SpawnObject(_virusBrains[0].transform.position);
        ViriusBrain _virus = poolableObject.GetComponent <ViriusBrain>();

        _virus.Born(_virusBrains);
        m_AliveVirius.Add(_virus);
    }
示例#5
0
    public void MakeaDataCube(DataCubeBrain[] dataCubebrains)
    {
        DataCubesBorn += 1;
        PoolableObject poolableObject = m_DataCubePool.GetObject();

        poolableObject.SpawnObject(dataCubebrains[0].transform.position);
        DataCubeBrain dataCubebrain = poolableObject.GetComponent <DataCubeBrain>();

        dataCubebrain.Born(dataCubebrains);
        m_AliveDataCubes.Add(dataCubebrain);
    }
示例#6
0
    private void StartPools()
    {
        m_DataCubePool = gameObject.AddComponent <ObjectPool>();
        m_DataCubePool.BeginPool(m_DataCubePrefab, m_DataCubesToSpawn, null);

        m_ViriusPool = gameObject.AddComponent <ObjectPool>();
        m_ViriusPool.BeginPool(m_ViriusPrefab, m_ViriusToSpawn, transform);

        m_MemorySlotPool = gameObject.AddComponent <ObjectPool>();
        m_MemorySlotPool.BeginPool(m_MemorySlotPrefab, 10, transform);

        m_ProcessorTreePrefabPool = gameObject.AddComponent <ObjectPool>();
        m_ProcessorTreePrefabPool.BeginPool(m_ProcessorTreePrefab, 10, null);

        m_GarbargeCollectorPool = gameObject.AddComponent <ObjectPool>();
        m_GarbargeCollectorPool.BeginPool(m_GarbargeCollecterPrefab, m_CarbargeCollectersToSpawn, transform);

        m_AliveDataCubes = new List <DataCubeBrain>();
        m_AliveVirius    = new List <ViriusBrain>();

        for (int i = 0; i < m_DataCubesToSpawn; i++)
        {
            PoolableObject _obj = m_DataCubePool.GetObject();
            _obj.SpawnObject(GetRandomPos());
            DataCubeBrain dataBrain = _obj.GetComponent <DataCubeBrain>();
            dataBrain.SetRandomStats();
            m_AliveDataCubes.Add(dataBrain);
        }
        CalculateAliveDC();

        for (int i = 0; i < m_ViriusToSpawn; i++)
        {
            PoolableObject _obj = m_ViriusPool.GetObject();
            _obj.SpawnObject(GetRandomPos());
            ViriusBrain virusbrain = _obj.GetComponent <ViriusBrain>();
            virusbrain.SetRandomStats();
            m_AliveVirius.Add(virusbrain);
        }

        for (int i = 0; i < m_CarbargeCollectersToSpawn; i++)
        {
            PoolableObject _obj = m_GarbargeCollectorPool.GetObject();
            _obj.SpawnObject(GetRandomPos());
        }
        int ammount = Mathf.RoundToInt(m_DataCubesToSpawn * 0.50f);

        for (int i = 0; i < ammount; i++)
        {
            PoolableObject _obj = m_ProcessorTreePrefabPool.GetObject();
            _obj.SpawnObject(GetRandomPos());
        }

        StartCoroutine(SpawnMemorySlot());
    }
示例#7
0
 private void Start()
 {
     for (int currentTeam = 0; currentTeam < _TotalAITeams; currentTeam++)
     {
         for (int aIUnit = 0; aIUnit < _AICountPerTeam; aIUnit++)
         {
             Spawner        spawner = Spawner.SpawnList.GetRandom();
             PoolableObject clone   = PoolManager.GetNext(_PoolableAI, spawner.transform.position, Quaternion.identity, true);
             clone.GetComponent <Health>().SetTeamNumber(currentTeam);
         }
     }
 }
示例#8
0
    private void SpawnHands()
    {
        Vector3 center = transform.position;                                                            // the center of the circle is the player

        center.y += gameObject.transform.localScale.y * 0.5f;
        for (int i = 0; i < _numOfHands; i++)                                                           // for loop to spawn the hands
        {
            Vector3    position = RandCircleSpawn(center, _spawnRadius);                                // spawn the hands in a cirlce around the player
            Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, center - position);        // make the hands face away from the player
            PoolManager.GetNext(_hand, position, rotation);
            _hand.GetComponent <HandDamage>().Player = gameObject;
        }
        AkSoundEngine.PostEvent(_handSound, gameObject);
    }
    protected override IEnumerator Attack()
    {
        WaitForSeconds Wait = new WaitForSeconds(AttackDelay);

        yield return(Wait);

        while (Damageables.Count > 0)
        {
            for (int i = 0; i < Damageables.Count; i++)
            {
                if (HasLineOfSightTo(Damageables[i].GetTransform()))
                {
                    targetDamageable = Damageables[i];
                    OnAttack?.Invoke(Damageables[i]);
                    Agent.enabled = false;
                    break;
                }
            }

            if (targetDamageable != null)
            {
                PoolableObject poolableObject = BulletPool.GetObject();
                if (poolableObject != null)
                {
                    bullet = poolableObject.GetComponent <Bullet>();

                    bullet.Damage             = Damage;
                    bullet.transform.position = transform.position + BulletSpawnOffset;
                    bullet.transform.rotation = Agent.transform.rotation;
                    bullet.Rigidbody.AddForce(Agent.transform.forward * BulletPrefab.MoveSpeed, ForceMode.VelocityChange);
                }
            }
            else
            {
                Agent.enabled = true; // no target in line of sight, keep trying to get closer
            }

            yield return(Wait);

            if (targetDamageable == null || !HasLineOfSightTo(targetDamageable.GetTransform()))
            {
                Agent.enabled = true;
            }

            Damageables.RemoveAll(DisabledDamageables);
        }

        Agent.enabled   = true;
        AttackCoroutine = null;
    }
示例#10
0
    private void SpawnPowerUp()
    {
        int            index          = Random.Range(0, m_PowerUpPools.Length);
        PoolableObject poolableObject = m_PowerUpPools[index].GetObject();
        Vector3        pos            = GetRandomPos();

        while (DetectPlayer(pos))
        {
            pos = GetRandomPos();
        }
        poolableObject.SpawnObject(pos);

        m_ActivePowerUp = poolableObject.GetComponent <PowerUp>();
    }
示例#11
0
 private void SpawnEnemys(int ammount)
 {
     for (int i = 0; i < ammount; i++)
     {
         int index = Random.Range(0, m_SpawnPoints.Length);
         if (DetectPlayer(m_SpawnPoints[index]))
         {
             index = Random.Range(0, m_SpawnPoints.Length);
         }
         PoolableObject poolableObject = m_EnemiesPool.GetObject();
         poolableObject.SpawnObject(m_SpawnPoints[index]);
         m_EnemiesAlive.Add(poolableObject.GetComponent <Enemy>());
     }
 }
示例#12
0
    public void SetOrder(Order order)
    {
        currentOrder = order;
        maxTime      = order.remaingTime;

        for (int i = 0; i < order.itens.Count; i++)
        {
            PoolableObject itemImage = itemImagePool.Request();
            Image          img       = itemImage.GetComponent <Image>();
            img.sprite = order.itens[i].sprite;
            itemImage.transform.SetParent(itemHolder);

            itemImages.Add(itemImage);
        }

        timer.fillAmount = 1;
    }
示例#13
0
        public override void Spawn()
        {
            PoolableObject theObj     = GameManager.Pooling.UnpoolObject(theID);
            PoolableEnemy  objAsEnemy = theObj.GetComponent <PoolableEnemy> () as PoolableEnemy;

            //TODO: Why doesn't this line work???
            //objAsEnemy = theObj as PoolableEnemy;

            if (objAsEnemy.killableObject != null)
            {
                objAsEnemy.killableObject.RequestRevive();
            }

            objAsEnemy.transform.position = transform.position;

            SetData_EnemyShipMovement(objAsEnemy);
            SetData_EnemyShipFiring(objAsEnemy);
            SetData_ProjectileShooter(objAsEnemy);
        }
示例#14
0
    private IEnumerator SpawnMemorySlot()
    {
        while (true)
        {
            yield return(new WaitUntil(() => m_MaxMemorySlots > m_CurrentMemorySlotsAlive));

            yield return(new WaitForSeconds(10));

            int ammount = Random.Range(2, Mathf.RoundToInt(m_DataCubesToSpawn * 0.2f));
            for (int i = 0; i < ammount; i++)
            {
                if (m_CurrentMemorySlotsAlive < m_MaxMemorySlots)
                {
                    PoolableObject poolableObject = m_MemorySlotPool.GetObject();
                    poolableObject.SpawnObject(GetRandomPos());
                    MemorySlot memorySlot = poolableObject.GetComponent <MemorySlot>();
                    memorySlot.SetMB(Random.Range(5, 10));
                    m_CurrentMemorySlotsAlive++;
                }
            }
        }
    }
    private void DoSpawnEnemy(int SpawnIndex, Vector3 TilePosition)
    {
        PoolableObject poolableObject = EnemyObjectPools[SpawnIndex].GetObject();

        if (poolableObject != null)
        {
            Enemy enemy = poolableObject.GetComponent <Enemy>();
            Enemies[SpawnIndex].SetupEnemy(enemy);

            NavMeshHit Hit;
            Vector3    SamplePosition = TilePosition * TileSize +
                                        new Vector3(Random.Range(-TileSize / 2, TileSize / 2), 0, Random.Range(-TileSize / 2, TileSize / 2));
            if (NavMesh.SamplePosition(SamplePosition, out Hit, 5f, enemy.Agent.areaMask))
            {
                enemy.Agent.Warp(Hit.position);
                // enemy needs to get enabled and start chasing now.
                enemy.Movement.Player = Player;
                enemy.Agent.enabled   = true;
                enemy.Movement.Spawn();
                AliveEnemies.Add(enemy);
                enemy.OnDie += HandleEnemyDeath;
            }
            else
            {
                Debug.LogError($"Unable to place NavMeshAgent on NavMesh. Tried to spawn on tile {TilePosition} at World Location: {SamplePosition}");
                SpawnedEnemies--;
                SpawnedTiles.Remove(TilePosition);
                enemy.gameObject.SetActive(false);
            }
        }
        else
        {
            Debug.LogError($"Unable to fetch enemy of type {SpawnIndex} from object pool. Out of objects?");
            SpawnedEnemies--;
            SpawnedTiles.Remove(TilePosition);
        }
    }