Skip to content
Snippets Groups Projects
Commit 54933124 authored by Alexis Iakovenko's avatar Alexis Iakovenko
Browse files

Implement replay feature

parent ae2abcca
No related branches found
No related tags found
No related merge requests found
fileFormatVersion: 2
guid: 3bbfbb7ed0825dd4f8cb95c6b6ee0090
folderAsset: yes
timeCreated: 1512997841
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File moved
File moved
File moved
File moved
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Replay : MonoBehaviour
{
public string gestureToLoad = "swing/1";
Gesture gestureToReplay;
int currentFrame = -1;
float lastTimestamp = 0;
void Start ()
{
gestureToReplay = new Gesture (gestureToLoad);
lastTimestamp = Time.unscaledTime;
}
void Update ()
{
if (currentFrame < gestureToReplay.states.Count - 2) //if replay not finished
{
//compute criteria to go to the next frame
bool goToNextFrame = false;
if (currentFrame == -1)
goToNextFrame = true;
else
{
float timePast = Time.unscaledTime - lastTimestamp;
if (timePast >= gestureToReplay.states [currentFrame + 1].timestamp - gestureToReplay.states [currentFrame].timestamp)
goToNextFrame = true;
}
//apply next frame
if (goToNextFrame)
{
currentFrame++;
Vector3 framePosition = gestureToReplay.states [currentFrame].position;
transform.position = framePosition;
Debug.Log ("[Replay] applying position " + framePosition +", key: " + currentFrame);
lastTimestamp = Time.unscaledTime;
}
}
}
}
fileFormatVersion: 2
guid: 04957c95584773b488c1ee790d2da0a8
timeCreated: 1512997497
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment