示例#1
0
        protected override void Init()
        {
            base.Init();
            DontDestroyOnLoad(this);

            LoadAudioSettings();
            LoadAudioConfiguration();

            musicSource = AddAudioSource();
            soundSource = new List <AudioSource>();
            soundSource.Add(AddAudioSource());

            audioBlock       = new AudioBlock();
            delay            = 0;
            musicTrackVolume = 0;
            state            = AudioState.Default;
        }
        void OnGUI()
        {
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            Color defaultColor = GUI.color;

            GUILayout.Space(9);

            defaultSetting.DrawGUI();
            GUILayout.Space(12);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Audio configuration", EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Max sound source count", GUILayout.Width(180));
            soundSourceCount = EditorGUILayout.IntField(soundSourceCount, GUILayout.Width(120));
            if (soundSourceCount < 1)
            {
                soundSourceCount = 1;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Fade time", GUILayout.Width(180));
            fadeTime = EditorGUILayout.FloatField(fadeTime, GUILayout.Width(120));
            if (fadeTime < 0)
            {
                fadeTime = 0;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Use fade ON", GUILayout.Width(180));
            useFadeOn = EditorGUILayout.Toggle(useFadeOn, GUILayout.Width(120));
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(12);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("New Audio Block", GUILayout.Width(250)))
            {
                AudioBlock newBlock = new AudioBlock();
                newBlock.name = GetUniqueBlockName();
                audioData.Add(newBlock.name, newBlock);
            }
            EditorGUILayout.EndHorizontal();

            string removeKey = "";

            foreach (var item in audioData)
            {
                GUILayout.Space(12);
                AEditorTool.DrawSeparator(AEditorTool.SeparationStyle.BigDark);

                var block = item.Value;

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Audio Block Name:");
                if (GUILayout.Button("Remove", GUILayout.Width(60)))
                {
                    removeKey = item.Key;
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                string name = block.name;
                name = EditorGUILayout.TextField(name, GUILayout.MinWidth(100), GUILayout.MaxWidth(250));
                if (audioData.ContainsKey(name) && audioData[name] != block)
                {
                    name = GetUniqueBlockName(name);
                }
                block.name = name;
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(12);

                EditorGUILayout.BeginHorizontal();
                GUI.color = Color.green;
                EditorGUILayout.LabelField("Music:");
                GUI.color = defaultColor;
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Delay between musics", GUILayout.Width(150));
                block.music.delay = EditorGUILayout.FloatField(block.music.delay, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Not reply length", GUILayout.Width(150));
                block.music.musicNotReplyCount = EditorGUILayout.IntField(block.music.musicNotReplyCount, GUILayout.Width(40));
                if (block.music.musicNotReplyCount < 0)
                {
                    block.music.musicNotReplyCount = 0;
                }
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(6);

                DrawTrackList(block.music, true);
                GUILayout.Space(6);

                EditorGUILayout.BeginHorizontal();
                GUI.color = Color.green;
                EditorGUILayout.LabelField("Sound:");
                GUI.color = defaultColor;
                EditorGUILayout.EndHorizontal();

                DrawTrackList(block.sound, false);
            }

            if (removeKey != "")
            {
                audioData.Remove(removeKey);
            }


            GUILayout.Space(12);
            if (GUILayout.Button("Save"))
            {
                SaveConfiguration(true);
                SaveNamesInCode();
            }
            GUILayout.Space(20);
            EditorGUILayout.EndScrollView();
        }