Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace iGP
- {
- public struct T
- {
- ...
- }
- public class AppSession : MonoBehaviour
- {
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- ///Unity event calls
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- public void Awake()
- {
- Reset();
- }
- public void Update()
- {
- currentDeltaTime += Time.Delta;
- if ( currentDeltaTime > speed )
- {
- LinkedList sortedInterpolateData = SortData();
- Interpolate(sortedInterpolateData);
- Reset();
- }
- }
- public void OnDestroy()
- {
- T.Clear();
- T = null;
- }
- public void OnEnable()
- {
- NetworkService.onReceive += Receive;
- }
- public void OnDisable()
- {
- NetworkService.onReceive -= Receive;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- //Public fields
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- public void InterpolateAll( LinkedList<T> sortedInterpolateData )
- {
- var currentNode = sortedInterpolateData.First;
- while (currentNode != null)
- {
- t = Lerp(currentNode.Value);
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- //Private methods
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- private void Receive(T newT)
- {
- interpolateData.AddLast(newT);
- }
- private void Reset()
- {
- T = new LinkedList<T>();
- currentDeltaTime = 0.0f;
- }
- private LinkedList<T> SortData()
- {
- ...
- }
- private T Lerp( T t)
- {
- ...
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- //Fields serialized by unity, you can see them in the inspector
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- [SerializeField] private float speed;
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- //Private fields
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- private float currentDeltaTime = 0.0f;
- private T t = null;
- private LinkedList<float> interpolateData;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement