|
@@ -5,7 +5,9 @@ using Kinect = Windows.Kinect;
|
|
|
|
|
|
public class PlayerReplay : MonoBehaviour
|
|
|
{
|
|
|
+
|
|
|
public Transform[] joints = new Transform[25];
|
|
|
+ public List<Transform[]> jointsSequence = new List<Transform[]>();
|
|
|
public Material boneMaterial;
|
|
|
|
|
|
private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>()
|
|
@@ -40,22 +42,25 @@ public class PlayerReplay : MonoBehaviour
|
|
|
{ Kinect.JointType.Neck, Kinect.JointType.Head },
|
|
|
};
|
|
|
|
|
|
+ public void AddJoints()
|
|
|
+ {
|
|
|
+ jointsSequence.Add(joints);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
public void Save()
|
|
|
{
|
|
|
- if(joints[0] == null)
|
|
|
+ if(jointsSequence.Count == 0)
|
|
|
{
|
|
|
- Debug.Log("joints have not been assigned");
|
|
|
+ Debug.Log("jointsSequence is empty");
|
|
|
return;
|
|
|
}
|
|
|
- SaveSystem.Save(this);
|
|
|
+ SaveSystem.Save(jointsSequence);
|
|
|
Debug.Log("Save success");
|
|
|
}
|
|
|
|
|
|
public void Load()
|
|
|
{
|
|
|
- JointsData data = SaveSystem.Load();
|
|
|
+ JointsDataSequence data = SaveSystem.Load();
|
|
|
|
|
|
if (data == null)
|
|
|
{
|
|
@@ -63,50 +68,60 @@ public class PlayerReplay : MonoBehaviour
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- GameObject body = new GameObject("Recorded Body");
|
|
|
- for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
|
|
|
- {
|
|
|
-
|
|
|
- if (jt == Kinect.JointType.Head)
|
|
|
- continue;
|
|
|
-
|
|
|
-
|
|
|
- GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
|
- LineRenderer lr = jointObj.AddComponent<LineRenderer>();
|
|
|
- lr.positionCount = 2;
|
|
|
- lr.material = boneMaterial;
|
|
|
- lr.startWidth = 0.3f;
|
|
|
- lr.endWidth = 0.3f;
|
|
|
-
|
|
|
- jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
|
|
|
- jointObj.name = jt.ToString();
|
|
|
- jointObj.transform.position = new Vector3(data.jointsPositionsX[(int)jt], data.jointsPositionsY[(int)jt], data.jointsPositionsZ[(int)jt]);
|
|
|
- jointObj.transform.parent = body.transform;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
|
|
|
- {
|
|
|
-
|
|
|
- if (!_BoneMap.ContainsKey(jt) || jt == Kinect.JointType.Neck)
|
|
|
- continue;
|
|
|
-
|
|
|
-
|
|
|
- Transform jointObj = body.transform.Find(jt.ToString());
|
|
|
- LineRenderer lr = jointObj.GetComponent<LineRenderer>();
|
|
|
-
|
|
|
+ StartCoroutine(ShowJoints(data));
|
|
|
|
|
|
- Transform targetJoint = body.transform.Find(_BoneMap[jt].ToString());
|
|
|
-
|
|
|
- lr.SetPosition(0, jointObj.localPosition);
|
|
|
- lr.SetPosition(1, targetJoint.localPosition);
|
|
|
+ Debug.Log("Load success");
|
|
|
+ }
|
|
|
|
|
|
+ private IEnumerator ShowJoints(JointsDataSequence data)
|
|
|
+ {
|
|
|
+
|
|
|
+ WaitForSeconds wait = new WaitForSeconds(2);
|
|
|
+ List<JointsData> jointsData = data.jointsDataSequence;
|
|
|
|
|
|
+ foreach(JointsData jd in jointsData)
|
|
|
+ {
|
|
|
+
|
|
|
+ GameObject body = new GameObject("Recorded Body");
|
|
|
+ for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (jt == Kinect.JointType.Head)
|
|
|
+ continue;
|
|
|
+
|
|
|
+
|
|
|
+ GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
|
+ LineRenderer lr = jointObj.AddComponent<LineRenderer>();
|
|
|
+ lr.positionCount = 2;
|
|
|
+ lr.material = boneMaterial;
|
|
|
+ lr.startWidth = 0.3f;
|
|
|
+ lr.endWidth = 0.3f;
|
|
|
+
|
|
|
+ jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
|
|
|
+ jointObj.name = jt.ToString();
|
|
|
+ jointObj.transform.position = new Vector3(jd.jointsPositionsX[(int)jt], jd.jointsPositionsY[(int)jt], jd.jointsPositionsZ[(int)jt]);
|
|
|
+ jointObj.transform.parent = body.transform;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!_BoneMap.ContainsKey(jt) || jt == Kinect.JointType.Neck)
|
|
|
+ continue;
|
|
|
+
|
|
|
+
|
|
|
+ Transform jointObj = body.transform.Find(jt.ToString());
|
|
|
+ LineRenderer lr = jointObj.GetComponent<LineRenderer>();
|
|
|
+
|
|
|
+
|
|
|
+ Transform targetJoint = body.transform.Find(_BoneMap[jt].ToString());
|
|
|
+
|
|
|
+ lr.SetPosition(0, jointObj.localPosition);
|
|
|
+ lr.SetPosition(1, targetJoint.localPosition);
|
|
|
+ }
|
|
|
+
|
|
|
+ yield return wait;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Debug.Log("Load success");
|
|
|
}
|
|
|
}
|