Beispiel #1
0
        // Methods
        /// <summary>
        /// Called by Unity.
        /// </summary>
        public void Awake()
        {
            startPosition = transform.position;
            startRotation = transform.rotation;

            // Find or create a replay manager
            ReplayManager.ForceAwake();

            // Create default texture
            whitePixel = new Texture2D(1, 1);
            whitePixel.SetPixel(0, 0, Color.white);
            whitePixel.Apply();

            if (allowPlaybackFreeCam == true)
            {
                // Find free cam
                freeCam = GetComponent <Camera>();

                // Add the camera if one was not found
                if (freeCam == null)
                {
                    freeCam = gameObject.AddComponent <Camera>();
                }

                // Disable by default
                freeCam.enabled = false;
            }
        }
Beispiel #2
0
        private void ReplayGoLive()
        {
            // Stop all recording
            if (ReplayManager.IsRecording == true)
            {
                ReplayManager.StopRecording();
            }

            // Stop all playback
            if (ReplayManager.IsReplaying == true)
            {
                ReplayManager.StopPlayback();
            }
        }
Beispiel #3
0
        private void DrawGUISettings(Rect area)
        {
            GUILayout.BeginArea(area, GUI.skin.box);
            {
                // Playback speed
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Speed:", GUILayout.Width(55));
                    ReplayTime.TimeScale = GUILayout.HorizontalSlider(ReplayTime.TimeScale, 0, 2);
                }
                GUILayout.EndHorizontal();

                // Playback direction
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Reverse:", GUILayout.Width(55));
                    bool result = GUILayout.Toggle(reversePlay, string.Empty);

                    // Chcck for change
                    if (result != reversePlay)
                    {
                        reversePlay = result;

                        // Check if we are currently replaying
                        if (ReplayManager.IsReplaying == true)
                        {
                            // Check for reverse play
                            ReplayTime.TimeScale = (reversePlay == true) ? -1f : 1f;

                            // Refresh playback
                            ReplayManager.BeginPlayback(false);
                        }
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndArea();
        }
Beispiel #4
0
        /// <summary>
        /// Called by unity.
        /// </summary>
        public void OnGUI()
        {
            // Default label style
            GUIStyle labelStyle = new GUIStyle(GUI.skin.label);

            labelStyle.fontStyle = FontStyle.Bold;


            // Create the gui screen area
            GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));
            {
                GUILayout.BeginHorizontal();
                {
                    // Create a button style
                    GUIStyle button = new GUIStyle(GUI.skin.button);
                    button.fontSize = 50;

                    button.padding = new RectOffset(3, 3, 3, 3);
                    button.margin  = new RectOffset(-1, -1, 0, 0);

                    GUI.color = (ReplayManager.IsRecording == false && ReplayManager.IsReplaying == false) ? highlight : normal;

                    if (GUILayout.Button(new GUIContent("Live", "Live mode"), button, GUILayout.Width(stateButtonWidth), GUILayout.Height(stateButtonHeight)) == true ||
                        IsReplayKeyPressed(liveModeShortcut) == true)
                    {
                        // Exit free cam
                        ExitPlaybackFreeCam();

                        // Live mode is just game mode (No replay element)
                        ReplayGoLive();
                    }

                    GUI.color = (ReplayManager.IsRecording == true) ? highlight : normal;

                    if (GUILayout.Button(new GUIContent("Rec", recordTexture, "Begin recording"), button, GUILayout.Width(stateButtonWidth), GUILayout.Height(stateButtonHeight)) == true ||
                        IsReplayKeyPressed(recordModeShortcut) == true)
                    {
                        // Exit free cam
                        ExitPlaybackFreeCam();

                        // Start a fresh recording
                        ReplayManager.BeginRecording(false);
                    }

                    GUI.color = (ReplayManager.IsReplaying == true) ? highlight : normal;

                    if (GUILayout.Button(new GUIContent("Play", playbackTexture, "Begin playback"), button, GUILayout.Width(stateButtonWidth), GUILayout.Height(stateButtonHeight)) == true ||
                        IsReplayKeyPressed(playModeShortcut) == true)
                    {
                        // Enable the free cam
                        if (allowPlaybackFreeCam == true)
                        {
                            EnterPlaybackFreeCam();
                        }

                        // Start playback
                        ReplayManager.BeginPlayback();
                    }

                    GUI.color = highlight;

                    // Push to right
                    GUILayout.FlexibleSpace();

                    // Recording status
                    if (ReplayManager.IsRecording == true)
                    {
                        string recordTime = ReplayTime.GetCorrectedTimeValueString(ReplayManager.Target.Duration);

                        GUILayout.Label(string.Format("Recording: {0}", recordTime), labelStyle);
                        labelStyle.fontSize = 50;

                        // Draw recoring lines
                        // Top left
                        DrawGUILine(new Vector2(50, 50), new Vector2(80, 50));
                        DrawGUILine(new Vector2(50, 50), new Vector2(50, 80));

                        // Top right
                        DrawGUILine(new Vector2(Screen.width - 80, 50), new Vector2(Screen.width - 50, 50));
                        DrawGUILine(new Vector2(Screen.width - 50, 50), new Vector2(Screen.width - 50, 80));

                        // Bottom left
                        DrawGUILine(new Vector2(50, Screen.height - 50), new Vector2(80, Screen.height - 50));
                        DrawGUILine(new Vector2(50, Screen.height - 50), new Vector2(50, Screen.height - 80));

                        // Bottom right
                        DrawGUILine(new Vector2(Screen.width - 80, Screen.height - 50), new Vector2(Screen.width - 50, Screen.height - 50));
                        DrawGUILine(new Vector2(Screen.width - 50, Screen.height - 50), new Vector2(Screen.width - 50, Screen.height - 80));
                    }

                    if (ReplayManager.IsReplaying == true)
                    {
                        if (allowPlaybackFreeCam == true && freeCam != null)
                        {
                            GUILayout.BeginVertical();
                            {
                                // Draw the free cam label
                                GUILayout.Label("Free Cam Enabled", labelStyle);

                                GUI.color = new Color(0.3f, 0.3f, 0.3f);

                                GUIStyle subLabelStyle = new GUIStyle(GUI.skin.label);
                                subLabelStyle.padding   = new RectOffset(0, 0, -2, -2);
                                subLabelStyle.fontSize  = 10;
                                subLabelStyle.alignment = TextAnchor.MiddleRight;

                                // Draw hint label
                                GUILayout.Label("Free Move: WASD", subLabelStyle);
                                GUILayout.Label("Free Look: RMB", subLabelStyle);

                                GUI.color = Color.white;
                            }
                            GUILayout.EndVertical();
                        }
                    }
                }
                GUILayout.EndHorizontal();

                // Push to bottom
                GUILayout.FlexibleSpace();

                // Make sure we are not recording for the playback controls
                if (ReplayManager.IsReplaying == true)
                {
                    GUILayout.BeginHorizontal();
                    {
                        // Check for paused
                        if (ReplayManager.IsPaused == true)
                        {
                            // Draw a play button
                            if (GUILayout.Button(playTexture, GUILayout.Width(playPauseWidth), GUILayout.Height(playPauseHeight)) == true)
                            {
                                // Check for reverse play
                                ReplayTime.TimeScale = (reversePlay == true) ? -1f : 1f;

                                // Begin playback from current location
                                ReplayManager.BeginPlayback(false);
                            }
                        }
                        else
                        {
                            // Draw a pause button
                            if (GUILayout.Button(pauseTexture, GUILayout.Width(playPauseWidth), GUILayout.Height(playPauseHeight)) == true)
                            {
                                // Pause playback
                                ReplayManager.PausePlayback();
                            }
                        }

                        // Slider space
                        GUILayout.BeginVertical();
                        {
                            // Push down slightly
                            GUILayout.Space(10);

                            float input = ReplayManager.CurrentPlaybackTimeNormalized;

                            // Draw the seek slider
                            float output = GUILayout.HorizontalSlider(input, 0, 1, GUILayout.Height(playPauseHeight));

                            // Check for change
                            if (input != output)
                            {
                                ReplayManager.SetPlaybackFrameNormalized(output);
                            }
                        }
                        GUILayout.EndVertical();

                        // Settings button
                        if (GUILayout.Button(new GUIContent(settingsTexture, "Open playback settings"), GUILayout.Width(playPauseWidth), GUILayout.Height(playPauseHeight)) == true)
                        {
                            // Toggle settings
                            showSettings = !showSettings;
                        }

                        // Check for settings window
                        if (showSettings == true)
                        {
                            Rect area = new Rect(Screen.width - 160, Screen.height - 100, 140, 50);

                            DrawGUISettings(area);
                        }

                        string currentTime = ReplayTime.GetCorrectedTimeValueString(ReplayManager.CurrentPlaybackTime);
                        string totalTime   = ReplayTime.GetCorrectedTimeValueString(ReplayManager.Target.Duration);

                        GUILayout.Label(string.Format("{0} / {1}", currentTime, totalTime), GUI.skin.button, GUILayout.Width(75));
                    }
                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.EndArea();
        }