예제 #1
0
 private void OnSceneLoaded(Scene arg0, LoadSceneMode arg1)
 {
     CurrentScene = arg0;
     lock (PlayingAudioSource)
     {
         VoiceCache.Clear();
         PlayingAudioSource.Clear();
         StoppedAudio.Clear();
     }
 }
예제 #2
0
        public void OnGUI()
        {
            try
            {
                OnKeyShort();

                if (!SubtitleConfig.EnableSubtitle)
                {
                    return;
                }

                if (BoxStyle == null)
                {
                    BoxStyle = new GUIStyle(GUI.skin.box)
                    {
                        wordWrap = true,
                        fontSize = 20
                    };
                }

                if (CurrentScene.name != "SceneYotogi")
                {
                    return;
                }

                var commandUnit = GameObject.Find("CommandUnit");
                if (commandUnit != null)
                {
                    var commandRects = new List <Rect>();

                    foreach (Transform obj in commandUnit.transform)
                    {
                        if (!obj.name.StartsWith("cm:"))
                        {
                            continue;
                        }

                        var component = obj.GetComponent <BoxCollider>();
                        if (component == null)
                        {
                            continue;
                        }
                        var vector = component.transform.TransformPoint(component.center);
                        vector = UICamera.currentCamera.WorldToScreenPoint(vector);
                        var x = component.size.x;
                        var y = component.size.y;

                        var rect = new Rect(vector.x - x / 2f, Screen.height - vector.y - y / 2f, x, y);
                        commandRects.Add(rect);
                    }

                    commandRects.Sort((rect1, rect2) => rect1.yMin.CompareTo(rect2.yMin));

                    if (commandRects.Count > 0)
                    {
                        var last = commandRects.Last();
                        _lastArea.x        = last.xMin;
                        _lastArea.y        = last.yMax + last.height;
                        _lastArea.width    = last.width;
                        _lastArea.height   = 1080;
                        _firstCommandUnitY = commandRects.First().yMin;
                    }
                    else
                    {
                        _lastArea.y = _firstCommandUnitY;
                    }
                }

                GUILayout.BeginArea(_lastArea);
                lock (PlayingAudioSource)
                {
                    var rendered = 0;
                    foreach (var audioFileName in PlayingAudio)
                    {
                        if (!PlayingAudioSource.TryGetValue(audioFileName, out var audioSource))
                        {
                            continue;
                        }

                        if (!audioSource.isPlaying)
                        {
                            StoppedAudio.Add(audioFileName);
                            continue;
                        }

                        if (!VoiceCache.ContainsKey(audioFileName))
                        {
                            continue;
                        }

                        if (SubtitleConfig.MaxSubtitle > 0 && rendered >= SubtitleConfig.MaxSubtitle)
                        {
                            continue;
                        }

                        GUILayout.Box(VoiceCache[audioFileName], BoxStyle);
                        rendered++;
                    }

                    foreach (var audioSource in StoppedAudio)
                    {
                        Logger.Log(LogLevel.Debug, $"{audioSource} Stopped.");
                        PlayingAudioSource.Remove(audioSource);
                    }
                    StoppedAudio.Clear();
                }
                GUILayout.EndArea();
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, ex);
                throw;
            }
        }