示例#1
0
文件: AudioItem.cs 项目: Raixur/Slabo
 public AudioItem(AudioItem orig)
 {
     Name = orig.Name;
     Loop = orig.Loop;
     LoopSequenceCount        = orig.LoopSequenceCount;
     LoopSequenceOverlap      = orig.LoopSequenceOverlap;
     LoopSequenceRandomDelay  = orig.LoopSequenceRandomDelay;
     LoopSequenceRandomPitch  = orig.LoopSequenceRandomPitch;
     LoopSequenceRandomVolume = orig.LoopSequenceRandomVolume;
     DestroyOnLoad            = orig.DestroyOnLoad;
     Volume                  = orig.Volume;
     SubItemPickMode         = orig.SubItemPickMode;
     MinTimeBetweenPlayCalls = orig.MinTimeBetweenPlayCalls;
     MaxInstanceCount        = orig.MaxInstanceCount;
     Delay        = orig.Delay;
     RandomVolume = orig.RandomVolume;
     RandomPitch  = orig.RandomPitch;
     RandomDelay  = orig.RandomDelay;
     OverrideAudioSourceSettings = orig.OverrideAudioSourceSettings;
     AudioSourceMinDistance      = orig.AudioSourceMinDistance;
     AudioSourceMaxDistance      = orig.AudioSourceMaxDistance;
     SpatialBlend = orig.SpatialBlend;
     for (var index = 0; index < orig.SubItems.Length; ++index)
     {
         ArrayHelper.AddArrayElement(ref SubItems, new AudioSubItem(orig.SubItems[index], this));
     }
 }
    private bool _IsRandomItemMode(AudioPickSubItemMode audioPickSubItemMode)
    {
        switch (audioPickSubItemMode)
        {
        case AudioPickSubItemMode.Random: return(true);

        case AudioPickSubItemMode.RandomNotSameTwice: return(true);

        case AudioPickSubItemMode.TwoSimultaneously: return(true);
        }
        return(false);
    }
示例#3
0
 public static AudioSubItem _ChooseSingleSubItem(AudioItem audioItem, AudioPickSubItemMode pickMode, AudioObject useExistingAudioObj)
 {
     return(_ChooseSubItems(audioItem, pickMode, useExistingAudioObj)[0]);
 }
示例#4
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);
        }
示例#5
0
        private static AudioSubItem[] _ChooseSubItems(AudioItem audioItem, AudioPickSubItemMode pickMode, AudioObject useExistingAudioObj)
        {
            if (audioItem.SubItems == null)
            {
                return(null);
            }
            var length = audioItem.SubItems.Length;

            if (length == 0)
            {
                return(null);
            }
            var index1     = 0;
            var flag       = useExistingAudioObj != null;
            var lastChosen = !flag ? audioItem.LastChosen : useExistingAudioObj.LastChosenSubItemIndex;

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

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

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

                case AudioPickSubItemMode.Sequence:
                    index1 = (lastChosen + 1) % length;
                    break;

                case AudioPickSubItemMode.SequenceWithRandomStart:
                    index1 = lastChosen != -1 ? (lastChosen + 1) % length : Random.Range(0, length);
                    break;

                case AudioPickSubItemMode.AllSimultaneously:
                    var audioSubItemArray = new AudioSubItem[length];
                    for (var index2 = 0; index2 < length; ++index2)
                    {
                        audioSubItemArray[index2] = audioItem.SubItems[index2];
                    }
                    return(audioSubItemArray);

                case AudioPickSubItemMode.TwoSimultaneously:
                    return(new[]
                    {
                        _ChooseSingleSubItem(audioItem, AudioPickSubItemMode.RandomNotSameTwice, useExistingAudioObj),
                        _ChooseSingleSubItem(audioItem, AudioPickSubItemMode.RandomNotSameTwice, useExistingAudioObj)
                    });

                case AudioPickSubItemMode.StartLoopSequenceWithFirst:
                    index1 = !flag ? 0 : (lastChosen + 1) % length;
                    break;

                case AudioPickSubItemMode.RandomNotSameTwiceOddsEvens:
                    index1 = _ChooseRandomSubitem(audioItem, false, lastChosen, true);
                    break;
                }
            }
            if (flag)
            {
                useExistingAudioObj.LastChosenSubItemIndex = index1;
            }
            else
            {
                audioItem.LastChosen = index1;
            }
            return(new[] { audioItem.SubItems[index1] });
        }