public void StateDefinitionTestSimplePasses() { DummyClass dc = new DummyClass(); DummyClass copy = new DummyClass(); dc.i = 1; dc.f = 2f; dc.d = 3d; dc.l = 4L; dc.v = new Vector3(1, 2, 3); dc.q = Quaternion.Euler(30f, 45f, 15f); dc.notRecorded = 1; StateDefinition sd = StateDefinitionFactory.CreateDefinition(typeof(DummyClass), "i", "f"); byte[] bytes = sd.GetState(dc); Debug.Log("State of data container: " + System.BitConverter.ToString(bytes)); sd.SetState(copy, bytes); Assert.AreEqual(dc.i, copy.i); Assert.AreEqual(dc.f, copy.f); Assert.AreEqual(dc.d, copy.d); Assert.AreEqual(dc.l, copy.l); Assert.AreNotEqual(dc.notRecorded, copy.notRecorded); }
/// <summary> /// Sets the state of an object to the state it had in the given sample index. /// If there was no recording data for the given sample, or the sample index is /// out of range, the state will not be set. /// Returns true if the state was set. /// </summary> /// <param name="o"></param> /// <param name="sampleIdx"></param> private bool SetState(object o, int sampleIdx) { RecordableMetadata meta = GetMetadata(o); StateDefinition def = GetDefinition(o.GetType()); byte[][] sample = samples[sampleIdx]; if (meta.id < sample.Length) { def.SetState(o, sample[meta.id]); return(true); } return(false); }