Example #1
0
 public AudioSubItem(AudioSubItem orig, AudioItem item)
 {
     SubItemType = orig.SubItemType;
     if (SubItemType == AudioSubItemType.Clip)
     {
         Clip = orig.Clip;
     }
     else if (SubItemType == AudioSubItemType.Item)
     {
         ItemModeAudioID = orig.ItemModeAudioID;
     }
     Probability          = orig.Probability;
     DisableOtherSubitems = orig.DisableOtherSubitems;
     Clip                = orig.Clip;
     Volume              = orig.Volume;
     PitchShift          = orig.PitchShift;
     Pan2D               = orig.Pan2D;
     Delay               = orig.Delay;
     RandomPitch         = orig.RandomPitch;
     RandomVolume        = orig.RandomVolume;
     RandomDelay         = orig.RandomDelay;
     ClipStopTime        = orig.ClipStopTime;
     ClipStartTime       = orig.ClipStartTime;
     FadeIn              = orig.FadeIn;
     FadeOut             = orig.FadeOut;
     RandomStartPosition = orig.RandomStartPosition;
     for (var index = 0; index < orig.IndividualSettings.Count; ++index)
     {
         IndividualSettings.Add(orig.IndividualSettings[index]);
     }
     Item = item;
 }
    private string[] GetSubitemNames()
    {
        AudioItem curItem = currentItem;

        if (curItem == null || curItem.subItems == null)
        {
            return(new string[0]);
        }

        var names = new string[curItem.subItems.Length];

        for (int i = 0; i < curItem.subItems.Length; i++)
        {
            AudioSubItemType subitemType = curItem.subItems[i] != null ? curItem.subItems[i].SubItemType : AudioSubItemType.Clip;

            if (subitemType == AudioSubItemType.Item)
            {
                names[i] = string.Format("ITEM {0}: {1}", i, (curItem.subItems[i].ItemModeAudioID ?? "*undefined*"));
            }
            else
            {
                names[i] = string.Format("CLIP {0}: {1}", i, (curItem.subItems[i] != null ? curItem.subItems[i].Clip ? curItem.subItems[i].Clip.name : "*unset*" : ""));
            }
        }
        return(names);
    }
