示例#1
0
        /// <summary>
        /// 当歌曲播放完毕时是单曲播放时
        /// </summary>
        private static void OnSinglePlay()
        {
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            scenesDatas.AudioSource.Stop();
            UILyricControl.ResetLyric(scenesDatas.LyricItems);
            scenesDatas.VideoPlayer.Stop();
            ModelManager.Instance.GetLogicDatas.Index = 0;
            SongControl.ReleaseAudioRelatedResources();
        }
示例#2
0
        /// <summary>
        /// 初始化
        /// </summary>
        internal static void Initialize()
        {
            ModelManager.Instance.GetParameter = ConfigControl.LoadConfig();

#if UNITY_EDITOR
            string[] filesName = Tools.PathTools.GetFileName(Tools.PathTools.GetAudioPath).
                                 Where((str) => Path.GetExtension(str) != ".meta").
                                 Select((audioName) => Path.GetFileName(audioName)).ToArray();
#else
            string[] filesName = Tools.PathTools.GetFileName(Tools.PathTools.GetAudioPath).
                                 Select(str => Path.GetFileName(str)).ToArray();
#endif
            ModelManager.Instance.GetLogicDatas = new LogicDatas
            {
                GameState        = GameState.Init,
                SongsName        = filesName,
                LyricInfo        = null,
                CycleType        = CycleType.LoopPlayback,
                Index            = 0,
                Timer            = 0,
                CurrentSongIndex = 0
            };
            Material audioDataMaterial = Resources.Load <Material>("Materials/AudioDataMaterial");
            ModelManager.Instance.GetScenesDatas = new ScenesDatas
            {
                AudioSource       = GameObject.FindObjectOfType <AudioSource>(),
                VideoPlayer       = GameObject.FindObjectOfType <UnityEngine.Video.VideoPlayer>(),
                AudioDataMaterial = audioDataMaterial,
                AudioDatas        = InitializeAndClear.InitAudioDatas(audioDataMaterial),
                TrailRenderer     = GameObject.FindObjectOfType <TrailRenderer>().transform,
                LyricItems        = GameObject.Find("LyricLayer").transform.GetComponentsInChildren <Text>(),
                SongName          = GameObject.Find("SongName").transform.GetComponent <Text>(),
                SongTotalTime     = GameObject.Find("SongTotalTime").transform.GetComponent <Text>(),
                SongPlayingTime   = GameObject.Find("SongPlayingTime").transform.GetComponent <Text>(),
                SongTimeSlide     = GameObject.Find("SongTimeSlider").transform.GetComponent <Slider>()
            };

            ControllerManager controllerManager = ControllerManager.Instance;
            controllerManager.RegisterOnUpdate(SongControl.ListeningSongOver);
            controllerManager.RegisterOnUpdate(AudioVisualizer.RefreshHeartbeat);
            controllerManager.RegisterOnUpdate(SongLyric.ListeningSongLyric);
            controllerManager.RegisterOnUpdate(MouseTrail.RefreshTrail);
            controllerManager.RegisterOnUpdate(AssetsControl.RefreshAssets);
            controllerManager.RegisterOnUpdate(SongControl.UpdateSongPlayingTime);

            Parameter   parameter   = ModelManager.Instance.GetParameter;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;
            UILyricControl.ChangeBaseLyricColor(parameter.BaseFontColor, scenesDatas.LyricItems);
            UILyricControl.ChangeCurrentLyricColor(parameter.CurrentFontColor, scenesDatas.LyricItems);
            UILyricControl.ChangeLyricFontSize(parameter.FontSize, scenesDatas.LyricItems);

            ModelManager.Instance.GetLogicDatas.GameState = GameState.StandBy;
            //Controller.SongControl.PlayOrPauseSong();
        }
示例#3
0
        /// <summary>
        /// 播放加载完毕的歌曲
        /// </summary>
        internal static void PlayLoadFinishSong()
        {
            LogicDatas  logicDatas  = ModelManager.Instance.GetLogicDatas;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            UILyricControl.InitLyric(scenesDatas.LyricItems, logicDatas.LyricInfo);
            scenesDatas.SongName.text        = System.IO.Path.GetFileNameWithoutExtension(logicDatas.SongsName[logicDatas.CurrentSongIndex]);
            scenesDatas.SongPlayingTime.text = "00:00";
            scenesDatas.SongTotalTime.text   = SongTimeTools.SongTimeToStringTime(scenesDatas.AudioSource.clip.length);
            scenesDatas.SongTimeSlide.value  = 0.0f;
            scenesDatas.AudioSource.time     = 0.0f;
            scenesDatas.AudioSource.Play();
            logicDatas.GameState = GameState.Playing;
        }
示例#4
0
        /// <summary>
        /// 释放已播放完毕的音频相关资源
        /// </summary>
        private static void ReleaseAudioRelatedResources()
        {
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            scenesDatas.AudioSource.Stop();
            scenesDatas.AudioSource.clip?.UnloadAudioData();
            scenesDatas.AudioSource.clip = null;
            ModelManager.Instance.GetLogicDatas.LyricInfo = null;
            scenesDatas.VideoPlayer.Stop();
            scenesDatas.VideoPlayer.enabled = false;
            scenesDatas.VideoPlayer.clip    = null;
            UILyricControl.ResetLyric(scenesDatas.LyricItems);
            scenesDatas.SongName.text        = string.Empty;
            scenesDatas.SongPlayingTime.text = string.Empty;
            scenesDatas.SongTotalTime.text   = string.Empty;
            scenesDatas.SongTimeSlide.value  = 0.0f;
            UnityEngine.Resources.UnloadUnusedAssets();
        }
示例#5
0
        /// <summary>
        /// 当歌曲播放完毕时是单曲循环时
        /// </summary>
        private static void OnSingleCycle()
        {
            LogicDatas  logicDatas  = ModelManager.Instance.GetLogicDatas;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            scenesDatas.AudioSource.time = 0.0f;
            scenesDatas.AudioSource.Play();
            scenesDatas.VideoPlayer.time = 0.0f;
            scenesDatas.VideoPlayer.Play();
            scenesDatas.SongPlayingTime.text = "00:00";
            scenesDatas.SongTimeSlide.value  = 0.0f;
            UILyricControl.ResetLyric(scenesDatas.LyricItems);
            UILyricControl.InitLyric(scenesDatas.LyricItems, logicDatas.LyricInfo);
            if (!string.IsNullOrEmpty(scenesDatas.VideoPlayer.url) && scenesDatas.VideoPlayer.isPrepared)
            {
                scenesDatas.VideoPlayer.Play();
            }
            logicDatas.Index = 0;
        }
示例#6
0
        /// <summary>
        /// 当设置面板数值变动时
        /// </summary>
        /// <param name="attributeName">属性名称</param>
        /// <param name="valueColor">颜色值</param>
        internal static void OnSettingValueChange(string attributeName, Color valueColor)
        {
            Parameter   parameter   = ModelManager.Instance.GetParameter;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            switch (attributeName)
            {
            case MainColorInputField:
            {
                parameter.MainColor = valueColor;
                scenesDatas.AudioDataMaterial.SetColor(_MainColor, valueColor);
            }
            break;

            case ViceColorInputField:
            {
                parameter.ViceColor = valueColor;
                scenesDatas.AudioDataMaterial.SetColor(_ViceColor, valueColor);
            }
            break;

            case BaseFontColorInputField:
            {
                parameter.BaseFontColor = valueColor;
                UILyricControl.ChangeBaseLyricColor(valueColor, scenesDatas.LyricItems);
            }
            break;

            case CurrentFontColorInputField:
            {
                parameter.CurrentFontColor = valueColor;
                UILyricControl.ChangeCurrentLyricColor(valueColor, scenesDatas.LyricItems);
            }
            break;

            default:
                break;
            }
        }
