码迷,mamicode.com
首页 > 其他好文 > 详细

音频控制

时间:2014-07-16 20:56:38      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:des   blog   os   art   for   io   

// 此类别集成MonoBehaviour
[System.Serializable] public class AudioData { public AUDIO_TYPE m_AudioType; public AudioClip m_Clip; }
public class AudioManager : MonoBehaviour
{
    public List<AudioData> m_SoundList;
    public List<AudioData> m_BgList;
}
using System;
using System.Collections.Generic;
using UnityEngine;


public class AudioControl : MonoBehaviour
{
    private Dictionary<AUDIO_TYPE, AudioClip> m_AudioList = new Dictionary<AUDIO_TYPE, AudioClip>();
    
    void Start()
    {
        
        AudioManager am = GameObject.FindObjectOfType<AudioManager>();
        for (int i = 0; i < am.m_SoundList.Count; i++)
        {
            m_AudioList.Add(am.m_SoundList[i].m_AudioType, am.m_SoundList[i].m_Clip);
        }

        Destroy(GameObject.FindObjectOfType<AudioManager>().gameObject);

        
    }

    void OnGUI()
    {
        if (GUILayout.Button("播放1"))
        {
            Camera.main.GetComponent<AudioSource>().clip = m_AudioList[AUDIO_TYPE.AT_SCENE_BGM];
            Camera.main.GetComponent<AudioSource>().Play();
        }
        if (GUILayout.Button("播放2"))
        {
            Camera.main.GetComponent<AudioSource>().clip = m_AudioList[AUDIO_TYPE.AT_OPEN_UI];
            Camera.main.GetComponent<AudioSource>().Play();
        }
        if (GUILayout.Button("播放3"))
        {
            Camera.main.GetComponent<AudioSource>().clip = m_AudioList[AUDIO_TYPE.AT_UI_OPEN_CLOSE];
            Camera.main.GetComponent<AudioSource>().Play();
        }
        if (GUILayout.Button("播放4"))
        {
            Camera.main.GetComponent<AudioSource>().clip = m_AudioList[AUDIO_TYPE.AT_UI_WIDGET];
            Camera.main.GetComponent<AudioSource>().Play();
        }
    }
}

 

音频控制,布布扣,bubuko.com

音频控制

标签:des   blog   os   art   for   io   

原文地址:http://www.cnblogs.com/123ing/p/3836410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!