示例#1
0
    void CreateSoundObject()
    {
        SoundObj soundObj = GameObject.Instantiate(SoundObjPrefab).GetComponent <SoundObj>();

        soundObj.controller = this;
        SoundObjects.AddLast(soundObj);
    }
示例#2
0
    void Explode()
    {
        GameObject newSound = Instantiate(soundPrefab, hit.transform.position, hit.transform.rotation);

        if (smallExplosion != null)
        {
            SoundObj so = newSound.GetComponent <SoundObj>();
            if (so != null)
            {
                so.GotHit();
            }
        }
        else
        {
            Debug.Log("smallExplosion is null as");
        }
        GameObject explode = (GameObject)Instantiate(hitEffect, transform.position, transform.rotation);

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
        foreach (Collider nearbyObject in colliders)
        {
            Rigidbody rigi = nearbyObject.GetComponent <Rigidbody>();
            if (rigi != null)
            {
                if (rigi.gameObject.tag == "Player" && rigi.gameObject.name != objectToIgnore)
                {
                    PlayerDamage pd = rigi.gameObject.GetComponent <PlayerDamage>();
                    pd.TakeDamage(1f, toScore);
                }
            }
        }
        Destroy(explode, 0.5f);
    }
示例#3
0
 public void Update()
 {
     for (int idx = 0; idx < _soundList.Count; ++idx)
     {
         SoundObj obj = _soundList[idx];
         if (obj.IsUsing)
         {
             obj.Update(Time.deltaTime);
         }
     }
 }
示例#4
0
    private static void PlayClipAt(AudioClip clip, bool setPos = false, Vector3 pos = new Vector3())
    {
        var tempGO = new SoundObj("TempAudio - " + clip.name, instance?.parrentTransform);

        if (setPos)
        {
            tempGO.gameObject.transform.position = pos;
        }
        tempGO.aSource.PlayOneShot(clip);
        Destroy(tempGO.gameObject, clip.length);
    }
示例#5
0
    //------------------------------------------------------------------------------//
    #endregion



    #region Recording functions
    //------------------------------------------------------------------------------//
    public void RecordInitialize(SoundObj soundObj)
    {
        state          = State.recordInit;
        curRecSoundObj = soundObj;

        //if first recording, use metronome


        //with pickup, stop first everything
        GlobalTime.Instance.Stop();
        GlobalTime.Instance.Record();
    }
示例#6
0
    private void StopSound()
    {
        GameObject actor = GameObject.Find(Actor);

        AudioSource[] aSources = actor.GetComponents <AudioSource>();
        SoundObj      sound    = ObjectController.Get().GetObject <SoundObj>(ObjectCategories.Sound, Name);

        for (int i = 0; i < aSources.Length; ++i)
        {
            if (aSources[i].clip.name == sound.Sound.name)
            {
                aSources[i].Stop();
            }
        }
    }
示例#7
0
    public GameObject PlaySound(string path)
    {
        GameObject soundObj = new GameObject();

        soundObj.transform.parent        = _Instance.gameObject.transform;
        soundObj.transform.localPosition = Vector3.zero;
        soundObj.name = "SoundObj";
        AudioSource audioSource = soundObj.AddComponent <AudioSource>();

        audioSource.clip   = Resources.Load <AudioClip>(path);
        audioSource.volume = PlayerPrefs.GetFloat("OtherSoundVolume", 1);
        SoundObj soundCtr = soundObj.AddComponent <SoundObj>();

        soundCtr.AudioSource = audioSource;
        return(soundObj);
    }
示例#8
0
    IEnumerator WaitUntilFinishedStoringAudio()
    {
        curRecSoundObj.RecordFinish();

        Debug.Log("audio being stored");
        while (curRecSoundObj.state != SoundObj.State.audioSecured)
        {
            yield return(null);
        }

        Debug.Log("done storing audio");
        curRecSoundObj = null;

        GlobalTime.Instance.Play();

        state = State.ready;
    }
示例#9
0
    private SoundObj _getSoundObj()
    {
        SoundObj obj = null;

        for (int idx = 0; idx < _soundList.Count; ++idx)
        {
            if (!_soundList[idx].IsUsing)
            {
                obj = _soundList[idx];
                break;
            }
        }
        if (obj == null)
        {
            obj = new SoundObj();
            _soundList.Add(obj);
        }
        return(obj);
    }
示例#10
0
    private void PlaySound()
    {
        SoundObj   sound = ObjectController.Get().GetObject <SoundObj>(ObjectCategories.Sound, Name);
        GameObject actor = GameObject.Find(Actor);

        if (sound == null)
        {
            Debug.LogError("Cannot find sound: " + Name);
            //Debug.Break();
        }
        if (actor == null)
        {
            Debug.LogError("Cannot find actor: " + Actor);
            //Debug.Break();
        }

        try
        {
            Debug.Log("Within PlaySound try block");
            AudioSource aSource;

            if (actor.audio && !actor.audio.isPlaying)
            {
                aSource = actor.audio;
            }
            else
            {
                aSource = actor.AddComponent <AudioSource>();
            }

            aSource.loop = Loop;
            aSource.clip = sound.Sound;
            aSource.Play();
        }
        catch { } // We already know what this could be, we don't care, dev will get the warning in console already.
    }
示例#11
0
    public GameObject PlayBackground(string path)
    {
        GameObject soundObj = GameObject.Find("BackgroundSoundObj");

        if (soundObj != null)
        {
            return(soundObj);
        }
        soundObj = new GameObject();
        soundObj.transform.parent        = _Instance.gameObject.transform;
        soundObj.transform.localPosition = Vector3.zero;
        soundObj.name = "BackgroundSoundObj";
        DontDestroyOnLoad(soundObj);
        AudioSource audioSource = soundObj.AddComponent <AudioSource>();

        audioSource.clip   = Resources.Load <AudioClip>(path);
        audioSource.volume = PlayerPrefs.GetFloat("BGSoundVolume", 1);
        audioSource.loop   = true;
        SoundObj soundCtr = soundObj.AddComponent <SoundObj>();

        soundCtr.IsLoop      = true;
        soundCtr.AudioSource = audioSource;
        return(soundObj);
    }
示例#12
0
 public void AddSound(SoundObj sound)
 {
     Debug.Log("Adding: " + sound.Name);
     Sounds.Add(sound);
 }
示例#13
0
 public void AddSound(SoundObj sound)
 {
     Debug.Log("Adding: " + sound.Name);
     Sounds.Add(sound);
 }