Exemplo n.º 1
0
    private void _SubitemTypePopup(AudioSubItem subItem)
    {
        var typeNames = new string[2];

        typeNames[0] = "Single Audio Clip";
        typeNames[1] = "Other Audio Item";

        int curIndex = 0;

        switch (subItem.SubItemType)
        {
        case AudioSubItemType.Clip: curIndex = 0; break;

        case AudioSubItemType.Item: curIndex = 1; break;
        }

        switch (Popup("SubItem Type", curIndex, typeNames))
        {
        case 0: subItem.SubItemType = AudioSubItemType.Clip; break;

        case 1: subItem.SubItemType = AudioSubItemType.Item; break;
        }

        //subItem.SubItemType = (AudioSubItemType) EnumPopup( "SubItem Type", subItem.SubItemType );
    }
Exemplo n.º 2
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);
    }
    private static bool _IsValidSubItem(AudioSubItem item)
    {
        switch (item.SubItemType)
        {
        case AudioSubItemType.Clip:
            return(item.Clip != null);

        case AudioSubItemType.Item:
            return(item.ItemModeAudioID != null && item.ItemModeAudioID.Length > 0);
        }
        return(false);
    }
Exemplo n.º 4
0
 internal void _CreateGaplessAudioClipTransition(AudioSubItem subItem)
 {
     if (_audioTransition == null)
     {
         _audioTransition = new GaplessAudioClipTransition(subItem.Clip, null);   // nextClip will be set later, this way it can not be null
         _audioTransition.onTransitionCallback = _OnGaplessAudioTransition;
     }
     else
     {
         _audioTransition.currentClip = subItem.Clip;
     }
     _SetNextClipForGaplessLoop();
     audio.clip = _audioTransition.CreateOutputClip(subItem.Clip.channels, subItem.Clip.frequency, true);
 }
Exemplo n.º 5
0
        public static AudioObject PlayWithProbabilityOfFirstItem(String p_AudioID, Transform p_Transform, Single p_volume, Single p_delay, Single p_startTime)
        {
            AudioItem audioItem = AudioController.GetAudioItem(p_AudioID);

            if (audioItem != null && audioItem.subItems.Length > 0)
            {
                AudioSubItem audioSubItem = audioItem.subItems[0];
                if (audioSubItem.Probability >= Random.Value)
                {
                    return(AudioController.Play(p_AudioID, p_Transform, p_volume, p_delay, p_startTime));
                }
            }
            else
            {
                Debug.LogError("Could not find Audio for AudioID=" + p_AudioID);
            }
            return(null);
        }
Exemplo n.º 6
0
 /*
  *  Function: Sets starting data for this AudioObject
  *  Parameter: iInstanceId id of this instance
  *  Parameter: pAudioSubItem related AudioItem
  *  Parameter: fVolume to set in this AudioObject
  *  Return: None
  */
 public void InitializeAudioObject(int iInstanceId, AudioSubItem pAudioSubItem, float fVolume)
 {
     if (pAudioSubItem.RelatedAudioItem.mustShowDebugInfo)
     {
         Debug.Log("Initialize AO with Volume[" + fVolume + "]");
     }
     name               = "AO_" + pAudioSubItem.RelatedAudioItem.relatedCategory.categoryId + "_" + pAudioSubItem.RelatedAudioItem.itemId;
     instanceId         = iInstanceId;
     currentSubItem     = pAudioSubItem;
     currentClip.clip   = null;
     currentClip.clip   = currentSubItem.audioClip;
     realVolume         = fVolume * currentSubItem.volume;
     volume             = realVolume;
     currentClip.volume = volume;
     currentClip.loop   = mustLoop;
     isPaused           = false;
     isPlaying          = false;
 }
    /// <summary>
    /// Copy constructor
    /// </summary>
    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 (int i = 0; i < orig.individualSettings.Count; ++i)
        {
            individualSettings.Add(orig.individualSettings[i]);
        }

        this.item = item;
    }
Exemplo n.º 8
0
    private void _DisplaySubItem_Item(AudioSubItem subItem)
    {
        EditFloat01(ref subItem.Probability, "Probability", " %");
        int audioIndex = 0;

        string[] possibleAudioIDs = _GetPossibleAudioIDs(false, "*undefined*");
        string[] possibleAudioIDs_withCategory = _GetPossibleAudioIDs(true, "*undefined*");

        if (subItem.ItemModeAudioID != null && subItem.ItemModeAudioID.Length > 0)
        {
            string idToSearch = subItem.ItemModeAudioID.ToLowerInvariant();

            for (int i = 1; i < possibleAudioIDs.Length; i++)
            {
                if (possibleAudioIDs[i].ToLowerInvariant() == idToSearch)
                {
                    audioIndex = i; break;
                }
            }
        }

        bool wasUndefinedBefore = (audioIndex == 0);

        audioIndex = Popup("AudioItem", audioIndex, possibleAudioIDs_withCategory);
        if (audioIndex > 0)
        {
            subItem.ItemModeAudioID = possibleAudioIDs[audioIndex];
        }
        else
        {
            if (!wasUndefinedBefore)
            {
                subItem.ItemModeAudioID = null;
            }
        }
    }
Exemplo n.º 9
0
    /*
     *  Function: Picks AudioSubItem to play, and creates the AudioObject based on the prefab passed
     *  Parameter: transformParent is the new parent of the AudioObject if provided
     *  Parameter: v3Point is the local position of the created AudioObject
     *  Parameter: fVolume to be passed to the AudioObject
     *  Parameter: pPrefab that will be used as instance for this AudioObject
     *  Return: AudioObject created to play this sound if successfull
     */
    public AudioObject Play(Transform transformParent, Vector3 v3Point, float fVolume, ref AudioObject pPrefab)
    {
        float fTimeElapsedSinceLastPlay = Time.realtimeSinceStartup - lastTimePlayed;

        if (mustShowDebugInfo)
        {
            Debug.Log("LastTimePlayed[" + lastTimePlayed + "] TimeELapsed[" + fTimeElapsedSinceLastPlay + "] MinTime[" + minTimeBetweenPlay + "] Volume[" + fVolume + "]");
        }
        if (fTimeElapsedSinceLastPlay >= minTimeBetweenPlay || minTimeBetweenPlay <= 0.0f)
        {
            AudioObject ao = null;
            if (subItemsList.Count > 0)
            {
                if (pPrefab != null)
                {
                    AudioSubItem asiSubItem = null;
                    //pick subitem
                    switch (subItemPickMode)
                    {
                    case SubItemPickMode.Unique:
                        asiSubItem = subItemsList[0];
                        break;

                    case SubItemPickMode.Random:
                        asiSubItem = subItemsList[UnityEngine.Random.Range(0, subItemsList.Count)];
                        break;

                    case SubItemPickMode.Ordered:
                        asiSubItem = subItemsList[currentIndex];
                        AdvanceIndex(true);
                        break;

                    case SubItemPickMode.InverseOrdered:
                        asiSubItem = subItemsList[currentIndex];
                        AdvanceIndex(false);
                        break;

                    default: break;
                    }

                    if (asiSubItem != null)
                    {
                        asiSubItem.SetAudioItem(this);
                    }

                    if (relatedCategory.onlyOneItemAllowed)
                    {
                        if (mustShowDebugInfo)
                        {
                            Debug.Log("Stopping all audios in category[" + relatedCategory.categoryId + "] because only one is allowed and will give chance for a new [" + itemId + "] audio.");
                        }
                        relatedCategory.StopAllAudios();
                    }

                    float itemVolume = fVolume * volume;
                    //substitute for pool manager function
                    if (ServiceLocator.Instance.GetServiceOfType <BaseAudioManager>(SERVICE_TYPE.AUDIOMANAGER).usePooledAudioObjects)
                    {
                        PoolableObject apo = ServiceLocator.Instance.GetServiceOfType <BasePoolManager>(SERVICE_TYPE.POOLMANAGER).Spawn("AM_" + relatedCategory.categoryId);
                        if (apo != null)
                        {
                            ao = ((AudioPooledObject)apo).audioObjReference;
                            if (ao != null)
                            {
                                ao.OnAudioStarted = OnAudioStarted;
                                ao.OnAudioStopped = OnAudioStopped;
                                ao.InitializeAudioObject(AudioManager.audioObjInstanceCounter, asiSubItem, itemVolume);

                                AudioManager.audioObjInstanceCounter++;
                                ao.CachedTransform.parent        = transformParent;
                                ao.CachedTransform.localPosition = v3Point;
                                lastTimePlayed = Time.realtimeSinceStartup;
                                ao.Play();
                                RegisterAudioObject(ao);
                            }
                            else
                            {
                                if (mustShowDebugInfo)
                                {
                                    Debug.LogWarning("There are no AudioObject reference on PooledAudioObject when playing Item[" + itemId + "]");
                                }
                            }
                        }
                        else
                        {
                            if (mustShowDebugInfo)
                            {
                                Debug.LogWarning("There are no AudioObject Prefab instance availbale in the pool to play Item[" + itemId + "] in category[AM_" + relatedCategory.categoryId + "]");
                            }
                        }
                    }
                    else
                    {
                        ao = GameObject.Instantiate(pPrefab) as AudioObject;
                        if (ao != null)
                        {
                            ao.InitializeAudioObject(AudioManager.audioObjInstanceCounter, asiSubItem, itemVolume);
                            AudioManager.audioObjInstanceCounter++;
                            ao.CachedTransform.parent        = transformParent;
                            ao.CachedTransform.localPosition = v3Point;
                            lastTimePlayed = Time.realtimeSinceStartup;
                            RegisterAudioObject(ao);
                            ao.Play();
                        }
                        else
                        {
                            if (mustShowDebugInfo)
                            {
                                Debug.LogWarning("There are no AudioObject Prefab instance to play Item[" + itemId + "]");
                            }
                        }
                    }
                }
                else
                {
                    if (mustShowDebugInfo)
                    {
                        Debug.LogWarning("There are no AudioObject Prefab to play Item[" + itemId + "]");
                    }
                }
            }
            else
            {
                if (mustShowDebugInfo)
                {
                    Debug.LogWarning("There are no SubItems to play in Item[" + itemId + "]");
                }
            }
            return(ao);
        }
        else
        {
            if (mustShowDebugInfo)
            {
                Debug.LogWarning("Time elpased since last[" + fTimeElapsedSinceLastPlay + "] is not enough to play Item[" + itemId + "]");
            }
        }

        return(null);
    }
Exemplo n.º 10
0
        private static AudioSubItem[] _ChooseSubItems(AudioItem audioItem, AudioPickSubItemMode pickMode, AudioObject useExistingAudioObj)
        {
            if (audioItem.subItems == null)
            {
                return(null);
            }
            int arraySize = audioItem.subItems.Length;

            if (arraySize == 0)
            {
                return(null);
            }

            int chosen = 0;

            AudioSubItem[] chosenItems;

            int lastChosen;

            bool useLastChosenOfExistingAudioObj = !object.ReferenceEquals(useExistingAudioObj, null);

            if (useLastChosenOfExistingAudioObj)   // don't use Unity's operator here, because it will be called by GaplessAudioClipTransistion
            {
                lastChosen = useExistingAudioObj._lastChosenSubItemIndex;
            }
            else
            {
                lastChosen = audioItem._lastChosen;
            }

            if (arraySize > 1)
            {
                switch (pickMode)
                {
                case AudioPickSubItemMode.Disabled:
                    return(null);

                case AudioPickSubItemMode.StartLoopSequenceWithFirst:
                    if (useLastChosenOfExistingAudioObj)
                    {
                        chosen = (lastChosen + 1) % arraySize;
                    }
                    else
                    {
                        chosen = 0;
                    }
                    break;

                case AudioPickSubItemMode.Sequence:
                    chosen = (lastChosen + 1) % arraySize;
                    break;

                case AudioPickSubItemMode.SequenceWithRandomStart:
                    if (lastChosen == -1)
                    {
                        chosen = UnityEngine.Random.Range(0, arraySize);
                    }
                    else
                    {
                        chosen = (lastChosen + 1) % arraySize;
                    }
                    break;

                case AudioPickSubItemMode.Random:
                    chosen = _ChooseRandomSubitem(audioItem, true, lastChosen);
                    break;

                case AudioPickSubItemMode.RandomNotSameTwice:
                    chosen = _ChooseRandomSubitem(audioItem, false, lastChosen);
                    break;

                case AudioPickSubItemMode.AllSimultaneously:
                    chosenItems = new AudioSubItem[arraySize];
                    for (int i = 0; i < arraySize; i++)    // Array.Copy( audioItem.subItems, chosenItems, arraySize );  not working on Flash export
                    {
                        chosenItems[i] = audioItem.subItems[i];
                    }

                    return(chosenItems);

                case AudioPickSubItemMode.TwoSimultaneously:
                    chosenItems    = new AudioSubItem[2];
                    chosenItems[0] = _ChooseSingleSubItem(audioItem, AudioPickSubItemMode.RandomNotSameTwice, useExistingAudioObj);
                    chosenItems[1] = _ChooseSingleSubItem(audioItem, AudioPickSubItemMode.RandomNotSameTwice, useExistingAudioObj);
                    return(chosenItems);

                case AudioPickSubItemMode.RandomNotSameTwiceOddsEvens:
                    chosen = _ChooseRandomSubitem(audioItem, false, lastChosen, true);
                    break;
                }
            }

            if (useLastChosenOfExistingAudioObj)
            {
                useExistingAudioObj._lastChosenSubItemIndex = chosen;
            }
            else
            {
                audioItem._lastChosen = chosen;
            }

            //Debug.Log( "chose:" + chosen );
            chosenItems    = new AudioSubItem[1];
            chosenItems[0] = audioItem.subItems[chosen];
            return(chosenItems);
        }
Exemplo n.º 11
0
 private static bool _IsValidSubItem( AudioSubItem item )
 {
     switch ( item.SubItemType )
     {
     case AudioSubItemType.Clip:
         return item.Clip != null;
     case AudioSubItemType.Item:
         return item.ItemModeAudioID != null && item.ItemModeAudioID.Length > 0;
     }
     return false;
 }
Exemplo n.º 12
0
    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 );
    }
Exemplo n.º 13
0
    private void _DisplaySubItem_Clip(AudioSubItem subItem, int subItemCount, AudioItem curItem)
    {
        // AudioSubItems

        if (subItem != null)
        {
            EditAudioClip(ref subItem.Clip, "Audio Clip");
            EditFloat01(ref subItem.Volume, "Volume", " %");

            EditFloat01(ref subItem.RandomVolume, "Random Volume", "±%");

            EditFloat(ref subItem.Delay, "Delay", "sec");
            //EditFloatWithinRange( ref subItem.Pan2D, "Pan2D [left..right]", -1.0f, 1.0f);
            EditFloatPlusMinus1(ref subItem.Pan2D, "Pan2D", "%left/right");
            if (_IsRandomItemMode(curItem.SubItemPickMode))
            {
                EditFloat01(ref subItem.Probability, "Probability", " %");
            }
            EditFloat(ref subItem.PitchShift, "Pitch Shift", "semitone");
            EditFloat(ref subItem.RandomPitch, "Random Pitch", "±semitone");
            EditFloat(ref subItem.RandomDelay, "Random Delay", "sec");
            EditFloat(ref subItem.FadeIn, "Fade-in", "sec");
            EditFloat(ref subItem.FadeOut, "Fade-out", "sec");


            if (!curItem.Loop)
            {
                EditFloat(ref subItem.ClipStartTime, "Start at", "sec");
                EditFloat(ref subItem.ClipStopTime, "Stop at", "sec");
            }
            EditBool(ref subItem.RandomStartPosition, "Random Start Position");
        }

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Play", GUILayout.Width(60)) && subItem != null)
        {
            if (EditorApplication.isPlaying && AudioController.DoesInstanceExist())
            {
                var     audioListener = AudioController.GetCurrentAudioListener();
                Vector3 pos;
                if (audioListener != null)
                {
                    pos = audioListener.transform.position + audioListener.transform.forward;
                }
                else
                {
                    pos = Vector3.zero;
                }

                AudioController.Instance.PlayAudioSubItem(subItem, 1, pos, null, 0, 0, false);
            }
            else
            {
                if (Application.platform == RuntimePlatform.OSXEditor)
                {
                    Debug.Log(_playNotSupportedOnMac);
                }
                else
                {
                    Debug.Log(_playWithInspectorNotice);
                    AC.InitializeAudioItems();
                    AC.PlayAudioSubItem(subItem, 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 = subItemCount;
                currentSubitemIndex = firstIndex;
                foreach (AudioClip audioClip in audioClips)
                {
                    AddArrayElement(ref curItem.subItems).Clip = audioClip;
                    currentSubitemIndex++;
                }
                currentSubitemIndex = firstIndex;
                KeepChanges();
            }
        }

        GUILayout.Label("use inspector lock!");
        EditorGUILayout.EndHorizontal();
    }
Exemplo n.º 14
0
    public override void OnInspectorGUI()
    {
        SetStyles();

        BeginInspectorGUI();

        _ValidateCurrentCategoryIndex();
        _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))
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Streaming Audio Buffer", labelFieldOption);
            AC.StreamingAudioBuffer = EditorGUILayout.ObjectField(AC.StreamingAudioBuffer, typeof(StreamingAudioBuffer), true) as StreamingAudioBuffer;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Audio listener", labelFieldOption);
            AC.AudioListenerReference = EditorGUILayout.ObjectField(AC.AudioListenerReference, typeof(AudioListener), true) as AudioListener;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Simple Sound Prefab", labelFieldOption);
            AC.SimpleSoundPrefab = EditorGUILayout.ObjectField(AC.SimpleSoundPrefab, typeof(SoundObject), true) as SoundObject;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Stream Sound Prefab", labelFieldOption);
            AC.StreamingSoundPrefab = EditorGUILayout.ObjectField(AC.StreamingSoundPrefab, typeof(SoundObject), true) as SoundObject;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Native Sound Prefab", labelFieldOption);
            AC.NativeSoundPrefab = EditorGUILayout.ObjectField(AC.NativeSoundPrefab, typeof(SoundObject), true) as SoundObject;
            EditorGUILayout.EndHorizontal();

            EditBool(ref AC.Persistent, "Persist Scene Loading", "A non-persisting AudioController will get destroyed when loading the next scene.");
            EditBool(ref AC.UnloadAudioClipsOnDestroy, "Unload Audio On Destroy", "This option will unload all AudioClips from memory which referenced by this AudioController if the controller gets destroyed (e.g. when loading a new scene and the AudioController is not persistent). \n" +
                     "Use this option in combination with additional none-persistent AudioControllers to keep only those audios in memory that are used by the current scene. Use the primary persistent AudioController for all global audio that is used throughout all scenes."
                     );

            bool currentlyDisabled = AC.DisableAudio;

            bool changed = EditBool(ref currentlyDisabled, "Disable Audio", "Disables all audio");
            if (changed)
            {
                AC.DisableAudio = currentlyDisabled;
            }

            float vol = AC.Volume;

            EditFloat01(ref vol, "Volume", "%");

            AC.Volume = vol;

            EditPrefab(ref AC.SoundSettings, "Sound Settings", "You may specify a prefab here that will contains settings for all sounds");
            EditBool(ref AC.UsePooledAudioObjects, "Use Pooled AudioObjects", "Pooling increases performance when playing many audio files. Strongly recommended particularly on mobile platforms.");
            EditBool(ref AC.PlayWithZeroVolume, "Play With Zero Volume", "If disabled Play() calls with a volume of zero will not create an AudioObject.");
        }

        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;

            var categoryNames = GetCategoryNames();

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

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

                if (!lastEntryIsNew)
                {
                    newCategoryIndex = AC.AudioCategories != null ? AC.AudioCategories.Length : 0;
                    ArrayHelper.AddArrayElement(ref AC.AudioCategories, new SoundsCategory(AC));
                    AC.AudioCategories[newCategoryIndex].Name = _nameForNewCategoryEntry;
                    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);
                }
                ArrayHelper.DeleteArrayElement(ref AC.AudioCategories, currentCategoryIndex);
                KeepChanges();
            }

            EditorGUILayout.EndHorizontal();

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


            SoundsCategory curCat = currentCategory;

            if (curCat != null)
            {
                if (curCat.SoundsManager == null)
                {
                    curCat.SoundsManager = AC;//TODO ???
                }
                if (justCreatedNewCategory)
                {
                    SetFocusForNextEditableField();
                }
                EditString(ref curCat.Name, "Name", curCat.Name == _nameForNewCategoryEntry ? textAttentionStyle : null);

                float volTmp = curCat.Volume;
                EditFloat01(ref volTmp, "Volume", " %");
                curCat.Volume = volTmp;

                EditPrefab(ref curCat.SoundSettingsOverride, "Sound Settings Override", "Use different settinfs if you want to specify different parameters such as the volume rolloff etc. per category");

                int selectedParentCategoryIndex;

                var catList = _GenerateCategoryListIncludingNone(out selectedParentCategoryIndex, curCat.ParentCategory);

                int newIndex = Popup("Parent Category", selectedParentCategoryIndex, catList, "The effective volume of a category is multiplied with the volume of the parent category.");
                if (newIndex != selectedParentCategoryIndex)
                {
                    KeepChanges();

                    if (newIndex <= 0)
                    {
                        curCat.ParentCategory = null;
                    }
                    else
                    {
                        curCat.ParentCategory = _GetCategory(catList[newIndex]);
                    }
                }

                int itemCount = currentItemCount;
                _ValidateCurrentItemIndex();

                VerticalSpace();

                SoundItem curItem = currentItem;

                if (itemFoldout = EditorGUILayout.Foldout(itemFoldout, "Audio Item Settings", foldoutStyle))
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Add selected audio clips", EditorStyles.miniButton))//TODO ???
                    {
                        UnityEngine.Object[] audioClips = GetSelectedAudioObjects();
                        if (audioClips.Length > 0)
                        {
                            int firstIndex = itemCount;
                            currentItemIndex = firstIndex;
                            foreach (AudioClip audioClip in audioClips)
                            {
                                ArrayHelper.AddArrayElement(ref curCat.AudioItems);
                                SoundItem audioItem = curCat.AudioItems[currentItemIndex];
                                audioItem.Name = audioClip.name;
                                ArrayHelper.AddArrayElement(ref audioItem.subItems).Clip = audioClip;
                                currentItemIndex++;
                            }
                            currentItemIndex = firstIndex;
                            KeepChanges();
                        }
                    }

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

                    // AudioItems

                    EditorGUILayout.BeginHorizontal();

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


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

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

                        if (!lastEntryIsNew)
                        {
                            newItemIndex = curCat.AudioItems != null ? curCat.AudioItems.Length : 0;
                            ArrayHelper.AddArrayElement(ref curCat.AudioItems);
                            curCat.AudioItems[newItemIndex].Name = _nameForNewAudioItemEntry;
                            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);
                        }
                        ArrayHelper.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();
                        }

                        bool isNewDummyName = curItem.Name == _nameForNewAudioItemEntry;
                        EditString(ref curItem.Name, "Name", isNewDummyName ? textAttentionStyle : null, "You must specify a unique name here (=audioID). This is the ID used in the script code to play this audio item.");

                        GUILayout.EndHorizontal();

                        int newItemCategoryIndex = Popup("Move to Category", currentCategoryIndex, GetCategoryNames());

                        if (newItemCategoryIndex != currentCategoryIndex)
                        {
                            var newCat = AC.AudioCategories[newItemCategoryIndex];
                            var oldCat = currentCategory;
                            ArrayHelper.AddArrayElement(ref newCat.AudioItems, curItem);
                            ArrayHelper.DeleteArrayElement(ref oldCat.AudioItems, currentItemIndex);
                            currentCategoryIndex = newItemCategoryIndex;
                            KeepChanges();
                            //AC.InitializeAudioItems(); //TODO
                            currentItemIndex = newCat.AudioItems.Length - 1;
                        }

                        if (EditFloat01(ref curItem.Volume, "Volume", " %"))
                        {
                            _AdjustVolumeOfAllAudioItems(curItem, null);
                        }

                        EditFloat(ref curItem.Delay, "Delay", "sec", "Delays the playback"); //TODO
                        EditInt(ref curItem.MaxInstanceCount, "Max Instance Count", "", "Sets the maximum number of simultaneously playing audio files of this particular audio item. If the maximum number would be exceeded, the oldest playing audio gets stopped.");
                        EditBool(ref curItem.SkipWhenExeeded, "Skip sound if Exeeded Limit", "");
                        EditBool(ref curItem.DestroyOnLoad, "Stop When Scene Loads", "If disabled, this audio item will continue playing even if a different scene is loaded.");
                        //TODO override prefab

                        curItem.Loop = (SoundLoopMode)EnumPopup("Loop Mode", curItem.Loop, "The Loop mode determines how the audio subitems are looped. \n'LoopSubitem' means that the chosen sub-item will loop. \n'LoopSequence' means that one subitem is played after the other. In which order the subitems are chosen depends on the subitem pick mode.");
                        if (curItem.Loop == SoundLoopMode.LoopSubitem)
                        {
                            EditFloat(ref curItem.OverlapTime, "When Overlap", "sec", "define time when start next clip"); //TODO
                        }
                        curItem.SubItemPickMode = (SoundPickSubItemMode)EnumPopup("Pick Subitem Mode", curItem.SubItemPickMode, "Determines which subitem is chosen when the audio item is played.");

                        EditPrefab(ref curItem.SoundSettingsOverride, "Sound Settings Override", "Use different settinfs if you want to specify different parameters such as the volume rolloff etc. per item");

                        EditBool(ref curItem.overrideAudioSourceSettings, "Override AudioSource Settings");
                        if (curItem.overrideAudioSourceSettings)
                        {
                            //EditorGUI.indentLevel++;

                            EditFloat(ref curItem.audioSource_MinDistance, "   Min Distance", "", "Overrides the 'Min Distance' parameter in the AudioSource settings of the AudioObject prefab (for 3d sounds)");
                            EditFloat(ref curItem.audioSource_MaxDistance, "   Max Distance", "", "Overrides the 'Max Distance' parameter in the AudioSource settings of the AudioObject prefab (for 3d sounds)");

                            //EditorGUI.indentLevel--;
                        }

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("");

                        if (GUILayout.Button("Play", GUILayout.Width(60)) && curItem != null)
                        {
                            if (_IsAudioControllerInPlayMode())
                            {
                                SoundsManager.Play(curItem.Name);
                            }
                        }

                        EditorGUILayout.EndHorizontal();
                        VerticalSpace();

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

                        if (subitemFoldout = EditorGUILayout.Foldout(subitemFoldout, "Audio Sub-Item Settings", foldoutStyle))
                        {
                            EditorGUILayout.BeginHorizontal();
                            if (GUILayout.Button("Add selected audio clips", EditorStyles.miniButton))
                            {
                                UnityEngine.Object[] audioObjects = GetSelectedAudioObjects();
                                if (audioObjects.Length > 0)
                                {
                                    int firstIndex = subItemCount;
                                    currentSubitemIndex = firstIndex;
                                    foreach (UnityEngine.Object audioObject in audioObjects)
                                    {
                                        SoundSubItem cSubItem = ArrayHelper.AddArrayElement(ref curItem.subItems);
                                        cSubItem.Clip = audioObject;
                                        currentSubitemIndex++;
                                    }
                                    currentSubitemIndex = firstIndex;
                                    KeepChanges();
                                }
                            }
                            GUILayout.Label("use inspector lock!");
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();

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

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

                                SoundClipType curSubItemType = SoundClipType.Clip;

                                if (subItemCount > 0)
                                {
                                    curSubItemType = curItem.subItems[currentSubitemIndex].SubItemType;
                                    if (curSubItemType == SoundClipType.Clip)
                                    {
                                        lastEntryIsNew = curItem.subItems[currentSubitemIndex].Clip == null;
                                    }
                                }

                                if (!lastEntryIsNew)
                                {
                                    currentSubitemIndex = subItemCount;
                                    ArrayHelper.AddArrayElement(ref curItem.subItems);
                                    KeepChanges();
                                }
                            }

                            if (GUILayout.Button("-", GUILayout.Width(30)) && subItemCount > 0)
                            {
                                ArrayHelper.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);
                                _DisplaySubItem_Clip(subItem, subItemCount, curItem);
                            }
                        }
                    }
                }
            }
        }

        VerticalSpace();

        EditorGUILayout.Space();

        if (EditorApplication.isPlaying)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Stop All Sounds"))
            {
                if (EditorApplication.isPlaying && SoundsManager.InstanceIfExist)
                {
                    SoundsManager.StopAllSounds();
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        EndInspectorGUI();

        #if AUDIO_PLUGIN
        if (GUILayout.Button("convert from audio controller"))
        {
            AudioController audio = GameObjectExtension.GetAllObjectsInScene <AudioController>()[0];
            AC.AudioCategories = new SoundsCategory[audio.AudioCategories.Length];

            for (int i = 0; i < audio.AudioCategories.Length; i++)
            {
                AudioCategory cat = audio.AudioCategories[i];

                SoundsCategory scat = new SoundsCategory(AC);
                scat.AudioItems = new SoundItem[cat.AudioItems.Length];
                scat.Name       = cat.Name;
                scat.Volume     = cat.Volume;
                if (cat.parentCategory != null)
                {
                    scat.ParentCategory = SoundsManager.Instance.GetCategory(cat.parentCategory.Name);
                }
                AC.AudioCategories[i] = scat;

                for (int j = 0; j < cat.AudioItems.Length; j++)
                {
                    AudioItem item = cat.AudioItems[j];

                    SoundItem sitem = new SoundItem();
                    sitem.subItems                    = new SoundSubItem[item.subItems.Length];
                    sitem.Name                        = item.Name;
                    sitem.Volume                      = item.Volume;
                    sitem.MaxInstanceCount            = item.MaxInstanceCount;
                    sitem.SkipWhenExeeded             = item.SkipWhenExeeded;
                    sitem.Delay                       = item.Delay;
                    sitem.overrideAudioSourceSettings = item.overrideAudioSourceSettings;
                    sitem.audioSource_MinDistance     = item.audioSource_MinDistance;
                    sitem.audioSource_MaxDistance     = item.audioSource_MaxDistance;
                    sitem.Loop                        = (SoundLoopMode)item.Loop;
                    sitem.SubItemPickMode             = (SoundPickSubItemMode)item.SubItemPickMode;

                    scat.AudioItems[j] = sitem;

                    for (int k = 0; k < item.subItems.Length; k++)
                    {
                        AudioSubItem subItem = item.subItems[k];

                        SoundSubItem       ssubItem = new SoundSubItem();
                        UnityEngine.Object asset    = subItem.Clip;
                        if (asset == null)
                        {
                            string path = subItem.StreamingAudioClipData.Path;
                            if (path.Length > 0)
                            {
//                                asset = UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.Object>("Assets/StreamingAssets" + path);
                                Debug.Log(asset);
                            }
                            else
                            {
                                Debug.LogError(cat.Name + "  " + item.Name + "  missing path");
                            }
                        }
                        else
                        {
                            Debug.LogError("use existing clip : " + asset);
                        }
                        ssubItem.Clip         = asset;
                        ssubItem.Volume       = subItem.Volume;
                        ssubItem.RandomVolume = subItem.RandomVolume;
                        ssubItem.Delay        = subItem.Delay;
                        ssubItem.Pan2D        = subItem.Pan2D;
                        ssubItem.Probability  = subItem.Probability;
                        ssubItem.RandomPitch  = subItem.RandomPitch;
                        ssubItem.RandomDelay  = subItem.RandomDelay;
                        ssubItem.FadeIn       = subItem.FadeIn;
                        ssubItem.FadeOut      = subItem.FadeOut;

                        sitem.subItems[k] = ssubItem;
                    }
                }
            }

            AC._currentInspectorSelection = new SoundsManager.InspectorSelection();
            AC.ValidateSounds();
        }
        #endif

        if (GUILayout.Button("print .wav items"))
        {
            foreach (SoundsCategory cat in AC.AudioCategories)
            {
                foreach (SoundItem item in cat.AudioItems)
                {
                    foreach (SoundSubItem subItem in item.subItems)
                    {
                        if (subItem.SubItemType != SoundClipType.Native)
                        {
                            Debug.Log(cat.Name + "/" + item.Name + "/" + subItem.Name);
                        }
                    }
                }
            }
        }

        if (GUILayout.Button("convert all to caf"))
        {
            foreach (SoundsCategory cat in AC.AudioCategories)
            {
                foreach (SoundItem item in cat.AudioItems)
                {
                    foreach (SoundSubItem subItem in item.subItems)
                    {
                        if (subItem.clipref.FullPath.Length > 0)
                        {
                            ConvertToCaff(cat, item, subItem);
                        }
                    }
                }
            }
        }


        if (GUILayout.Button("convert wav to caf"))
        {
            foreach (SoundsCategory cat in AC.AudioCategories)
            {
                foreach (SoundItem item in cat.AudioItems)
                {
                    foreach (SoundSubItem subItem in item.subItems)
                    {
                        if (subItem.clipref.FullPath.Length > 0 && subItem.SubItemType == SoundClipType.Clip)
                        {
                            string path = ConvertToCaff(cat, item, subItem);
                            AssetDatabase.Refresh();
                            subItem.Clip = AssetDatabase.LoadAssetAtPath <DefaultAsset>("Assets" + path);
                        }
                    }
                }
            }
        }


        if (GUILayout.Button("convert all to ogg"))
        {
            string rootDirectory = Application.dataPath + "/StreamingAssets/";
            var    allFiles      = Directory.GetFiles(rootDirectory, "*.caf", SearchOption.AllDirectories);

            foreach (string file in allFiles)
            {
                string filePath = file;

                int fileExtPos = file.LastIndexOf(".");
                if (fileExtPos >= 0)
                {
                    filePath = file.Substring(0, fileExtPos);
                }

                string sourceFile      = filePath + ".caf";
                string destanationFile = filePath + ".ogg";

                string processPath = Application.dataPath + "/SoundsPlugin/ffmpeg";
                string attributes  = string.Format("-i {0} -acodec libvorbis {1}", sourceFile.ShellString(), destanationFile.ShellString());

                System.Diagnostics.Process p = System.Diagnostics.Process.Start(processPath, attributes);
                p.WaitForExit();
            }
        }
    }