Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace iGP
  6. {
  7. public struct T
  8. {
  9. ...
  10. }
  11.  
  12. public class AppSession : MonoBehaviour
  13. {
  14. ////////////////////////////////////////////////////////////////////////////////////////////////////
  15. ///Unity event calls
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////
  17. public void Awake()
  18. {
  19. Reset();
  20. }
  21.  
  22. public void Update()
  23. {
  24. currentDeltaTime += Time.Delta;
  25. if ( currentDeltaTime > speed )
  26. {
  27. LinkedList sortedInterpolateData = SortData();
  28. Interpolate(sortedInterpolateData);
  29. Reset();
  30. }
  31. }
  32.  
  33. public void OnDestroy()
  34. {
  35. T.Clear();
  36. T = null;
  37. }
  38.  
  39. public void OnEnable()
  40. {
  41. NetworkService.onReceive += Receive;
  42. }
  43.  
  44. public void OnDisable()
  45. {
  46. NetworkService.onReceive -= Receive;
  47. }
  48.  
  49. ////////////////////////////////////////////////////////////////////////////////////////////////////
  50. //Public fields
  51. ////////////////////////////////////////////////////////////////////////////////////////////////////
  52. public void InterpolateAll( LinkedList<T> sortedInterpolateData )
  53. {
  54. var currentNode = sortedInterpolateData.First;
  55. while (currentNode != null)
  56. {
  57. t = Lerp(currentNode.Value);
  58. }
  59. }
  60.  
  61. ////////////////////////////////////////////////////////////////////////////////////////////////////
  62. //Private methods
  63. ////////////////////////////////////////////////////////////////////////////////////////////////////
  64. private void Receive(T newT)
  65. {
  66. interpolateData.AddLast(newT);
  67. }
  68.  
  69. private void Reset()
  70. {
  71. T = new LinkedList<T>();
  72. currentDeltaTime = 0.0f;
  73. }
  74.  
  75. private LinkedList<T> SortData()
  76. {
  77. ...
  78. }
  79.  
  80. private T Lerp( T t)
  81. {
  82. ...
  83. }
  84.  
  85. ////////////////////////////////////////////////////////////////////////////////////////////////////
  86. //Fields serialized by unity, you can see them in the inspector
  87. ////////////////////////////////////////////////////////////////////////////////////////////////////
  88. [SerializeField] private float speed;
  89.  
  90. ////////////////////////////////////////////////////////////////////////////////////////////////////
  91. //Private fields
  92. ////////////////////////////////////////////////////////////////////////////////////////////////////
  93. private float currentDeltaTime = 0.0f;
  94. private T t = null;
  95. private LinkedList<float> interpolateData;
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement