コード例 #1
0
        public int GetInsertIndex(BetterPlayerAudioOverride[] betterPlayerAudioOverrides,
                                  BetterPlayerAudioOverride voiceOverride)
        {
            if (betterPlayerAudioOverrides == null ||
                !Utilities.IsValid(voiceOverride))
            {
                return(-1);
            }

            var index = 0;

            foreach (var betterPlayerAudioOverride in betterPlayerAudioOverrides)
            {
                if (!Utilities.IsValid(betterPlayerAudioOverride))
                {
                    continue;
                }

                if (betterPlayerAudioOverride.priority > voiceOverride.priority)
                {
                    ++index;
                    continue;
                }

                break;
            }

            return(index);
        }
コード例 #2
0
        public BetterPlayerAudioOverride[] InsertNewOverride(BetterPlayerAudioOverride voiceOverride, int insertIndex,
                                                             BetterPlayerAudioOverride[] tempList, BetterPlayerAudioOverride[] originalList)
        {
            if (insertIndex >= originalList.Length)
            {
                var tempList2 = new BetterPlayerAudioOverride[insertIndex + 1];
                tempList.CopyTo(tempList2, 0);
                tempList2[tempList2.Length - 1] = voiceOverride;
                tempList = tempList2;
            }
            else
            {
                tempList[insertIndex] = voiceOverride;
            }

            return(tempList);
        }
コード例 #3
0
        public bool AddOverride(BetterPlayerAudioOverride voiceOverride)
        {
            if (!Utilities.IsValid(voiceOverride))
            {
                return(false);
            }

            if (BetterPlayerAudioOverrides == null || BetterPlayerAudioOverrides.Length == 0)
            {
                BetterPlayerAudioOverrides = new[] { voiceOverride };
                return(true);
            }

            foreach (var betterPlayerAudioOverride in BetterPlayerAudioOverrides)
            {
                if (betterPlayerAudioOverride == voiceOverride)
                {
                    return(false);
                }
            }

            Remove(BetterPlayerAudioOverrides, voiceOverride);
            var slotsNeeded = Consolidate(BetterPlayerAudioOverrides) + 1;
            var insertIndex = GetInsertIndex(BetterPlayerAudioOverrides, voiceOverride);
            var tempList    = new BetterPlayerAudioOverride[slotsNeeded];

            if (insertIndex > 0)
            {
                Array.ConstrainedCopy(BetterPlayerAudioOverrides, 0, tempList, 0, insertIndex);
            }

            tempList[insertIndex] = voiceOverride;
            if (slotsNeeded - insertIndex > 1)
            {
                Array.ConstrainedCopy(BetterPlayerAudioOverrides,
                                      insertIndex,
                                      tempList,
                                      insertIndex + 1,
                                      slotsNeeded - insertIndex - 1);
            }

            BetterPlayerAudioOverrides = tempList;

            return(true);
        }
コード例 #4
0
        public bool Remove(BetterPlayerAudioOverride[] list, BetterPlayerAudioOverride betterPlayerAudioOverride)
        {
            if (list == null)
            {
                return(false);
            }

            var removed = false;

            for (var i = 0; i < list.Length; i++)
            {
                if (list[i] == betterPlayerAudioOverride)
                {
                    list[i] = null;
                    removed = true;
                }
            }

            return(removed);
        }
コード例 #5
0
 public int RemoveOverride(BetterPlayerAudioOverride betterPlayerAudioOverride)
 {
     Remove(BetterPlayerAudioOverrides, betterPlayerAudioOverride);
     return(Consolidate(BetterPlayerAudioOverrides));
 }