Unity에서 만들고있는 게임에 대한 재생 시스템이 있습니다. keyFrame 배열에있는 프레임의 프레임 버퍼까지 저장하고 프레임 버퍼를 넘은 후에 프레임을 바꿉니다. "Fire1"버튼 중 하나를 누르면. 프레임 버퍼보다 많은 프레임이 저장되어 있으면 재생이 잘되지만 프레임 버퍼보다 저장된 프레임이 적 으면 다시 재생되고 빈 프레임에 도달하면 프레임이 충분하지 않기 때문에 아무 것도 움직이지 않습니다 (What's Happening GIF)재생 시스템, 링 버퍼, 프레임 버퍼에 도달하기 전에 재생 시작
using UnityEngine;
using System.Collections;
public class ReplaySystem : MonoBehaviour
{
private const int bufferFrames = 500;
private MyKeyFrame[] keyFrames = new MyKeyFrame[bufferFrames];
private Rigidbody rigidBody;
// Use this for initialization
void Start()
{
rigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Fire1"))
PlayBack();
else
Record();
}
private void PlayBack()
{
rigidBody.isKinematic = true;
int frame = Time.frameCount % bufferFrames;
Debug.Log("Reading frame " + frame);
transform.position = keyFrames[frame].pos;
transform.rotation = keyFrames[frame].rot;
}
private void Record()
{
rigidBody.isKinematic = false;
int frame = Time.frameCount % bufferFrames;
float time = Time.time;
Debug.Log("Writing frame " + frame);
keyFrames[frame] = new MyKeyFrame(time, transform.position, transform.rotation);
}
}
/// <summary>
/// A Structure for storing time, position, and rotation
/// </summary>
public struct MyKeyFrame
{
public float frameTime;
public Vector3 pos;
public Quaternion rot;
public MyKeyFrame(float time, Vector3 pos, Quaternion rot)
{
frameTime = time;
this.pos = pos;
this.rot = rot;
}
}
은 어떻게 재생 프레임 버퍼보다 저장 프레임이 적은 경우 저장된 키 프레임의 수부터 시작합니까?
은 이미 시도했다 : - 다음 모듈을