예제 #1
0
        public void TestNewFromBytes()
        {
            using (var b1 = new Bytes(new byte[] { 1, 2, 3, 4 })) {
                using (var b2 = b1.NewFromBytes(1, 2)) {
                    // b2 takes a reference to b1 in unmanaged code.
                    // to make sure this works, we release the managed
                    // refernece to b1.
                    b1.Dispose();
                    Assert.That(b2.Count, Is.EqualTo(2));
                    Assert.That(b2[0], Is.EqualTo(2));
                    Assert.That(b2[1], Is.EqualTo(3));

                    Assert.That(() => b1.NewFromBytes(0, 1),
                                Throws.TypeOf <ObjectDisposedException> ());

                    Assert.That(() => b2.NewFromBytes(0, 3),
                                Throws.TypeOf <ArgumentException> ());
                    Assert.That(() => b2.NewFromBytes(-1, 0),
                                Throws.TypeOf <ArgumentOutOfRangeException> ());
                    Assert.That(() => b2.NewFromBytes(0, -1),
                                Throws.TypeOf <ArgumentOutOfRangeException> ());

                    using (var b3 = b2.NewFromBytes(0, 0)) {
                        Assert.That(b3.Count, Is.EqualTo(0));
                    }
                }
            }

            Utility.AssertNoGLibLog();
        }
예제 #2
0
        public void TestCount()
        {
            using (var b = new Bytes(new byte[5])) {
                Assert.That(b.Count, Is.EqualTo(5));

                b.Dispose();
                Assert.That(() => b.Count, Throws.TypeOf <ObjectDisposedException> ());
            }

            Utility.AssertNoGLibLog();
        }
예제 #3
0
        public void TestIndexer()
        {
            using (var b = new Bytes(new byte[] { 1, 2, 3 })) {
                Assert.That(b[0], Is.EqualTo(1));
                Assert.That(b[1], Is.EqualTo(2));
                Assert.That(b[2], Is.EqualTo(3));

                b.Dispose();
                Assert.That(() => b[0], Throws.TypeOf <ObjectDisposedException> ());
            }

            Utility.AssertNoGLibLog();
        }
예제 #4
0
        public void TestGetEnumerator()
        {
            using (var bytes = new Bytes(new byte[] { 1, 2, 3 })) {
                var expected = 1;
                foreach (var b in bytes)
                {
                    Assert.That(b, Is.EqualTo(expected++));
                }
                Assert.That(expected, Is.EqualTo(4));

                bytes.Dispose();
                Assert.That(() => bytes.GetEnumerator(),
                            Throws.TypeOf <ObjectDisposedException> ());
                Assert.That(() => ((IEnumerable)bytes).GetEnumerator(),
                            Throws.TypeOf <ObjectDisposedException> ());
            }

            Utility.AssertNoGLibLog();
        }
예제 #5
0
    public static SkeletonAnimationData clipToAnimationData(AnimationClip clip, Dictionary <string, CurveData> boneObj)
    {
        var frameCount = (int)Math.Floor(clip.length * clip.frameRate) + 1;
        var curveBinds = AnimationUtility.GetCurveBindings(clip);

        foreach (var item in curveBinds)
        {
            if (item.type == typeof(Transform))
            {
                var path = item.path;
                var i    = path.LastIndexOf("/");
                if (i != -1)
                {
                    path = path.Substring(i + 1);
                }

                CurveData data = boneObj[path];

                var curve = AnimationUtility.GetEditorCurve(clip, item);

                switch (item.propertyName)
                {
                case "m_LocalPosition.x":
                    data.pos_curve[0] = curve;
                    break;

                case "m_LocalPosition.y":
                    data.pos_curve[1] = curve;
                    break;

                case "m_LocalPosition.z":
                    data.pos_curve[2] = curve;
                    break;

                case "m_LocalRotation.x":
                    data.qua_curve[0] = curve;
                    break;

                case "m_LocalRotation.y":
                    data.qua_curve[1] = curve;
                    break;

                case "m_LocalRotation.z":
                    data.qua_curve[2] = curve;
                    break;

                case "m_LocalRotation.w":
                    data.qua_curve[3] = curve;
                    break;

                case "m_LocalScale.x":
                    data.sca_curve[0] = curve;
                    break;

                case "m_LocalScale.y":
                    data.sca_curve[1] = curve;
                    break;

                case "m_LocalScale.z":
                    data.sca_curve[2] = curve;
                    break;
                }
            }
        }



        SkeletonAnimationData animData = new SkeletonAnimationData();

        animData.name       = Export.getAnimationName(clip);
        animData.duration   = clip.length;
        animData.totalFrame = frameCount;
        animData.eDuration  = 1 / clip.frameRate;

        animData.frames = new Dictionary <string, byte[]>();


        foreach (var item in boneObj)
        {
            var   curve = item.Value;
            var   name  = curve.bone.name;
            Bytes bytes = new Bytes();
            for (int i = 0; i < frameCount; i++)
            {
                float     now    = i / clip.frameRate;
                Matrix4x4 matrix = curve.toMatrix(now);
                bytes.write(Matrix4x4ToBytes(matrix));
            }
            animData.frames.Add(name, bytes.ToArray());
            bytes.Dispose();
        }

        return(animData);
    }
예제 #6
0
 public void Dispose()
 {
     Bytes.Dispose();
 }