示例#7
0
        /// <summary>
        /// 当歌曲播放完毕时是顺序播放时
        /// </summary>
        private static void OnPlayInOrder()
        {
            LogicDatas  logicDatas  = ModelManager.Instance.GetLogicDatas;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            logicDatas.CurrentSongIndex++;
            logicDatas.Index = 0;
            if (logicDatas.CurrentSongIndex >= logicDatas.SongsName.Length)
            {
                scenesDatas.AudioSource.Stop();
                UILyricControl.ResetLyric(scenesDatas.LyricItems);
                if (scenesDatas.VideoPlayer.isPlaying)
                {
                    scenesDatas.VideoPlayer.Stop();
                }
                logicDatas.CurrentSongIndex = logicDatas.SongsName.Length - 1;
            }
            else
            {
                SongControl.ReleaseAudioRelatedResources();
                SongControl.LoadNextSong(logicDatas.SongsName[logicDatas.CurrentSongIndex]);
            }
        }
示例#8
0
        /// <summary>
        /// 当歌曲播放完毕时是随机播放时
        /// </summary>
        private static void OnRandomPlay()
        {
            LogicDatas  logicDatas  = ModelManager.Instance.GetLogicDatas;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;
            int         index       = UnityEngine.Random.Range(0, logicDatas.SongsName.Length);

            logicDatas.Index = 0;
            if (index == logicDatas.CurrentSongIndex)
            {
                scenesDatas.AudioSource.Play();
                if (string.IsNullOrEmpty(scenesDatas.VideoPlayer.url) && scenesDatas.VideoPlayer.isPrepared)
                {
                    scenesDatas.VideoPlayer.Play();
                }
                UILyricControl.InitLyric(scenesDatas.LyricItems, logicDatas.LyricInfo);
            }
            else
            {
                logicDatas.CurrentSongIndex = index;
                SongControl.ReleaseAudioRelatedResources();
                SongControl.LoadNextSong(logicDatas.SongsName[logicDatas.CurrentSongIndex]);
            }
        }
示例#9
0
        /// <summary>
        /// 改变歌词
        /// </summary>
        /// <param name="songtime">歌曲时间</param>
        internal static void ChangeLyric(float songtime)
        {
            LyricInfo lyricInfo = ModelManager.Instance.GetLogicDatas.LyricInfo;
            int       index     = -1;

            for (int i = 0; i < lyricInfo.lyrics.Count; i++)
            {
                if (lyricInfo.lyrics[i].lyricTime >= songtime)
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                return;
            }
            LogicDatas  logicDatas  = ModelManager.Instance.GetLogicDatas;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            logicDatas.Index = index;
            UILyricControl.ChangeLyric(scenesDatas.LyricItems, logicDatas.Index, logicDatas.LyricInfo);
        }
示例#10
0
        /// <summary>
        /// 监听歌曲歌词
        /// </summary>
        internal static void ListeningSongLyric()
        {
            LogicDatas  logicDatas  = ModelManager.Instance.GetLogicDatas;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            if (logicDatas.LyricInfo == null)
            {
                return;
            }
            //最后一句歌词
            if (logicDatas.Index >= logicDatas.LyricInfo.lyrics.Count - 1)
            {
                return;
            }

            //需播放下一句歌词时
            if (Tools.AudioSourceData.GetCurrentSongTime(scenesDatas.AudioSource) >= logicDatas.LyricInfo.lyrics[logicDatas.Index + 1].lyricTime)
            {
                //切换当前歌词为index+1
                UILyricControl.NextLyric(scenesDatas.LyricItems, logicDatas.Index, logicDatas.LyricInfo);
                logicDatas.Index++;
            }
        }
示例#11
0
        /// <summary>
        /// 当设置面板数值变动时
        /// </summary>
        /// <param name="attributeName">属性名称</param>
        /// <param name="value">值</param>
        internal static void OnSettingValueChange(string attributeName, float value)
        {
            Parameter parameter = ModelManager.Instance.GetParameter;

            switch (attributeName)
            {
            case RadiusSlider:
                parameter.Radius = value;
                break;

            case OffsetXSlider:
                parameter.OffsetX = value;
                break;

            case OffsetYSlider:
                parameter.OffsetY = value;
                break;

            case AudioDataCountSlider:
                parameter.AudioDataCount = (int)value;
                break;

            case LineWidthSlider:
                parameter.LineWidth = value;
                break;

            case MinHightSlider:
                parameter.MinHight = value;
                break;

            case MaxHightSlider:
                parameter.MaxHight = value;
                break;

            case ColorBrightnessSlider:
            {
                parameter.ColorBrightness = value;
                ModelManager.Instance.GetScenesDatas.AudioDataMaterial.SetFloat(_Brightness, value);
            }
            break;

            case UpdateIntervalSlider:
                parameter.UpdateInterval = value;
                break;

            case AmplificationFactorSlider:
                parameter.AmplificationFactor = value;
                break;

            case RotateSpeedSlider:
                parameter.RotateSpeed = value;
                break;

            case FontSizeSlider:
            {
                parameter.FontSize = (int)value;
                UILyricControl.ChangeLyricFontSize((int)value, ModelManager.Instance.GetScenesDatas.LyricItems);
            }
            break;

            default:
                break;
            }
        }
示例#12
0
        /// <summary>
        /// 取消
        /// </summary>
        internal static void Cancel()
        {
            Parameter   parameter   = ModelManager.Instance.GetParameter;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            if (parameter.Radius != radiusSliderCache)
            {
                parameter.Radius = radiusSliderCache;
            }
            if (parameter.OffsetX != offsetXSliderCache)
            {
                parameter.OffsetX = offsetXSliderCache;
            }
            if (parameter.OffsetY != offsetYSliderCache)
            {
                parameter.OffsetY = offsetYSliderCache;
            }
            if (parameter.AudioDataCount != audioDataCountSliderCache)
            {
                parameter.AudioDataCount = audioDataCountSliderCache;
            }
            if (parameter.LineWidth != lineWidthSliderCache)
            {
                parameter.LineWidth = lineWidthSliderCache;
            }
            if (parameter.MinHight != minHightSliderCache)
            {
                parameter.MinHight = minHightSliderCache;
            }
            if (parameter.MaxHight != maxHightSliderCache)
            {
                parameter.MaxHight = maxHightSliderCache;
            }
            if (parameter.ColorBrightness != colorBrightnessSliderCache)
            {
                parameter.ColorBrightness = colorBrightnessSliderCache;
                scenesDatas.AudioDataMaterial.SetFloat(_Brightness, colorBrightnessSliderCache);
            }
            if (parameter.MainColor != mainColorInputFieldCache)
            {
                parameter.MainColor = mainColorInputFieldCache;
                scenesDatas.AudioDataMaterial.SetColor(_MainColor, mainColorInputFieldCache);
            }
            if (parameter.ViceColor != viceColorInputFieldCache)
            {
                parameter.ViceColor = viceColorInputFieldCache;
                scenesDatas.AudioDataMaterial.SetColor(_ViceColor, viceColorInputFieldCache);
            }
            if (parameter.UpdateInterval != updateIntervalSliderCache)
            {
                parameter.UpdateInterval = updateIntervalSliderCache;
            }
            if (parameter.AmplificationFactor != amplificationFactorSliderCache)
            {
                parameter.AmplificationFactor = amplificationFactorSliderCache;
            }
            if (parameter.RotateSpeed != rotateSpeedSliderCache)
            {
                parameter.RotateSpeed = rotateSpeedSliderCache;
            }

            if (parameter.BaseFontColor != baseFontColorInputFieldCache)
            {
                parameter.BaseFontColor = baseFontColorInputFieldCache;
                UILyricControl.ChangeBaseLyricColor(baseFontColorInputFieldCache, scenesDatas.LyricItems);
            }
            if (parameter.CurrentFontColor != currentFontColorInputFieldCache)
            {
                parameter.CurrentFontColor = currentFontColorInputFieldCache;
                UILyricControl.ChangeCurrentLyricColor(currentFontColorInputFieldCache, scenesDatas.LyricItems);
            }
            if (parameter.FontSize != fontSizeSliderCache)
            {
                parameter.FontSize = fontSizeSliderCache;
                UILyricControl.ChangeLyricFontSize(fontSizeSliderCache, scenesDatas.LyricItems);
            }
        }
示例#13
0
        /// <summary>
        /// 重置
        /// </summary>
        internal static void Reset(Dictionary <string, AudioPlayer.View.UIBehaviour> uiControls)
        {
            Parameter parameter = ModelManager.Instance.GetParameter;

            parameter.Radius              = 3.5f;
            parameter.OffsetX             = 0.0f;
            parameter.OffsetY             = 0.7f;
            parameter.AudioDataCount      = 64;
            parameter.LineWidth           = 0.02f;
            parameter.MinHight            = 0.14f;
            parameter.MaxHight            = 1.4f;
            parameter.ColorBrightness     = 3.4f;
            parameter.MainColor           = Color.blue;
            parameter.ViceColor           = Color.green;
            parameter.UpdateInterval      = 0.08f;
            parameter.AmplificationFactor = 14.0f;
            parameter.RotateSpeed         = 10.0f;

            parameter.BaseFontColor    = new Color(50.0f / 255.0f, 50.0f / 255.0f, 50.0f / 255.0f, 1.0f);
            parameter.CurrentFontColor = new Color(163.0f / 255.0f, 1.0f, 6.0f / 255.0f, 255.0f);
            parameter.FontSize         = 30;

            if (uiControls.ContainsKey(RadiusSlider))
            {
                uiControls[RadiusSlider].GetSlider().value = parameter.Radius;
            }
            if (uiControls.ContainsKey(OffsetXSlider))
            {
                uiControls[OffsetXSlider].GetSlider().value = parameter.OffsetX;
            }
            if (uiControls.ContainsKey(OffsetYSlider))
            {
                uiControls[OffsetYSlider].GetSlider().value = parameter.OffsetY;
            }
            if (uiControls.ContainsKey(AudioDataCountSlider))
            {
                uiControls[AudioDataCountSlider].GetSlider().value = parameter.AudioDataCount % 64;
            }
            if (uiControls.ContainsKey(LineWidthSlider))
            {
                uiControls[LineWidthSlider].GetSlider().value = parameter.LineWidth;
            }
            if (uiControls.ContainsKey(MinHightSlider))
            {
                uiControls[MinHightSlider].GetSlider().value = parameter.MinHight;
            }
            if (uiControls.ContainsKey(MaxHightSlider))
            {
                uiControls[MaxHightSlider].GetSlider().value = parameter.MaxHight;
            }
            if (uiControls.ContainsKey(ColorBrightnessSlider))
            {
                uiControls[ColorBrightnessSlider].GetSlider().value = parameter.ColorBrightness;
            }
            if (uiControls.ContainsKey(UpdateIntervalSlider))
            {
                uiControls[UpdateIntervalSlider].GetSlider().value = parameter.UpdateInterval;
            }
            if (uiControls.ContainsKey(AmplificationFactorSlider))
            {
                uiControls[AmplificationFactorSlider].GetSlider().value = parameter.AmplificationFactor;
            }
            if (uiControls.ContainsKey(RotateSpeedSlider))
            {
                uiControls[RotateSpeedSlider].GetSlider().value = parameter.RotateSpeed;
            }

            if (uiControls.ContainsKey(FontSizeSlider))
            {
                uiControls[FontSizeSlider].GetSlider().value = parameter.FontSize;
            }

            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            scenesDatas.AudioDataMaterial.SetFloat(_Brightness, 3.4f);
            scenesDatas.AudioDataMaterial.SetColor(_MainColor, Color.blue);
            scenesDatas.AudioDataMaterial.SetColor(_ViceColor, Color.green);
            UILyricControl.ChangeBaseLyricColor(parameter.BaseFontColor, scenesDatas.LyricItems);
            UILyricControl.ChangeCurrentLyricColor(parameter.CurrentFontColor, scenesDatas.LyricItems);
            UILyricControl.ChangeLyricFontSize(parameter.FontSize, scenesDatas.LyricItems);
        }