Пример #1
0
    IEnumerator StateMainMenu()
    {
        if (debug)
        {
            Debug.Log("StateMainMenu");
        }

        // start main music track
        if (mainMusicTrack != null)
        {
            mainMusicTrack.Play(AudioManager.GetInstance().GetEmitter(gameObject, mainMusicTrack));
        }
        // instantiate main menu prefab (under canvas)
        var panelGo = Instantiate(mainMenuPrefab, GetCanvas().gameObject.transform);

        yield return(null);      // wait a frame for panel initialization

        // create listener for gameModeSelected event
        var selected = false;
        var listener = panelGo.AddComponent <GameEventListener>();

        listener.SetEvent(gameModeSelected);
        listener.Response.AddListener(() => { selected = true; });

        // wait for gameModeSelected event
        yield return(new WaitUntil(() => selected));

        Debug.Log("GameMode: " + gameInfo.gameMode);

        // clean up
        Destroy(panelGo);

        // transition StatePlayerSelect
        StartCoroutine(StatePlayerSelect());
    }
Пример #2
0
        // ===============================================================================
        // Play event with given clip name
        // ===============================================================================

        public void Play(AudioEvent audioEvent, string clipName = null, OnEndDelegate onChangeState = null)
        {
            Debug.Assert(audioEvent != null);

            state         = ESoundSourceState.Initial;
            OnChangeState = onChangeState;

            SoundSystem.Add(Link);
            audioEvent.Add(linkForEvent);

            Source.gameObject.SetActive(true);
            Source.outputAudioMixerGroup = audioEvent.MixerGroup;
            Source.priority            = 0;
            Source.mute                = false;
            Source.playOnAwake         = false;
            Source.ignoreListenerPause = true;
            Source.rolloffMode         = AudioRolloffMode.Linear;
            Source.minDistance         = 0f;
            Source.maxDistance         = 100000f;

            if (clipName == null)
            {
                audioEvent.Play(Source, false); // do not play, just set clip, pitch, volume
            }
            else
            {
                audioEvent.Play(Source, clipName, false); // do not play, just set clip, pitch, volume
            }
            EventName = audioEvent.name;
            ClipName  = Source.clip.name;
            Name      = $"SND:{EventName}#{ClipName}";
            ClipLen   = Source.clip.length;

            var clipLen05 = ClipLen * 0.5f;

            Is3D        = false;
            IsLooped    = audioEvent.IsLooped;
            IsPausable  = audioEvent.IsPausable;
            DelayTime   = audioEvent.DelayTime.Random;
            FadeInTime  = Mathf.Min(audioEvent.FadeInTime.Random, clipLen05);
            FadeOutTime = Mathf.Min(audioEvent.FadeOutTime.Random, clipLen05);

            DoFadeIn      = FadeInTime > 0;
            DoFadeOut     = FadeOutTime > 0;
            EventVolume   = audioEvent.Volume.Random;
            FadeVolume    = 0;
            FadeOutAtTime = ClipLen - FadeOutTime;
            Volume        = 1f;
            Play();
        }
Пример #3
0
 private void HandleVictoryState()
 {
     for (int i = 0; i < ReInput.players.playerCount; i++)
     {
         Player player = ReInput.players.GetPlayer(i);
         if (player.GetButtonDown("Start"))
         {
             confirmUIEvent.Play(uiAudioSource);
             OnPause();
             ClearRound();
             PrepareRound();
             gameManager.SetState(GameManager.GameState.Title);
         }
     }
 }
Пример #4
0
    private void Update()
    {
        if (moveWater && !FindObjectOfType <LevelManager>().gamePaused)
        {
            transform.localPosition = new Vector3(0, transform.localPosition.y + fillSpeed / 1000, 0);

            if (!audioPlaying)
            {
                startAudio = true;
            }
        }

        if (startAudio)
        {
            if (!_audioSource)
            {
                _audioSource = FindObjectOfType <SoundManager>().GetOpenAudioSource();
            }
            waterSound.Play(_audioSource);
            startAudio   = false;
            audioPlaying = true;
        }

        if (!audioPlaying)
        {
            if (_audioSource)
            {
                _audioSource.Stop();
            }
        }

        audioPlaying = moveWater;
    }
Пример #5
0
 void TryPlayingEvent(AudioEvent audioEvent)
 {
     if (audioEvent != null)
     {
         audioEvent.Play(true);
     }
 }
    void OnSetAvatarEditorVisibility(bool visible)
    {
        AudioScriptableObjects.listItemAppear.ResetPitch();

        if (visible)
        {
            if (musicFadeOut != null)
            {
                StopCoroutine(musicFadeOut);
                StartCoroutine(eventMusic.FadeIn(1f));
            }

            if (!eventMusic.source.isPlaying)
            {
                eventMusic.Play();
            }

            view.eyeColorSelector.OnColorChanged  += OnEyeColorChanged;
            view.skinColorSelector.OnColorChanged += OnSkinColorChanged;
            view.hairColorSelector.OnColorChanged += OnHairColorChanged;
            view.OnAvatarAppear += OnAvatarAppear;
        }
        else
        {
            musicFadeOut = eventMusic.FadeOut(2f);
            StartCoroutine(musicFadeOut);

            view.eyeColorSelector.OnColorChanged  -= OnEyeColorChanged;
            view.skinColorSelector.OnColorChanged -= OnSkinColorChanged;
            view.hairColorSelector.OnColorChanged -= OnHairColorChanged;
            view.OnAvatarAppear -= OnAvatarAppear;
        }
    }
Пример #7
0
    protected override void CompletionTracking()
    {
        base.CompletionTracking();

        if (isComplete && !FindObjectOfType <LeakSpawner>().firstCompleteSay)
        {
            FindObjectOfType <DialogManager>().DialogSayThis("Quick! Gotta pull the lever before something else goes wrong.", 5f);
            FindObjectOfType <LeakSpawner>().firstCompleteSay = true;
        }

        if (CompletionValue <= 0.25f && CompletionValue >= 0f)
        {
            if (!gushingPlaying)
            {
                gushingPlaying = true;
                audioSource    = FindObjectOfType <SoundManager>().GetOpenAudioSource();
                gushingSound.Play(audioSource, true);
            }
        }

        if (CompletionValue >= 0.25f)
        {
            if (gushingPlaying)
            {
                audioSource.Stop();
                gushingPlaying = false;
            }
        }

        animator.SetFloat("PatchPower", CompletionValue);
    }
Пример #8
0
    IEnumerator FireBullets(Vector3 _direction, int _damage, float _waitTime)
    {
        canFire = false;

        Vector3 _position = gunPoint.position;

        _position.z = 0;

        GameObject bullet = Instantiate(projectile, _position, Quaternion.identity);

        bullet.transform.up = _direction;
        bullet.GetComponent <Projectile>().FiringPoint     = gunPoint.position;
        bullet.GetComponent <Projectile>().projectileSpeed = projectileSpeed;
        bullet.GetComponent <Projectile>().damage          = CalculateDamage(); // calc before it gets here
        //bullet.GetComponent<Projectile>().projectileRange = weapon.Range;

        if (fireSound)
        {
            fireSound.Play(SoundManager.Instance.GetOpenAudioSource());
        }

        yield return(new WaitForSeconds(_waitTime));

        doubleDamage = false;
        if (doubleDamageInd)
        {
            doubleDamageInd.SetActive(false);
        }
        canFire = true;
    }
Пример #9
0
    public void Play(AudioEvent simpleAudioEvent)
    {
        var source = Get();

        source.outputAudioMixerGroup = simpleAudioEvent.MixerGroup;
        simpleAudioEvent.Play(source);
    }
Пример #10
0
 public void PlayMusic(AudioEvent audioEvent, bool force = false)
 {
     if (Music || force)
     {
         audioEvent.Play(sourceMusic);
     }
 }
Пример #11
0
 public void PlaySFX(AudioEvent audioEvent, bool force = false)
 {
     if (Sounds || force)
     {
         audioEvent.Play(sourceEffects);
     }
 }
Пример #12
0
 private void PlayAudioEvent(AudioEvent audioE, AudioSource audioS)
 {
     if (audioE != null && audioS != null)
     {
         audioE.Play(audioS);
     }
 }
Пример #13
0
    private IEnumerator SwitchAudio(AudioEvent e)
    {
        float time = 0.0f;

        if (m_source.isPlaying)
        {
            // Fade audio out
            while (time < m_fadeTime)
            {
                time           += Time.deltaTime;
                m_source.volume = 1.0f - Mathf.Clamp01(time / m_fadeTime);
                yield return(null);
            }
        }

        if (e != null)
        {
            // Play new audio, fade in
            e.Play(m_source);
            time = 0.0f;
            while (time < m_fadeTime)
            {
                time           += Time.deltaTime;
                m_source.volume = Mathf.Clamp01(time / m_fadeTime);
                yield return(null);
            }
        }
    }
Пример #14
0
    /**
     * Events
     */
    public static AudioEvent PlayEvent(string name)
    {
        AudioEvent e = GetEvent(name);

        e.Play();
        return(e);
    }
Пример #15
0
    void rbMotor()
    {
        if (rb == null)
        {
            return;
        }
        if (Mathf.Approximately(_forwardDrive, 0))
        {
            if (motorOn && motorSfx != null)
            {
                motorSfx.Stop(AudioManager.GetInstance().GetEmitter(rootGo, motorSfx));
            }
            motorOn = false;
            return;
        }
        if (!motorOn && motorSfx != null)
        {
            //motorSfx.Play(audio);
            motorSfx.Play(AudioManager.GetInstance().GetEmitter(rootGo, motorSfx));
        }
        motorOn = true;
        var f = maxTorque * _forwardDrive;

        if (reverse)
        {
            f = -f;
        }
        rb.maxAngularVelocity = maxSpeed;
        rb.AddTorque(transform.right * f);
    }
 void OnLand()
 {
     if (footstepLand != null)
     {
         footstepLand.Play(true);
     }
 }
Пример #17
0
    private IEnumerator PlayHeroResponse()
    {
        heroPositiveResponses.Play(friendly.GetComponent <AudioSource>());
        yield return(new WaitForSeconds(7));

        routine = null;
    }
Пример #18
0
    public void Hurt()
    {
        hitClip?.Play(Toolbox.Instance.Get <SoundKit>());
        // if (isDying) return;
        if (tween.isRunning())
        {
            tween.stop(true, true);
        }
        tween.initialize(tweenTarget, 0f, 0.2f);
        tween.setFrom(1.0f).start();

        if (--hp <= 0)
        {
            deathClip?.Play(Toolbox.Instance.Get <SoundKit>());
            // isDying = true;
            GameObject obj = Instantiate(snailDie, transform.position, Quaternion.identity);
            obj.transform.localScale = transform.localScale;

            if (tween.isRunning())
            {
                tween.stop(true, true);
            }
            Destroy(gameObject);
        }
        else
        {
            AddKnockback();
        }
    }
Пример #19
0
    private void Awake()
    {
        Health        health   = GetComponent <Health>();
        EnemyShooting shooting = GetComponent <EnemyShooting>();

        shooting.ShotFired += () => onShotFiredAudio.Play(audioSource);
    }
Пример #20
0
 void SimulateFootsteps()
 {
     if (!AvatarIsInView() && (blackBoard.movementSpeed / Time.deltaTime) > 1f && blackBoard.isGrounded)
     {
         if (Time.time >= nextFootstepTime)
         {
             if ((blackBoard.movementSpeed / Time.deltaTime) > 6f)
             {
                 if (footstepRun != null)
                 {
                     footstepRun.Play(true);
                 }
                 if (clothesRustleShort != null)
                 {
                     clothesRustleShort.Play(true);
                 }
                 nextFootstepTime = Time.time + RUN_INTERVAL_SEC;
             }
             else
             {
                 if (footstepWalk != null)
                 {
                     footstepWalk.Play(true);
                 }
                 if (clothesRustleShort != null)
                 {
                     clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
                 }
                 nextFootstepTime = Time.time + WALK_INTERVAL_SEC;
             }
         }
     }
 }
Пример #21
0
    private void Update()
    {
        if (Input.GetButtonUp("Jump"))
        {
            if (audioSource != null)
            {
                audioSource.Stop();
                audioSource = null;
            }

            if (animator.gameObject.activeSelf)
            {
                animator.SetBool("IsTorching", false);
                animator.gameObject.SetActive(false);
            }
        }

        if (Input.GetButton("Jump") && isTorchable)
        {
            if (audioSource == null)
            {
                audioSource      = FindObjectOfType <SoundManager>().GetOpenAudioSource();
                audioSource.loop = true;
                blowtorch.Play(audioSource);
            }

            animator.gameObject.SetActive(true);
            animator.SetBool("IsTorching", true);
        }
    }
Пример #22
0
    private void OnTriggerEnter(Collider other)
    {
        var destructible = other.gameObject.GetComponent <Destructible>();

        if (destructible == null)
        {
            return;
        }

        moving = false;

        if (!IsHitCrateFrontPanel(other))
        {
            falling = true;
            return;
        }

        int hitPoints = GetHitPoints(other.gameObject.transform.position.x) * spearPowerChargeEffects.GetPower();

        GameScore.score += hitPoints;

        CrateImpact.Play(audioSource);

        destructible.AddStuckProjectile(this);

        destructible.TakeDamage(hitPoints);
    }
Пример #23
0
    private void Update()
    {
        if (!canMove)
        {
            return;
        }

        PlayerInput();

        if (Time.time > nextMoveTime)
        {
            nextMoveTime = Time.time + moveInterval;

            if (doResetPlayerInput)
            {
                moveDir            = Vector2.zero;
                doResetPlayerInput = false;
                return;
            }

            if (moveDir != Vector2.zero)
            {
                if (moveSound)
                {
                    moveSound.Play(SoundManager.instance.GetOpenAudioSource());
                }

                transform.position = transform.position + (Vector3)moveDir;
                moveDir            = Vector2.zero;
            }
        }
    }
Пример #24
0
    private IEnumerator CountDown()
    {
        float time = 3;

        countDownText.gameObject.SetActive(true);

        while (true)
        {
            while (time > 0)
            {
                countDownText.text = time.ToString("0.0");

                time -= Time.deltaTime;

                yield return(null);
            }

            SpawnBall();
            audioSpawnBall.Play(audioSource);

            if (!multipleBalls)
            {
                countDownText.gameObject.SetActive(false);
                break;
            }

            time += 3;
        }
    }
Пример #25
0
 // Collision Enter 2D
 void OnCollisionEnter2D(Collision2D other)
 {
     if (impactAudio != null)
     {
         impactAudio.Play();
     }
 }
        public IEnumerator ProgressAndCompleteSequence()
        {
            Vector3 scale = progress.transform.localScale;

            if (Math.Abs(scale.x - progressTarget) > Mathf.Epsilon)
            {
                progressBarIncrementAudioEvent.Play();
            }
            while (Math.Abs(scale.x - progressTarget) > Mathf.Epsilon)
            {
                scale.x = Mathf.MoveTowards(scale.x, progressTarget, Time.deltaTime);
                progress.transform.localScale = scale;
                yield return(null);
            }
            if (progressTarget < 1)
            {
                yield break;
            }

            //Dont play completed animation if is already playing
            if (animator.GetCurrentAnimatorClipInfo(0).All(x => x.clip.name != TASK_COMPLETED_ANIMATION_NAME))
            {
                yield return(WaitForSecondsCache.Get(0.5f));

                animator.SetTrigger(COMPLETED_ANIMATOR_TRIGGER);
                taskCompleteAudioEvent.Play();
                yield return(null); // Wait for the animator to update its clipInfo
            }

            yield return(new WaitUntil(() => animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.95f));

            OnDestroyed?.Invoke(task.id);
            Destroy(gameObject);
        }
    // Use this for initialization
    void Start()
    {
        animator = GetComponent <Animator>();
        var audio = gameObject.GetComponent <AudioSource>();

        explosionAudioEvent.Play(audio);
    }
 void OnJump()
 {
     if (footstepJump != null)
     {
         footstepJump.Play(true);
     }
 }
Пример #29
0
    void DoTheDash()
    {
        doDash = false;
        Vector3 _dirFacing = GetComponentInChildren <FiringCtrl>().transform.right;

        var   rayStart = transform.position;
        var   rayDir   = _dirFacing;
        float rayDist  = dashDistance;

        Debug.DrawRay(rayStart, rayDir * rayDist, Color.green);

        RaycastHit2D[] hits = Physics2D.RaycastAll(rayStart, rayDir, rayDist, 1 << LayerMask.NameToLayer("Obstacle"));

        if (hits != null)
        {
            Debug.Log("Hits");
            foreach (RaycastHit2D hit in hits)
            {
                Debug.Log(hit.collider.name);

                Component damageableComponent = hit.collider.gameObject.GetComponent(typeof(IDamageable)); // nullable value

                if (damageableComponent)
                {
                    (damageableComponent as IDamageable).TakeDamage(10);
                }
            }
        }
        Instantiate(dashDisplay, transform.position, transform.transform.rotation);
        dashSound.Play(SoundManager.Instance.GetOpenAudioSource());
        Vector2 dashPos = transform.position + (_dirFacing * dashDistance);

        transform.position = dashPos;
    }
    public void Launch(GameObject target)
    {
        var entity = target.GetComponent <LivingEntity>();

        if (entity == null)
        {
            beamVisualEffect.targets[1] = null;
            return;
        }
        if (source != null)
        {
            if (fireAudioEvent != null)
            {
                fireAudioEvent.Play(source);
            }
        }
        if (ability != null)
        {
            ability.TriggerAbility(entity.gameObject, entity.centerPosition.transform.position);
        }
        beamVisualEffect.targets[0] = firePoint;
        beamVisualEffect.targets[1] = entity.centerPosition;
        beamVisualEffect.Play(false);
        float damage = owner.Damage.Value;

        entity.TakeDamage(damage);
    }