• 音频控制


    // 此类别集成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();
            }
        }
    }
  • 相关阅读:
    hdu--4027--不错的线段树
    hdu--3275--线段树<again>
    hdu--2795--又是线段树
    hdu--4407--一不留神就TLE了
    zoj--3822--第二题概率dp
    hdu--3911--线段树<我最近爱上她了>
    hdu--1710--二叉树的各种遍历间的联系
    hdu--1712--分组背包<如果你真的明白了背包..>
    hdu--4576--概率dp<见过最简单的概率dp>
    list remove object
  • 原文地址:https://www.cnblogs.com/123ing/p/3836410.html
Copyright © 2020-2023  润新知