Example #3
0
    private static Boolean _IsValidSubItem(AudioSubItem item)
    {
        AudioSubItemType subItemType = item.SubItemType;

        if (subItemType != AudioSubItemType.Clip)
        {
            return(subItemType == AudioSubItemType.Item && item.ItemModeAudioID != null && item.ItemModeAudioID.Length > 0);
        }
        return(item.Clip != null);
    }
    public override void OnInspectorGUI()
    {
        SetStyles();

        BeginInspectorGUI();

        AC = (AudioController)target;

        _ValidateCurrentItemIndex();
        _ValidateCurrentSubItemIndex();

        if (lastCategoryIndex != currentCategoryIndex ||
            lastItemIndex != currentItemIndex ||
            lastSubItemIndex != currentSubitemIndex)
        {
            GUIUtility.keyboardControl = 0; // workaround for Unity weirdness not changing the value of a focused GUI element when changing a category/item
            lastCategoryIndex          = currentCategoryIndex;
            lastItemIndex    = currentItemIndex;
            lastSubItemIndex = currentSubitemIndex;
        }



        EditorGUILayout.Space();

        if (globalFoldout = EditorGUILayout.Foldout(globalFoldout, "Global Audio Settings", foldoutStyle))
        {
            AC.DisableAudio = GetBool(AC.DisableAudio, "Disable Audio");
            AC.Volume       = GetFloat01(AC.Volume, "Volume", "%");
            EditPrefab(ref AC.AudioObjectPrefab, "Audio Object Prefab");
            EditBool(ref AC.UsePooledAudioObjects, "Use Pooled AudioObjects");
            EditBool(ref AC.PlayWithZeroVolume, "Play With Zero Volume");
        }

        VerticalSpace();

        // playlist specific
        if (playlistFoldout = EditorGUILayout.Foldout(playlistFoldout, "Music & Playlist Settings", foldoutStyle))
        {
            EditorGUILayout.BeginHorizontal();
            currentPlaylistIndex = Popup("Playlist", currentPlaylistIndex, GetPlaylistNames());
            if (GUILayout.Button("Up", GUILayout.Width(35)) && AC.musicPlaylist != null && AC.musicPlaylist.Length > 0)
            {
                if (SwapArrayElements(AC.musicPlaylist, currentPlaylistIndex, currentPlaylistIndex - 1))
                {
                    currentPlaylistIndex--;
                    KeepChanges();
                }
            }
            if (GUILayout.Button("Dwn", GUILayout.Width(40)) && AC.musicPlaylist != null && AC.musicPlaylist.Length > 0)
            {
                if (SwapArrayElements(AC.musicPlaylist, currentPlaylistIndex, currentPlaylistIndex + 1))
                {
                    currentPlaylistIndex++;
                    KeepChanges();
                }
            }
            if (GUILayout.Button("-", GUILayout.Width(25)) && AC.musicPlaylist != null && AC.musicPlaylist.Length > 0)
            {
                DeleteArrayElement(ref AC.musicPlaylist, currentPlaylistIndex);
                currentPlaylistIndex = Mathf.Clamp(currentPlaylistIndex - 1, 0, AC.musicPlaylist.Length - 1);
                KeepChanges();
            }

            EditorGUILayout.EndHorizontal();

            string itemToAdd = _ChooseItem("Add to Playlist");
            if (!string.IsNullOrEmpty(itemToAdd))
            {
                AddToPlayList(itemToAdd);
            }

            EditBool(ref AC.loopPlaylist, "Loop Playlist");
            EditBool(ref AC.shufflePlaylist, "Shuffle Playlist");
            EditBool(ref AC.crossfadePlaylist, "Crossfade Playlist");
            EditFloat(ref AC.musicCrossFadeTime, "Music Crossfade Time", "sec");
            EditFloat(ref AC.delayBetweenPlaylistTracks, "Delay Betw. Playlist Tracks", "sec");
        }

        VerticalSpace();

        int categoryCount = AC.AudioCategories != null ? AC.AudioCategories.Length : 0;

        currentCategoryIndex = Mathf.Clamp(currentCategoryIndex, 0, categoryCount - 1);

        if (categoryFoldout = EditorGUILayout.Foldout(categoryFoldout, "Category Settings", foldoutStyle))
        {
            // Audio Items
            EditorGUILayout.BeginHorizontal();

            bool justCreatedNewCategory = false;

            int newCategoryIndex = Popup("Category", currentCategoryIndex, GetCategoryNames(), popupStyleColored);
            if (GUILayout.Button("+", GUILayout.Width(30)))
            {
                bool lastEntryIsNew = false;

                if (categoryCount > 0)
                {
                    lastEntryIsNew = AC.AudioCategories[currentCategoryIndex].Name == "???";
                }

                if (!lastEntryIsNew)
                {
                    newCategoryIndex = AC.AudioCategories != null ? AC.AudioCategories.Length : 0;
                    AddArrayElement(ref AC.AudioCategories);
                    AC.AudioCategories[newCategoryIndex].Name = "???";
                    justCreatedNewCategory = true;
                    KeepChanges();
                }
            }

            if (GUILayout.Button("-", GUILayout.Width(30)) && categoryCount > 0)
            {
                if (currentCategoryIndex < AC.AudioCategories.Length - 1)
                {
                    newCategoryIndex = currentCategoryIndex;
                }
                else
                {
                    newCategoryIndex = Mathf.Max(currentCategoryIndex - 1, 0);
                }
                DeleteArrayElement(ref AC.AudioCategories, currentCategoryIndex);
                KeepChanges();
            }

            EditorGUILayout.EndHorizontal();

            if (newCategoryIndex != currentCategoryIndex)
            {
                currentCategoryIndex = newCategoryIndex;
                currentItemIndex     = 0;
                currentSubitemIndex  = 0;
                _ValidateCurrentItemIndex();
                _ValidateCurrentSubItemIndex();
            }


            AudioCategory curCat = currentCategory;

            if (curCat != null)
            {
                if (justCreatedNewCategory)
                {
                    SetFocusForNextEditableField();
                }
                EditString(ref curCat.Name, "Name");
                curCat.Volume = GetFloat01(curCat.Volume, "Volume", " %");
                EditPrefab(ref curCat.AudioObjectPrefab, "Audio Object Prefab Override");

                int itemCount = currentItemCount;
                _ValidateCurrentItemIndex();

                /*if ( GUILayout.Button( "Add all items in this category to playlist" ) )
                 * {
                 *  for ( int i = 0; i < itemCount; i++ )
                 *  {
                 *      AddArrayElement( ref AC.musicPlaylist, curCat.AudioItems[i].Name );
                 *  }
                 *  currentPlaylistIndex = AC.musicPlaylist.Length - 1;
                 *  KeepChanges();
                 * }*/

                VerticalSpace();

                AudioItem curItem = currentItem;

                if (itemFoldout = EditorGUILayout.Foldout(itemFoldout, "Audio Item Settings", foldoutStyle))
                {
                    // AudioItems

                    EditorGUILayout.BeginHorizontal();

                    int  newItemIndex       = Popup("Item", currentItemIndex, GetItemNames(), popupStyleColored);
                    bool justCreatedNewItem = false;


                    if (GUILayout.Button("+", GUILayout.Width(30)))
                    {
                        bool lastEntryIsNew = false;

                        if (itemCount > 0)
                        {
                            lastEntryIsNew = curCat.AudioItems[currentItemIndex].Name == "???";
                        }

                        if (!lastEntryIsNew)
                        {
                            newItemIndex = curCat.AudioItems != null ? curCat.AudioItems.Length : 0;
                            AddArrayElement(ref curCat.AudioItems);
                            curCat.AudioItems[newItemIndex].Name = "???";
                            justCreatedNewItem = true;
                            KeepChanges();
                        }
                    }

                    if (GUILayout.Button("-", GUILayout.Width(30)) && itemCount > 0)
                    {
                        if (currentItemIndex < curCat.AudioItems.Length - 1)
                        {
                            newItemIndex = currentItemIndex;
                        }
                        else
                        {
                            newItemIndex = Mathf.Max(currentItemIndex - 1, 0);
                        }
                        DeleteArrayElement(ref curCat.AudioItems, currentItemIndex);
                        KeepChanges();
                    }



                    if (newItemIndex != currentItemIndex)
                    {
                        currentItemIndex    = newItemIndex;
                        currentSubitemIndex = 0;
                        _ValidateCurrentSubItemIndex();
                    }

                    curItem = currentItem;

                    EditorGUILayout.EndHorizontal();

                    if (curItem != null)
                    {
                        GUILayout.BeginHorizontal();
                        if (justCreatedNewItem)
                        {
                            SetFocusForNextEditableField();
                        }
                        EditString(ref curItem.Name, "Name");

                        /*if ( GUILayout.Button( "Add to playlist" ) )
                         * {
                         *  AddToPlayList( curItem.Name );
                         * }*/

                        GUILayout.EndHorizontal();

                        EditFloat01(ref curItem.Volume, "Volume", " %");
                        EditFloat(ref curItem.Delay, "Delay", "sec");
                        EditFloat(ref curItem.MinTimeBetweenPlayCalls, "Min Time Between Play", "sec");
                        EditInt(ref curItem.MaxInstanceCount, "Max Instance Count");

                        EditBool(ref curItem.DestroyOnLoad, "Stop When Scene Loads");
                        EditBool(ref curItem.Loop, "Loop");

                        curItem.SubItemPickMode = (AudioPickSubItemMode)EnumPopup("Pick Subitem Mode", curItem.SubItemPickMode);

                        //EditString( ref curItem.PlayAdditional, "Play Additional" );
                        //EditString( ref curItem.PlayInstead, "Play Instead" );

                        EditorGUILayout.BeginHorizontal();

                        if (GUILayout.Button("Play", GUILayout.Width(60)) && curItem != null)
                        {
                            if (EditorApplication.isPlaying && AudioController.DoesInstanceExist())
                            {
                                AudioController.Play(curItem.Name);
                            }
                            else
                            {
                                if (Application.platform == RuntimePlatform.OSXEditor)
                                {
                                    Debug.Log(_playNotSupportedOnMac);
                                }
                                else
                                {
                                    AC.InitializeAudioItems();
                                    Debug.Log(_playWithInspectorNotice);
                                    AC.PlayAudioItem(curItem, 1, Vector3.zero, null, 0, 0, true);
                                }
                            }
                        }

                        if (GUILayout.Button("Add selected audio clips", EditorStyles.miniButton))
                        {
                            AudioClip[] audioClips = GetSelectedAudioclips();
                            if (audioClips.Length > 0)
                            {
                                int firstIndex = itemCount;
                                currentItemIndex = firstIndex;
                                foreach (AudioClip audioClip in audioClips)
                                {
                                    AddArrayElement(ref curCat.AudioItems);
                                    AudioItem audioItem = curCat.AudioItems[currentItemIndex];
                                    audioItem.Name = audioClip.name;
                                    AddArrayElement(ref audioItem.subItems).Clip = audioClip;
                                    currentItemIndex++;
                                }
                                currentItemIndex = firstIndex;
                                KeepChanges();
                            }
                        }

                        GUILayout.Label("use inspector lock!");
                        EditorGUILayout.EndHorizontal();

                        VerticalSpace();

                        int subItemCount = curItem.subItems != null ? curItem.subItems.Length : 0;
                        currentSubitemIndex = Mathf.Clamp(currentSubitemIndex, 0, subItemCount - 1);
                        AudioSubItem subItem = currentSubItem;

                        if (subitemFoldout = EditorGUILayout.Foldout(subitemFoldout, "Audio Sub-Item Settings", foldoutStyle))
                        {
                            EditorGUILayout.BeginHorizontal();

                            currentSubitemIndex = Popup("SubItem", currentSubitemIndex, GetSubitemNames(), popupStyleColored);

                            if (GUILayout.Button("+", GUILayout.Width(30)))
                            {
                                bool lastEntryIsNew = false;

                                AudioSubItemType curSubItemType = AudioSubItemType.Clip;

                                if (subItemCount > 0)
                                {
                                    curSubItemType = curItem.subItems[currentSubitemIndex].SubItemType;
                                    if (curSubItemType == AudioSubItemType.Clip)
                                    {
                                        lastEntryIsNew = curItem.subItems[currentSubitemIndex].Clip == null;
                                    }
                                    if (curSubItemType == AudioSubItemType.Item)
                                    {
                                        lastEntryIsNew = curItem.subItems[currentSubitemIndex].ItemModeAudioID == null ||
                                                         curItem.subItems[currentSubitemIndex].ItemModeAudioID.Length == 0;
                                    }
                                }

                                if (!lastEntryIsNew)
                                {
                                    currentSubitemIndex = subItemCount;
                                    AddArrayElement(ref curItem.subItems);
                                    curItem.subItems[currentSubitemIndex].SubItemType = curSubItemType;
                                    KeepChanges();
                                }
                            }

                            if (GUILayout.Button("-", GUILayout.Width(30)) && subItemCount > 0)
                            {
                                DeleteArrayElement(ref curItem.subItems, currentSubitemIndex);
                                if (currentSubitemIndex >= curItem.subItems.Length)
                                {
                                    currentSubitemIndex = Mathf.Max(curItem.subItems.Length - 1, 0);
                                }
                                KeepChanges();
                            }
                            EditorGUILayout.EndHorizontal();

                            subItem = currentSubItem;

                            if (subItem != null)
                            {
                                _SubitemTypePopup(subItem);


                                if (subItem.SubItemType == AudioSubItemType.Item)
                                {
                                    _DisplaySubItem_Item(subItem);
                                }
                                else
                                {
                                    _DisplaySubItem_Clip(subItem, subItemCount, curItem);
                                }
                            }
                        }
                    }
                }
            }
        }

        VerticalSpace();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Show Audio Log"))
        {
            var win = EditorWindow.GetWindow(typeof(AudioLogView));
            win.Show();
        }

        if (GUILayout.Button("Show Item Overview"))
        {
            AudioItemOverview win = EditorWindow.GetWindow(typeof(AudioItemOverview)) as AudioItemOverview;
            win.Show(AC);
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        if (EditorApplication.isPlaying)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Stop All Sounds"))
            {
                if (EditorApplication.isPlaying && AudioController.DoesInstanceExist())
                {
                    AudioController.StopAll();
                }
            }
            if (GUILayout.Button("Stop Music Only"))
            {
                if (EditorApplication.isPlaying && AudioController.DoesInstanceExist())
                {
                    AudioController.StopMusic();
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();
        GUILayout.Label("----- ClockStone Audio Toolkit v3.3 -----  ", centeredTextStyle);

        EndInspectorGUI();

        //Debug.Log( "currentCategoryIndex: " + currentCategoryIndex );
    }