PlayerReplay.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerReplay : MonoBehaviour
  5. {
  6. public Transform[] joints = new Transform[25];
  7. public Material boneMaterial;
  8. // (need to implement controller click to trigger save)
  9. public void Save()
  10. {
  11. SaveSystem.Save(this);
  12. }
  13. public void Load()
  14. {
  15. JointsData data = SaveSystem.Load();
  16. if(data == null)
  17. {
  18. Debug.Log("Load failed");
  19. return;
  20. }
  21. for(int i = 0; i < joints.Length; i++)
  22. {
  23. // Create GameObject cubes for joints
  24. GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
  25. LineRenderer lr = jointObj.AddComponent<LineRenderer>();
  26. lr.positionCount = 2;
  27. lr.material = boneMaterial;
  28. lr.startWidth = 0.3f;
  29. lr.endWidth = 0.3f;
  30. jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
  31. // (need to test)
  32. jointObj.transform.position = new Vector3(data.jointsPositionsX[i], data.jointsPositionsY[i], data.jointsPositionsZ[i]);
  33. // Connect the joints with LineRenderer
  34. }
  35. }
  36. }