Ejemplo n.º 1
0
	/// <summary>
	/// The base level private method that plays
	/// a sound.  It creates a custom audio
	/// source that gives us more control over
	/// the sound.
	/// </summary>
	/// <returns>The sound.</returns>
	/// <param name="sound">Sound.</param>
	/// <param name="hashOverrides">Hash overrides.</param>
	private LgAudioSource PlaySound(DataSound sound, Hashtable hashOverrides){
		GameObject soundObject = new GameObject("Sound: " + sound.GetResourceName()); 
		LgAudioSource soundSource = soundObject.AddComponent<LgAudioSource>();
		soundSource.Init(sound, transform, hashOverrides);
		
		return soundSource;		
	}
Ejemplo n.º 2
0
    /// <summary>
    /// The base level private method that plays
    /// a sound.  It creates a custom audio
    /// source that gives us more control over
    /// the sound.
    /// </summary>
    private LgAudioSource PlaySound(DataSound sound, Hashtable option)
    {
        GameObject    soundObject = new GameObject("Sound: " + sound.GetResourceName());
        LgAudioSource soundSource = soundObject.AddComponent <LgAudioSource>();

        soundSource.Init(sound, transform, option);

        return(soundSource);
    }
Ejemplo n.º 3
0
    public void Init(DataSound sound, Transform tf, Hashtable option)
    {
        string    strResource = sound.GetResourceName();
        AudioClip clip        = Resources.Load(strResource) as AudioClip;

        if (clip == null)
        {
            Debug.LogError("No such sound clip for resource " + strResource);
            Destroy(gameObject);
            return;
        }

        audioClipName = strResource;

        // this is a little messy, but get variables that could be overriden
        float volume = sound.GetVolume();

        if (option.Contains("Volume"))
        {
            volume = (float)option["Volume"];
        }

        float pitch = sound.GetPitch();

        if (option.Contains("Pitch"))
        {
            pitch = (float)option["Pitch"];
        }
        bool loop = false;

        if (option.Contains("Loop"))
        {
            loop = (bool)option["Loop"];
        }

        // create the audio source
        audioSource                   = gameObject.AddComponent <AudioSource>();
        audioSource.clip              = clip;
        audioSource.volume            = volume;
        audioSource.pitch             = pitch;
        audioSource.loop              = loop;
        gameObject.transform.parent   = tf;
        gameObject.transform.position = tf.position;
        audioSource.Play();

        // add destroy script
        if (!loop)
        {
            DestroyThis scriptDestroy = gameObject.AddComponent <DestroyThis>();
            scriptDestroy.SetLife(clip.length);
        }
    }