Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3.  
  4. public class RecPlay : MonoBehaviour {
  5.  
  6. List<Vector3> vectors;
  7. List<Quaternion> angles;
  8.  
  9. enum State { Null, isRecodring, isPlaying, isStopped, isPaused, isRewinding }
  10. State recorderState = State.Null;
  11.  
  12. bool isInverse = false;
  13.  
  14. int count = 0;
  15. int totalFrames = 0;
  16.  
  17. GameObject[] recordables;
  18. List<Vector3>[] gvectors;
  19. List<Quaternion>[] gangles;
  20.  
  21.  
  22. void Start () {
  23.  
  24. vectors = new List<Vector3>();
  25. angles = new List<Quaternion> ();
  26.  
  27. recordables = GameObject.FindGameObjectsWithTag ("Recordable");
  28.  
  29. gvectors = new List<Vector3>[recordables.Length];
  30. gangles = new List<Quaternion>[recordables.Length];
  31.  
  32. for (int n = 0; n<recordables.Length; n++) {
  33. gvectors [n] = new List<Vector3> ();
  34. gangles [n] = new List<Quaternion>();
  35. }
  36. }
  37.  
  38. void Update () {
  39. switch (recorderState)
  40. {
  41. case State.Null:
  42. break;
  43. case State.isRecodring:
  44. Record(recordables);
  45. break;
  46. case State.isPlaying:
  47. Play(recordables);
  48. break;
  49. case State.isStopped:
  50. break;
  51. case State.isPaused:
  52. Pause(recordables);
  53. break;
  54. case State.isRewinding:
  55. Rewind(recordables);
  56. break;
  57. }
  58. }
  59.  
  60. public void Record(GameObject[] rec){
  61.  
  62. for (int b = 0; b<gvectors.Length; b++) {
  63. gvectors[b].Add (rec[b].transform.position);
  64. gangles[b].Add (rec[b].transform.rotation);
  65. }
  66. totalFrames = gvectors[0].Count - 1;
  67. }
  68.  
  69. void Play(GameObject[] rec){
  70.  
  71. isInverse = false;
  72. if (count < gvectors[0].Count) {
  73. for (int b = 0; b<gvectors.Length; b++) {
  74. rec[b].transform.position = gvectors[b][count];
  75. rec[b].transform.rotation = gangles[b][count];
  76. }
  77. count++;
  78. } else {
  79. count = 0;
  80. }
  81. }
  82.  
  83. void Pause(GameObject[] rec)
  84. {
  85. if (!isInverse)
  86. {
  87. for (int b = 0; b < gvectors.Length; b++)
  88. {
  89. rec[b].transform.position = gvectors[b][count];
  90. rec[b].transform.rotation = gangles[b][count];
  91. }
  92. }
  93. if (isInverse)
  94. {
  95. for (int b = 0; b < gvectors.Length; b++)
  96. {
  97. rec[b].transform.position = gvectors[b][totalFrames];
  98. rec[b].transform.rotation = gangles[b][totalFrames];
  99. }
  100. }
  101. }
  102.  
  103. void Rewind(GameObject[] rec)
  104. {
  105. isInverse = true;
  106. if (totalFrames != 0)
  107. {
  108. for (int b = 0; b < gvectors.Length; b++)
  109. {
  110. rec[b].transform.position = gvectors[b][totalFrames];
  111. rec[b].transform.rotation = gangles[b][totalFrames];
  112. }
  113. totalFrames--;
  114. }
  115. else
  116. {
  117. totalFrames = gvectors[0].Count - 1;
  118. }
  119. }
  120.  
  121. public void ChangeState(int state)
  122. {
  123. recorderState = (State)state;
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement