Beispiel #1
0
 private void LoadSbWindow()
 {
     if (_sbWindow == null || _sbWindow.IsClosed)
     {
         _sbWindow = new StoryboardWindow();
         _mainWindow.Deactivated     += MainWindow_Deactivated;
         _mainWindow.Activated       += MainWindow_Activated;
         _mainWindow.Closing         += MainWindow_Closing;
         _mainWindow.LocationChanged += _mainWindow_LocationChanged;
     }
     ReLocate();
     _sbWindow.Show();
 }
Beispiel #2
0
    public IEnumerator CalculateSceneProxies(StoryboardWindow window, StoryboardData data, TimelineAsset timeline, PlayableDirector playable, Vector3 position, Vector3 sceneProxyBounds)
    {
        data.m_proxySets.Clear();

        IEnumerable <IMarker> markers = timeline.markerTrack.GetMarkers();

        markers = markers.OrderBy(a => a.time);
        IEnumerator markersIt = markers.GetEnumerator();

        while (markersIt.MoveNext())
        {
            if (markersIt.Current is StoryboardMarker marker)
            {
                playable.time = marker.m_jumpsToTime ? marker.m_jumpTime : marker.time;
                playable.Evaluate();

                yield return(null);

                ProxySet set = new ProxySet();
                set.m_proxies = new List <Proxy>();



                Collider[] colliders = Physics.OverlapBox(position, sceneProxyBounds / 2.0f);

                for (int i = 0; i < colliders.Length; i++)
                {
                    Proxy    proxy = new Proxy();
                    Collider col   = colliders[i];
                    proxy.m_collider     = colliders[i];
                    proxy.m_gameObjectID = proxy.m_collider.gameObject.GetInstanceID().ToString();
                    set.m_proxies.Add(proxy);
                }

                yield return(null);

                set.m_marker = marker;
                data.m_proxySets.Add(set);
            }
        }
        playable.time = 0.0;
        playable.Evaluate();
        window.OnProxyCalculationEnd();
    }
Beispiel #3
0
        protected async override Task OnAfterRenderAsync(bool isFirstRender)
        {
            await JSRuntime.InvokeVoidAsync("doUserSelectDir");

            var queryString = QueryHelpers.ParseQuery(new Uri(NavigationManager.Uri).Query);

            ResourceReader = await BeatmapHelper.LoadNetworkResources(94790);

            /*
             * if (queryString.TryGetValue("sid", out var beatmapSetId))
             *  ResourceReader = await BeatmapHelper.LoadNetworkResources(int.Parse(beatmapSetId.ToString()));
             * else
             *  //尝试发起本地上传文件请求
             *  ResourceReader = await BeatmapHelper.LoadLocalResources();
             *
             * if (ResourceReader is null)
             * {
             *  //错误处理
             *  return;
             * }
             */

            Console.WriteLine("Start to select a .osb file and a .osu file (if it exist.)");
            var osbFilePath = ResourceReader.EnumeratePath("*.osb").FirstOrDefault();
            var osuFilePath = ResourceReader.EnumeratePath("*.osu").FirstOrDefault();

            Console.WriteLine("osu file : " + osuFilePath);
            Console.WriteLine("osb file : " + osbFilePath);

            var updater = StoryboardHelper.ParseStoryboard(ResourceReader.ReadFile(osuFilePath), ResourceReader.ReadFile(osbFilePath));

            Console.WriteLine($"Storyboard objects count : {updater.StoryboardObjectList.Count}");

            Console.WriteLine($"Start load render resource...");
            await StoryboardWindow.PrepareRenderResource(updater, ResourceReader);

            Console.WriteLine($"Render resource loading DONE!");

            StoryboardWindow.Play();

            Console.WriteLine($"OnAfterRenderAsync() end");
        }
Beispiel #4
0
    public static void ShowWindow()
    {
        StoryboardWindow window = EditorWindow.GetWindow <StoryboardWindow>();

        EditorWindow.FocusWindowIfItsOpen(typeof(StoryboardWindow));
    }
Beispiel #5
0
        /// <summary>
        /// Play a new file by file path.
        /// </summary>
        private async Task PlayNewFile(string path, bool play)
        {
            if (path == null)
            {
                return;
            }
            if (File.Exists(path))
            {
                try
                {
                    var osu = new OsuFile(path);
                    var fi  = new FileInfo(path);
                    if (!fi.Exists)
                    {
                        throw new FileNotFoundException("Cannot locate.", fi.FullName);
                    }
                    var dir = fi.Directory.FullName;

                    /* Clear */
                    ClearHitsoundPlayer();

                    /* Set new hitsound player*/
                    App.HitsoundPlayer = new HitsoundPlayer(path, osu);
                    _cts = new CancellationTokenSource();

                    /* Set Meta */
                    MapIdentity nowIdentity =
                        new MapIdentity(fi.Directory.Name, App.HitsoundPlayer.Osufile.Metadata.Version);

                    MapInfo mapInfo = DbOperator.GetMapFromDb(nowIdentity);
                    //BeatmapEntry entry = App.PlayerList.Entries.GetBeatmapByIdentity(nowIdentity);
                    BeatmapEntry entry   = App.Beatmaps.GetBeatmapByIdentity(nowIdentity);
                    OsuFile      osuFile = App.HitsoundPlayer.Osufile;

                    LblTitle.Content  = App.HitsoundPlayer.Osufile.Metadata.GetUnicodeTitle();
                    LblArtist.Content = App.HitsoundPlayer.Osufile.Metadata.GetUnicodeArtist();
                    ((ToolTip)NotifyIcon.TrayToolTip).Content =
                        (string)LblArtist.Content + " - " + (string)LblTitle.Content;
                    bool isFaved = SetFaved(nowIdentity);
                    App.HitsoundPlayer.SingleOffset = mapInfo.Offset;
                    Offset.Value = App.HitsoundPlayer.SingleOffset;

                    App.PlayerList.CurrentInfo =
                        new CurrentInfo(osuFile.Metadata.Artist,
                                        osuFile.Metadata.ArtistUnicode,
                                        osuFile.Metadata.Title,
                                        osuFile.Metadata.TitleUnicode,
                                        osuFile.Metadata.Creator,
                                        osuFile.Metadata.Source,
                                        osuFile.Metadata.TagList,
                                        osuFile.Metadata.BeatmapID,
                                        osuFile.Metadata.BeatmapSetID,
                                        entry != null
                                ? (entry.DiffStarRatingStandard.ContainsKey(Mods.None)
                                    ? entry.DiffStarRatingStandard[Mods.None]
                                    : 0)
                                : 0,
                                        osuFile.Difficulty.HPDrainRate,
                                        osuFile.Difficulty.CircleSize,
                                        osuFile.Difficulty.ApproachRate,
                                        osuFile.Difficulty.OverallDifficulty,
                                        App.MusicPlayer?.Duration ?? 0,
                                        nowIdentity,
                                        mapInfo,
                                        entry,
                                        isFaved);

                    /* Set Lyric */
                    SetLyric();

                    /* Set Progress */
                    //PlayProgress.Value = App.HitsoundPlayer.SingleOffset;
                    PlayProgress.Maximum = App.HitsoundPlayer.Duration;
                    PlayProgress.Value   = 0;
                    LblTotal.Content     = new TimeSpan(0, 0, 0, 0, App.HitsoundPlayer.Duration).ToString(@"mm\:ss");
                    LblNow.Content       = new TimeSpan(0, 0, 0, 0, App.HitsoundPlayer.PlayTime).ToString(@"mm\:ss");
#if DEBUG
                    /* Set Storyboard */
                    if (false)
                    {
                        if (_sbWindow == null || _sbWindow.IsClosed)
                        {
                            _sbWindow = new StoryboardWindow();
                            _sbWindow.Show();
                            App.StoryboardProvider = new Media.Storyboard.StoryboardProvider(_sbWindow);
                        }

                        App.StoryboardProvider.LoadStoryboard(dir, App.HitsoundPlayer.Osufile);
                    }
#endif
                    /* Set Video */
                    bool showVideo = ViewModel.EnableVideo && !ViewModel.IsMiniMode;
                    if (VideoElement != null)
                    {
                        await ClearVideoElement(showVideo);

                        if (showVideo)
                        {
                            var videoName = App.HitsoundPlayer.Osufile.Events.VideoInfo?.Filename;
                            if (videoName == null)
                            {
                                VideoElement.Source           = null;
                                VideoElementBorder.Visibility = System.Windows.Visibility.Hidden;
                            }
                            else
                            {
                                var vPath = Path.Combine(dir, videoName);
                                if (File.Exists(vPath))
                                {
                                    VideoElement.Source = new Uri(vPath);
                                    _videoOffset        = -App.HitsoundPlayer.Osufile.Events.VideoInfo.Offset;
                                    if (_videoOffset >= 0)
                                    {
                                        _waitAction = () => { };
                                        _position   = TimeSpan.FromMilliseconds(_videoOffset);
                                    }
                                    else
                                    {
                                        _waitAction = () => { Thread.Sleep(TimeSpan.FromMilliseconds(-_videoOffset)); };
                                    }
                                }
                                else
                                {
                                    VideoElement.Source           = null;
                                    VideoElementBorder.Visibility = System.Windows.Visibility.Hidden;
                                }
                            }
                        }
                    }

                    /* Set Background */
                    if (App.HitsoundPlayer.Osufile.Events.BackgroundInfo != null)
                    {
                        var bgPath = Path.Combine(dir, App.HitsoundPlayer.Osufile.Events.BackgroundInfo.Filename);
                        BlurScene.Source = File.Exists(bgPath) ? new BitmapImage(new Uri(bgPath)) : null;
                        Thumb.Source     = File.Exists(bgPath) ? new BitmapImage(new Uri(bgPath)) : null;
                    }
                    else
                    {
                        BlurScene.Source = null;
                    }

                    /* Start Play */
                    switch (MainFrame.Content)
                    {
                    case RecentPlayPage recentPlayPage:
                        var item = recentPlayPage.ViewModels.FirstOrDefault(k =>
                                                                            k.GetIdentity().Equals(nowIdentity));
                        recentPlayPage.RecentList.SelectedItem = item;
                        break;

                    case CollectionPage collectionPage:
                        collectionPage.MapList.SelectedItem =
                            collectionPage.ViewModels.FirstOrDefault(k =>
                                                                     k.GetIdentity().Equals(nowIdentity));
                        break;
                    }

                    _videoPlay = play;
                    if (play)
                    {
                        if (showVideo && VideoElement?.Source != null)
                        {
                            VideoPlay();
                            //App.HitsoundPlayer.Play();
                        }
                        else
                        {
                            App.HitsoundPlayer.Play();
                        }
                    }

                    //if (!App.PlayerList.Entries.Any(k => k.GetIdentity().Equals(nowIdentity)))
                    //    App.PlayerList.Entries.Add(entry);
                    App.Config.CurrentPath = path;
                    App.SaveConfig();

                    RunSurfaceUpdate();
                    DbOperator.UpdateMap(nowIdentity);
                }
                catch (MultiTimingSectionException ex)
                {
                    var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK,
                                             MessageBoxImage.Warning);
                    if (result == MessageBoxResult.OK)
                    {
                        if (App.HitsoundPlayer == null)
                        {
                            return;
                        }
                        if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing)
                        {
                            PlayNext(false, true);
                        }
                    }
                }
                catch (BadOsuFormatException ex)
                {
                    var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK,
                                             MessageBoxImage.Warning);
                    if (result == MessageBoxResult.OK)
                    {
                        if (App.HitsoundPlayer == null)
                        {
                            return;
                        }
                        if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing)
                        {
                            PlayNext(false, true);
                        }
                    }
                }
                catch (VersionNotSupportedException ex)
                {
                    var result = MsgBox.Show(this, @"铺面读取时发生问题:" + ex.Message, Title, MessageBoxButton.OK,
                                             MessageBoxImage.Warning);
                    if (result == MessageBoxResult.OK)
                    {
                        if (App.HitsoundPlayer == null)
                        {
                            return;
                        }
                        if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing)
                        {
                            PlayNext(false, true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    var result = MsgBox.Show(this, @"发生未处理的异常问题:" + (ex.InnerException ?? ex), Title,
                                             MessageBoxButton.OK, MessageBoxImage.Error);
                    if (result == MessageBoxResult.OK)
                    {
                        if (App.HitsoundPlayer == null)
                        {
                            return;
                        }
                        if (App.HitsoundPlayer.PlayerStatus != PlayerStatus.Playing)
                        {
                            PlayNext(false, true);
                        }
                    }

                    Console.WriteLine(ex);
                }
            }
            else
            {
                MsgBox.Show(this, string.Format(@"所选文件不存在{0}。", App.Beatmaps == null
                        ? ""
                        : " ,可能是db没有及时更新。请关闭此播放器或osu后重试"),
                            Title, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Beispiel #6
0
    public bool Simulate(StoryboardWindow window, Transform cameraTransform, StoryboardData data, TimelineAsset timeline, PlayableDirector playable,
                         ref int simulatedMarkerCount, string debugPositioning, string debugLook, string debugTrack, string debugFX, RenderTexture rt, bool simulateAll, int simulatedIndex = -1)
    {
        StoryboardNode previousNode = simulateAll ? null : (simulatedIndex == 0 ? null : data.m_nodes[simulatedIndex - 1]);

        int iStart = simulateAll ? 0 : simulatedIndex;
        int iEnd   = simulateAll ? data.m_nodes.Count : simulatedIndex + 1;

        for (int i = iStart; i < iEnd; i++)
        {
            StoryboardNode currentNode = data.m_nodes[i];

            if (currentNode.m_isLocked)
            {
                previousNode = currentNode;
                simulatedMarkerCount++;
                continue;
            }

            // Calculate target position
            SimulationTargetData targetData = new SimulationTargetData();
            targetData.m_target         = null;
            targetData.m_targetForward  = Vector3.forward;
            targetData.m_targetRight    = Vector3.right;
            targetData.m_targetUp       = Vector3.up;
            targetData.m_targetPosition = Vector3.zero;

            for (int j = 0; j < currentNode.m_marker.m_targets.Length; j++)
            {
                var objects = Resources.FindObjectsOfTypeAll <StoryboardTarget>().Where(obj => obj.gameObject.name == currentNode.m_marker.m_targets[j]);

                if (objects.Count <StoryboardTarget>() > 1)
                {
                    Debug.LogError("Multiple storyboard targets with the same name is found. Please make sure each target has a unique name to avoid any confusions.");
                    currentNode.m_simulationData = null;
                    data.m_nodes.Clear();
                    return(false);
                }

                GameObject go = GameObject.Find(currentNode.m_marker.m_targets[j]);

                if (go == null)
                {
                    Debug.LogError("The target " + currentNode.m_marker.m_targets[j] + " could not be found, aborting simulation.");
                    currentNode.m_simulationData = null;
                    data.m_nodes.Clear();
                    return(false);
                }

                targetData.m_targetPosition += go.transform.position;

                if (currentNode.m_marker.m_targets.Length == 1)
                {
                    targetData.m_target         = go.transform;
                    targetData.m_targetPosition = targetData.m_target.position;
                    targetData.m_targetForward  = targetData.m_target.forward;
                    targetData.m_targetRight    = targetData.m_target.right;
                    targetData.m_targetUp       = targetData.m_target.up;
                }
            }

            // Finalize target position as mid point.
            targetData.m_targetPosition /= currentNode.m_marker.m_targets.Length;

            StoryboardDirectorData      dirData = data.m_directorData;
            DecisionTechniquePreference pref    = data.m_decisionTechnique;
            float          dramThresh           = data.m_dramatizationThreshold;
            float          paceThresh           = data.m_paceThreshold;
            bool           useFX = data.m_useFX;
            bool           simulationSuccessful = false;
            int            timeoutCounter       = 0;
            StoryboardNode nextNode             = i < data.m_nodes.Count - 1 ? data.m_nodes[i + 1] : null;

            while (!simulationSuccessful && timeoutCounter < data.m_techniqueTimeout)
            {
                currentNode.m_positioningTechnique = GetTechnique("Positioning", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);
                currentNode.m_simulationData       = new SimulationData();
                simulationSuccessful = currentNode.m_positioningTechnique.m_implementation.Simulate(data, currentNode, nextNode, targetData);
                timeoutCounter++;
            }

            // Set simulation's target data.
            currentNode.m_simulationData.m_targetData = targetData;


            //currentNode.m_lookTechnique = GetTechnique("Look", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);
            //currentNode.m_trackTechnique = GetTechnique("Track", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);
            //currentNode.m_fxTechnique = GetTechnique("FX", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);

            // D E B U G
            if (debugPositioning != "")
            {
                currentNode.m_trackTechnique = data.m_directorData.m_categories[0].m_techniques.Find(o => o.m_title.CompareTo(debugPositioning) == 0);
            }
            if (debugLook != "")
            {
                currentNode.m_lookTechnique = data.m_directorData.m_categories[1].m_techniques.Find(o => o.m_title.CompareTo(debugLook) == 0);
            }
            if (debugTrack != "")
            {
                currentNode.m_trackTechnique = data.m_directorData.m_categories[2].m_techniques.Find(o => o.m_title.CompareTo(debugTrack) == 0);
            }
            if (debugFX != "")
            {
                currentNode.m_fxTechnique = data.m_directorData.m_categories[3].m_techniques.Find(o => o.m_title.CompareTo(debugFX) == 0);
            }

            ApplySimulationPropertiesToCamera(currentNode.m_simulationData, cameraTransform);
            currentNode.m_simulationData.m_snapshots.Add(TakeCameraSnapshot(cameraTransform.GetComponent <Camera>(), rt));

            previousNode = currentNode;
            simulatedMarkerCount++;
            targetData = null;
        }

        // Make sure we reset back the playable.
        playable.time = 0.0;
        playable.Evaluate();
        window.OnSimulationEnd();
        return(true);
    }