Пример #1
0
        public void WeCanSampleOnAPrivateField()
        {
            SampleTester<Vector3> test = new SampleTester<Vector3>();
            Vector3Sampler sampler = new Vector3Sampler(test, "privateField", x, y, z);
            Vector3 oldValue = test.property;

            sampler.Sample(0.5f);

            Assert.That(test.GetPrivateField(), Is.Not.EqualTo(oldValue));
        }
Пример #2
0
        public void WeCanSampleOnAPrivateField()
        {
            SampleTester <Vector3> test    = new SampleTester <Vector3>();
            Vector3Sampler         sampler = new Vector3Sampler(test, "privateField", x, y, z);
            Vector3 oldValue = test.property;

            sampler.Sample(0.5f);

            Assert.That(test.GetPrivateField(), Is.Not.EqualTo(oldValue));
        }
Пример #3
0
        public void WeCanChangeTheValueOfAPropertyOfAnObject()
        {
            SampleTester<Vector3> test = new SampleTester<Vector3>();
            Vector3Sampler sampler = new Vector3Sampler(test, "property", x, y, z);

            Vector3 oldValue = test.property;

            sampler.Sample(0.5f);

            Assert.That(test.property, Is.Not.EqualTo(oldValue));
        }
Пример #4
0
        public void WeCanChangeTheValueOfAFieldOfAnObject()
        {
            SampleTester <Vector3> test    = new SampleTester <Vector3>();
            Vector3Sampler         sampler = new Vector3Sampler(test, "field", x, y, z);

            Vector3 oldValue = test.property;

            sampler.Sample(0.5f);

            Assert.That(test.field, Is.Not.EqualTo(oldValue));
        }
Пример #5
0
        public void WeCanSampleWithFewerCurvesWithoutDestroyingExistingValues()
        {
            SampleTester<Vector3> test = new SampleTester<Vector3>() { property = new Vector3(3) };
            Vector3Sampler sampler = new Vector3Sampler(test, "property", x, null, null);

            Vector3 oldValue = test.property;

            sampler.Sample(0.5f);

            Assert.That(test.property.x, Is.Not.EqualTo(oldValue.x));
            Assert.That(test.property.y, Is.EqualTo(oldValue.y));
            Assert.That(test.property.z, Is.EqualTo(oldValue.z));
        }
Пример #6
0
        public void WeCanSampleWithFewerCurvesWithoutDestroyingExistingValues()
        {
            SampleTester <Vector3> test = new SampleTester <Vector3>()
            {
                property = new Vector3(3)
            };
            Vector3Sampler sampler = new Vector3Sampler(test, "property", x, null, null);

            Vector3 oldValue = test.property;

            sampler.Sample(0.5f);

            Assert.That(test.property.x, Is.Not.EqualTo(oldValue.x));
            Assert.That(test.property.y, Is.EqualTo(oldValue.y));
            Assert.That(test.property.z, Is.EqualTo(oldValue.z));
        }
        static List <ISampler> OnSamplerCollectionBuilder(object target, IDictionary <string, Curve> curves)
        {
            var map = new List <Tuple <Bone, string, ISampler> >();

            var root = (target as SkinnedAnimation).Skeleton;

            foreach (var pair in curves)
            {
                var pathSegment     = pair.Key.Split('/');
                var objectSegment   = pathSegment[pathSegment.Length - 1].Split(':');
                var propertySegment = objectSegment[objectSegment.Length - 1].Split('.');

                if (propertySegment.Length > 2)
                {
                    throw new IndexOutOfRangeException("propertySegment.Length > 2");
                }
                var bone = root;

                if (pathSegment.Length > 2)
                {
                    for (int i = 1; i < pathSegment.Length - 1; i++)
                    {
                        bone = bone.Transform.Children.Find((child) => child.Bone.Name.Equals(pathSegment[i]))?.Bone;

                        if (bone == null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    if (!bone.Name.Equals(pathSegment[0]))
                    {
                        throw new ArgumentOutOfRangeException("pathSegment");
                    }
                }

                if (bone == null)
                {
                    continue;
                }

                var sampler = map.Find((t) => t.Item1 == bone && t.Item2.Equals(propertySegment[0]))?.Item3;

                if (sampler == null)
                {
                    var propertyInfo = ReflectionHelper.GetProperty(bone.Transform, propertySegment[0]);

                    if (propertyInfo != null)
                    {
                        switch (propertyInfo.PropertyType.Name)
                        {
                        case "Vector3":
                        {
                            var getter = ReflectionHelper.GetterForProperty <Func <Vector3> >(bone.Transform, propertySegment[0]);
                            var setter = ReflectionHelper.SetterForProperty <Action <Vector3> >(bone.Transform, propertySegment[0]);

                            sampler = new Vector3Sampler(getter, setter);
                        }
                        break;

                        case "Quaternion":
                        {
                            var getter = ReflectionHelper.GetterForProperty <Func <Quaternion> >(bone.Transform, propertySegment[0]);
                            var setter = ReflectionHelper.SetterForProperty <Action <Quaternion> >(bone.Transform, propertySegment[0]);

                            sampler = new QuaternionSampler(getter, setter);
                        }
                        break;
                        }

                        if (sampler != null)
                        {
                            map.Add(Tuple.Create(bone, propertySegment[0], sampler));
                        }
                    }
                }

                if (sampler != null)
                {
                    sampler.SetCurve(pair.Key, pair.Value);
                }
            }

            var samplers = new List <ISampler>();

            foreach (var item in map)
            {
                samplers.Add(item.Item3);
            }

            return(samplers);
        }
Пример #8
0
 public void WeWillGetAnErrorIfWeTryToCreateASamplerForANonExistingMember()
 {
     SampleTester<Vector3> test = new SampleTester<Vector3>();
     Vector3Sampler sampler = new Vector3Sampler(test, "NonExistantMember", x, y, z);
 }
Пример #9
0
 public void WeWillGetAnErrorIfWeTryToSampleAMethod()
 {
     SampleTester<Vector3> test = new SampleTester<Vector3>();
     Vector3Sampler sampler = new Vector3Sampler(test, "Method", x, y, z);
 }
Пример #10
0
 public void WeWillGetAnErrorIfWeTryToSampleAMethod()
 {
     SampleTester <Vector3> test    = new SampleTester <Vector3>();
     Vector3Sampler         sampler = new Vector3Sampler(test, "Method", x, y, z);
 }
Пример #11
0
 public void WeWillGetAnErrorIfWeTryToCreateASamplerForANonExistingMember()
 {
     SampleTester <Vector3> test    = new SampleTester <Vector3>();
     Vector3Sampler         sampler = new Vector3Sampler(test, "NonExistantMember", x, y, z);
 }