Ejemplo n.º 1
0
        public CharacterTypeOfGameObject FindNearestOpponentGameObjectWithType()
        {
            float shortestSqrDist = float.MaxValue;
            CharacterTypeOfGameObject nearestChar = new CharacterTypeOfGameObject();

            foreach (CharacterTypeOfGameObject item in m_visibledCharWithType)
            {
                if (m_CharType == CharacterType.EnemyBoxer || m_CharType == CharacterType.EnemyGunner)
                {
                    if (item.TypeOfCharacter == CharacterType.Player || item.TypeOfCharacter == CharacterType.PlayerBoxerCampanion || item.TypeOfCharacter == CharacterType.PlayerGunnerCampanion)
                    {
                        if (nearestChar.characterGameObject == null)
                        {
                            nearestChar     = item;
                            shortestSqrDist = Vector3.SqrMagnitude(transform.position - nearestChar.characterGameObject.transform.position);
                            continue;
                        }
                        else
                        {
                            float sqrDist = Vector3.SqrMagnitude(transform.position - item.characterGameObject.transform.position);

                            if (sqrDist < shortestSqrDist)
                            {
                                shortestSqrDist = sqrDist;
                                nearestChar     = item;
                            }
                        }
                    }
                }
                else if (m_CharType == CharacterType.PlayerBoxerCampanion || m_CharType == CharacterType.PlayerGunnerCampanion)
                {
                    if (item.TypeOfCharacter == CharacterType.EnemyBoxer || item.TypeOfCharacter == CharacterType.EnemyGunner)
                    {
                        if (nearestChar.characterGameObject == null)
                        {
                            nearestChar     = item;
                            shortestSqrDist = Vector3.SqrMagnitude(transform.position - nearestChar.characterGameObject.transform.position);
                            continue;
                        }
                        else
                        {
                            float sqrDist = Vector3.SqrMagnitude(transform.position - item.characterGameObject.transform.position);

                            if (sqrDist < shortestSqrDist)
                            {
                                shortestSqrDist = sqrDist;
                                nearestChar     = item;
                            }
                        }
                    }
                }
            }

            return(nearestChar);
        }
Ejemplo n.º 2
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == this.transform.root.gameObject)
        {
            return;
        }

        if (other.CompareTag("Player"))
        {
            CharacterTypeOfGameObject         ch     = new CharacterTypeOfGameObject(other.gameObject, CharacterType.Player);
            CharacterTypeAndTimerOfGameObject chType = new CharacterTypeAndTimerOfGameObject(ch, 0f);
            m_aiManager.m_charWithTypeAndTimer.Add(chType);
        }
        else if (other.CompareTag("PlayerCampanion"))
        {
            if (other.gameObject.GetComponent <PlayerBoxerCampanion>() != null)
            {
                CharacterTypeOfGameObject         ch     = new CharacterTypeOfGameObject(other.gameObject, CharacterType.PlayerBoxerCampanion);
                CharacterTypeAndTimerOfGameObject chType = new CharacterTypeAndTimerOfGameObject(ch, 0f);
                m_aiManager.m_charWithTypeAndTimer.Add(chType);
            }
            else
            {
                CharacterTypeOfGameObject         ch     = new CharacterTypeOfGameObject(other.gameObject, CharacterType.PlayerGunnerCampanion);
                CharacterTypeAndTimerOfGameObject chType = new CharacterTypeAndTimerOfGameObject(ch, 0f);
                m_aiManager.m_charWithTypeAndTimer.Add(chType);
            }
        }
        else if (other.CompareTag("Enemy"))
        {
            if (other.gameObject.GetComponent <EnemyGunner>() != null)
            {
                CharacterTypeOfGameObject         ch     = new CharacterTypeOfGameObject(other.gameObject, CharacterType.EnemyGunner);
                CharacterTypeAndTimerOfGameObject chType = new CharacterTypeAndTimerOfGameObject(ch, 0f);
                m_aiManager.m_charWithTypeAndTimer.Add(chType);
            }
            else
            {
                CharacterTypeOfGameObject         ch     = new CharacterTypeOfGameObject(other.gameObject, CharacterType.EnemyBoxer);
                CharacterTypeAndTimerOfGameObject chType = new CharacterTypeAndTimerOfGameObject(ch, 0f);
                m_aiManager.m_charWithTypeAndTimer.Add(chType);
            }
        }
    }
Ejemplo n.º 3
0
        private void VisualPerception(CharacterTypeAndTimerOfGameObject item, string tag)
        {
            Vector3 dir = item.CharacterGameObjectWithType.characterGameObject.transform.position - transform.position;

            bool isVisible = CheckVisibility(dir, tag);

            if (isVisible)
            {
                if (item.VisibilityTimer >= m_AIVisibleTime)
                {
                    item.VisibilityTimer = m_AIVisibleTime;
                    return;
                }

                float vt = item.IncrementOrDecrementTimer(Time.deltaTime);

                if (m_visibledCharWithType.Contains(item.CharacterGameObjectWithType))
                {
                    return;
                }

                if (vt >= m_AIVisibleTime || dir.sqrMagnitude <= m_AIField.ThresoldViewRange * m_AIField.ThresoldViewRange)
                {
                    item.VisibilityTimer = m_AIVisibleTime;
                    m_visibledCharWithType.Add(item.CharacterGameObjectWithType);
                }
            }
            else
            {
                if (item.VisibilityTimer <= 0)
                {
                    item.VisibilityTimer = 0f;
                    return;
                }

                float vt = item.IncrementOrDecrementTimer(-Time.deltaTime);

                if (vt <= 0f)
                {
                    CharacterTypeOfGameObject chType = item.CharacterGameObjectWithType;
                    m_visibledCharWithType.Remove(chType);
                }
            }
        }
Ejemplo n.º 4
0
 public CharacterTypeAndTimerOfGameObject(CharacterTypeOfGameObject charType, float timer)
 {
     CharacterGameObjectWithType = charType;
     VisibilityTimer             = timer;
 }
Ejemplo n.º 5
0
    public void AddPlayerToCharaterList(GameObject gm, CharacterType typeChar)
    {
        CharacterTypeOfGameObject chGmType = new CharacterTypeOfGameObject(gm, typeChar);

        m_PlayerGameObjectWithType.Add(chGmType);
    }