예제 #1
0
    public void CheckIfEnemyIsInRange(DynamicSound s)
    {
        List <Enemy> enemies = GetNearbyEnemies(s.maxEnemyDistance);

        foreach (Enemy enemy in enemies)
        {
            EnemyAwarenessSystem awarenessSystem = enemy.awarenessSystem;
            if (awarenessSystem.Awareness == awarenessSystem.MaxAwareness)
            {
                continue;
            }

            IList <Vector2> soundPath = NavMesh2D.instance.GetPathTo(enemy.transform.position, transform.position);
            if (soundPath == null)
            {
                return;
            }
            float distance = 0f;
            for (int i = 0; i < (soundPath.Count - 1); ++i)
            {
                distance += Vector2.Distance(soundPath[i], soundPath[i + 1]);
            }
            float awarenessIncrease = GetAwarenessIncrease(s.maxEnemyDistance, distance, awarenessSystem.soundReactionMultiplier, s.noise);
            awarenessSystem.Awareness += awarenessIncrease;

            if (awarenessSystem.Awareness > awarenessSystem.MaxAwareness)
            {
                awarenessSystem.Awareness = awarenessSystem.MaxAwareness;
            }
        }
    }
    public override void Play(string name)
    {
        DynamicSound s = GetDynamicSound(name);

        s.ConfigureAudioSource(audioSource);

        if (!audioSource.isPlaying)
        {
            audioSource.Play();
        }
        CheckIfEnemyIsInRange(s);
    }
예제 #3
0
    public override void Play(string name)
    {
        DynamicSound s = GetDynamicSound(name);

        if (s == null)
        {
            return;
        }
        s.ConfigureAudioSource(audioSource);

        if (!audioSource.loop)
        {
            audioSource.Play();
        }
        else if (!audioSource.isPlaying)
        {
            audioSource.Play();
        }
        CheckIfEnemyIsInRange(s);
    }
예제 #4
0
    public void Play2DClipAtPoint(string name, Vector2 position)
    {
        //  Create a temporary audio source object
        GameObject tempAudioSource = new GameObject("TempAudio");

        // Set Position
        tempAudioSource.transform.position = position;

        AudioSource audioSource = tempAudioSource.AddComponent <AudioSource>();

        DynamicSound s = GetDynamicSound(name);

        s.ConfigureAudioSource(audioSource);

        CheckIfEnemyIsInRange(s);

        if (!audioSource.loop || !audioSource.isPlaying)
        {
            audioSource.Play();
        }

        //  Set it to self destroy
        Destroy(tempAudioSource, s.clip.length);
    }
예제 #5
0
 public void AddSound(DynamicSound s)
 {
     sounds.Add(s);
 }
예제 #6
0
    public void SetupAudioSource(string name)
    {
        DynamicSound s = GetDynamicSound(name);

        s.ConfigureAudioSource(audioSource);
    }