/// <summary> /// Generates a List of FixedQueues of StateDescriptors from the given byte buffer. /// </summary> /// <param name="buffer"></param> /// <returns></returns> private static List <FixedQueue <StateDescriptor> > ReadStates(byte[] buffer) { IFormatter formatter = new BinaryFormatter(); List <FixedQueue <StateDescriptor> > states = new List <FixedQueue <StateDescriptor> >(); int stateSize = System.Runtime.InteropServices.Marshal.SizeOf(new StateDescriptor()); MemoryStream ms = new MemoryStream(buffer); while (ms.Position < ms.Length) { FixedQueue <StateDescriptor> currentStates = new FixedQueue <StateDescriptor>(Tracker.Length); for (int i = 0; i < Tracker.Length; i++) { currentStates.Add((StateDescriptor)formatter.Deserialize(ms)); } states.Add(currentStates); } return(states); }
/// <summary> /// Creates a new ReplayState instance. /// </summary> public ReplayState(string fieldPath, FixedQueue <List <ContactDescriptor> > contactPoints) { tStart = Time.time; this.fieldPath = fieldPath; this.contactPoints = contactPoints.ToList(); trackers = UnityEngine.Object.FindObjectsOfType <Tracker>().ToList(); playbackMode = PlaybackMode.Paused; firstFrame = true; active = false; contactThreshold = Mathf.Sqrt(30f); DynamicCamera.MovingEnabled = true; Texture2D thumbTexture = (Texture2D)Resources.Load("Images/thumb"); Texture2D rewindTexture = (Texture2D)Resources.Load("Images/rewind"); Texture2D rewindHoverTexture = (Texture2D)Resources.Load("Images/rewindHover"); Texture2D rewindPressedTexture = (Texture2D)Resources.Load("Images/rewindPressed"); Texture2D stopTexture = (Texture2D)Resources.Load("Images/stop"); Texture2D stopHoverTexture = (Texture2D)Resources.Load("Images/stopHover"); Texture2D stopPressedTexture = (Texture2D)Resources.Load("Images/stopPressed"); Texture2D playTexture = (Texture2D)Resources.Load("Images/play"); Texture2D playHoverTexture = (Texture2D)Resources.Load("Images/playHover"); Texture2D playPressedTexture = (Texture2D)Resources.Load("Images/playPressed"); Texture2D collisionTexture = (Texture2D)Resources.Load("Images/collision"); Texture2D collisionHoverTexture = (Texture2D)Resources.Load("Images/collisionHover"); Texture2D collisionPressedTexture = (Texture2D)Resources.Load("Images/collisionPressed"); Texture2D consolidateTexture = (Texture2D)Resources.Load("Images/consolidate"); Texture2D consolidateHoverTexture = (Texture2D)Resources.Load("Images/consolidateHover"); Texture2D consolidatePressedTexture = (Texture2D)Resources.Load("Images/consolidatePressed"); circleTexture = (Texture)Resources.Load("Images/circle"); keyframeTexture = (Texture)Resources.Load("Images/keyframe"); Texture2D sliderBackground = new Texture2D(1, 1); sliderBackground.SetPixel(0, 0, new Color(0.1f, 0.15f, 0.15f, 0.75f)); sliderBackground.Apply(); windowStyle = new GUIStyle { alignment = TextAnchor.UpperLeft, normal = new GUIStyleState { background = sliderBackground, textColor = Color.white } }; thumbStyle = new GUIStyle { fixedWidth = ThumbWidth, fixedHeight = ThumbHeight, normal = new GUIStyleState { background = thumbTexture } }; rewindStyle = CreateButtonStyle("rewind"); stopStyle = CreateButtonStyle("stop"); playStyle = CreateButtonStyle("play"); collisionStyle = CreateButtonStyle("collision"); consolidateStyle = CreateButtonStyle("consolidate"); }