示例#1
0
    private void RecordFrame()
    {
        if (recordIndex < frames.Length)
        {
            recordTime += Time.smoothDeltaTime * 1000;
            GhostShot newFrame = new GhostShot()
            {
                timeMark = recordTime,
                posMark  = transform.position,
                rotMark  = transform.rotation
            };

            frames[recordIndex] = newFrame;

            recordIndex++;
        }
        else
        {
            StopRecording();
        }
    }
示例#2
0
    private void Update()
    {
        if (IsReplaying())
        {
            if (replayIndex < frames.Length)
            {
                GhostShot frame = frames[replayIndex];

                if (!frame.isFinal)
                {
                    if (replayTime < frame.timeMark)
                    {
                        if (replayIndex == 0)
                        {
                            replayTime = frame.timeMark;
                        }
                        else
                        {
                            DoLerp(frames[replayIndex - 1], frame);
                            replayTime += Time.smoothDeltaTime * 1000 * replayTimescale;
                        }
                    }
                    else
                    {
                        replayIndex++;
                    }
                }
                else
                {
                    StopReplay();
                }
            }
            else
            {
                StopReplay();
            }
        }
    }
示例#3
0
    void RecordSnapshot()
    {
        if (IsRecording())
        {
            if (recordingIndex < shots.Length)
            {
                recordingTime += Time.deltaTime;                                // increase the elapsed time
                GhostShot newShot = new GhostShot(false);                       // create a new GhostShot

                newShot.timeBegin = recordingTime;                              // mark the beginning time
                newShot.timeEnd   = newShot.timeBegin + snapshotFrequency;      // mark the end time by adding snapshotFrequency

                if (recordingIndex > 0)                                         // if this isn't the first shot...
                {
                    newShot.posBegin = shots[recordingIndex - 1].posEnd;        // ...then mark the previous position as a beginning position for this shot
                    newShot.rotBegin = shots[recordingIndex - 1].rotEnd;
                }
                else
                {
                    newShot.posBegin = recordTarget.transform.position;         // ...otherwise mark the current position as the beginning position for this shot
                    newShot.rotBegin = recordTarget.transform.rotation;
                }

                newShot.posEnd = recordTarget.transform.position;
                newShot.rotEnd = recordTarget.transform.rotation;

                shots[recordingIndex] = newShot;                                // allocate the new shot to a specified array item

                recordingIndex++;                                               // increase the index
            }
            else
            {
                StopRecording();
            }
        }
    }
示例#4
0
 private void DoLerp(GhostShot a, GhostShot b)
 {
     transform.position = Vector3.Slerp(a.posMark, b.posMark, Mathf.Clamp(replayTime, a.timeMark, b.timeMark));
     transform.rotation = Quaternion.Slerp(a.rotMark, b.rotMark, Mathf.Clamp(replayTime, a.timeMark, b.timeMark));
 }