zoukankan      html  css  js  c++  java
  • 音频控制

    // 此类别集成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();
            }
        }
    }
  • 相关阅读:
    Iaas、Paas、Saas对比分析
    一个不一样的Python教程
    传销的那些年
    availableProcessors is already set to [8], rejecting [8]
    脚本是个好东西
    《设计模式之禅》之桥梁模式
    博文视点之传奇程序员修炼之道观后感
    《设计模式之禅》之享元模式
    《设计模式之禅》之解释器模式
    Git修改commit提交信息
  • 原文地址:https://www.cnblogs.com/123ing/p/3836410.html
Copyright © 2011-2022 走看看