Exemple #1
0
		public override void InvokeAction(object sender, EventArgs e)
		{
            windowCount++;
            RecordFrame doc = new RecordFrame();
            doc.Text = "Record " + windowCount.ToString();
            doc.MdiParent = MainWindow;
            doc.Show();
		}
    //Recordng all values every frame
    private void FixedUpdate()
    {
        RecordFrame recordFrame = new RecordFrame();

        recordFrame.position = transform.position;
        recordFrame.rotation = transform.rotation;
        if (isPlayer1)
        {
            recordFrame.isShooting = Input.GetKeyDown(KeyCode.Space);
        }
        else
        {
            recordFrame.isShooting = Input.GetKeyDown(KeyCode.Keypad0);
        }
        recordFrame.weaponIndex = pd.weaponIndex;
        recordFrame.hasWeapon   = pd.hasWeapon;
        recordFrame.velocity    = rb2d.velocity;
        recordFrame.isOnGround  = pc.isOnGround;
        record.Add(recordFrame);
    }
    private void TimelineLoop()
    {
        var frames = (int)(RecordingLength / FixedTime);

        if (_localFrame < 0 && PlayState == PlaybackState.Reversed)
        {
            if (Clones.Any(c => c.Index == _loops - 1))
            {
                if (!LevelManager.Instance.Ending)
                {
                    foreach (var clone in Clones.ToList())
                    {
                        clone.Index--;
                        if (clone.Index < 0)
                        {
                            Clones.RemoveAll(x => x.Index == clone.Index);
                            Destroy(clone.gameObject);
                        }
                    }
                }
                else
                {
                    if (_ending)
                    {
                        foreach (var clone in Clones.ToList())
                        {
                            clone.Index--;

                            if (clone.Index < 0)
                            {
                                Clones.RemoveAll(x => x.Index == clone.Index);
                                Destroy(clone.gameObject);
                            }
                        }
                        _ending = false;
                    }
                }

                if (OnResetTimeline != null)
                {
                    OnResetTimeline();
                }

                _loops--;
                TimelineStart();
                _localFrame = frames - 1;
            }
        }
        else if (_localFrame >= frames && PlayState == PlaybackState.Playing)
        {
            if (_globalFrame > 0)
            {
                if (!LevelManager.Instance.Ending)
                {
                    Recordings.Add(_currentRecording);

                    foreach (var clone in Clones.ToList())
                    {
                        clone.Index++;
                    }
                }
                else
                {
                    if (_ending)
                    {
                        foreach (var clone in Clones.ToList())
                        {
                            clone.Index++;
                        }
                        _ending = false;
                    }
                }

                var newClone = CreateClone();
                newClone.Index = 0;
                Clones.Add(newClone);

                if (OnResetTimeline != null)
                {
                    OnResetTimeline();
                }

                _loops++;
                TimelineStart();
            }
        }

        if (!LevelManager.Instance.Ending)
        {
            //Record
            var newRecording = new RecordFrame
            {
                Position = Player.position
            };
            try
            {
                _currentRecording[_localFrame] = newRecording;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

        //Play
        if (Recordings.Count > 0)
        {
            foreach (var clone in Clones.ToList())
            {
                if (!clone)
                {
                    Clones.RemoveAll(x => x.Index == clone.Index);
                    continue;
                }

                var rec = Recordings[clone.Index];

                if (rec[_localFrame] != null)
                {
                    clone.transform.position = rec[_localFrame].Position;
                }
            }
        }

        if (!Paused && !GameManager.Instance.AllowBackwardsTime)
        {
            if (PlayState == PlaybackState.Reversed)
            {
                _localFrame--;
                _globalFrame--;

                if (_localFrame < -1 && _globalFrame >= 0)
                {
                    _localFrame = frames - 1;
                }
            }
            else
            {
                _localFrame++;
                _globalFrame++;

                if (_localFrame >= frames + 1)
                {
                    _localFrame = 0;
                }
            }
        }
    }