public ResourceObject Parse(ByteBuffer bb)
        {
            UnityEngine.AnimationClip clip = new UnityEngine.AnimationClip();

            Schema.AnimationClip _clip = Schema.AnimationClip.GetRootAsAnimationClip(bb);
            clip.frameRate = _clip.FrameRate;
            clip.wrapMode  = (UnityEngine.WrapMode)_clip.WrapMode;
            clip.legacy    = true;

            for (int i = 0; i < _clip.BindingsLength; i++)
            {
                Schema.CurveBinding        bind   = _clip.GetBindings(i);
                Schema.AnimationCurve      _curve = bind.Curve;
                UnityEngine.AnimationCurve curve  = new UnityEngine.AnimationCurve();

                for (int j = 0; j < _curve.KeyFramesLength; j++)
                {
                    Schema.KeyFrame      _kf = _curve.GetKeyFrames(j);
                    UnityEngine.Keyframe kf  = new UnityEngine.Keyframe(_kf.Time, _kf.Value, _kf.InTangent, _kf.OutTangent);
                    kf.tangentMode = _kf.TangentMode;
                    curve.AddKey(kf);
                }
                curve.preWrapMode  = (UnityEngine.WrapMode)_curve.PreWrapMode;
                curve.postWrapMode = (UnityEngine.WrapMode)_curve.PostWrapMode;

                var  assembly = Assembly.Load("UnityEngine");
                Type type     = assembly.GetType(bind.Type);
                clip.SetCurve(bind.Path, type, bind.PropertyName, curve);
            }
            return(new ResourceObjectSingle(clip));
        }
        public void EqualSource()
        {
            Assert.AreEqual(originClip.frameRate, clip.FrameRate);
            Assert.AreEqual(originClip.wrapMode, (UnityEngine.WrapMode)clip.WrapMode);

            EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(originClip);
            Assert.AreEqual(clip.BindingsLength, bindings.Length);
            for (int i = 0; i < bindings.Length; i++)
            {
                Schema.CurveBinding bind = clip.GetBindings(i);
                Assert.AreEqual(bind.PropertyName, bindings[i].propertyName);
                Assert.AreEqual(bind.Path, bindings[i].path);
                Assert.AreEqual(bind.Type, bindings[i].type.FullName);

                Schema.AnimationCurve      curv        = bind.GetCurve(new Schema.AnimationCurve());
                UnityEngine.AnimationCurve originCurve = AnimationUtility.GetEditorCurve(originClip, bindings[i]);

                Assert.AreEqual(curv.PreWrapMode, (Schema.WrapMode)originCurve.preWrapMode);
                Assert.AreEqual(curv.PostWrapMode, (Schema.WrapMode)originCurve.postWrapMode);
                Assert.AreEqual(curv.KeyFramesLength, originCurve.keys.Length);

                for (int j = 0; j < curv.KeyFramesLength; j++)
                {
                    Schema.KeyFrame      keyFrame       = curv.GetKeyFrames(j);
                    UnityEngine.Keyframe originKeyframe = originCurve.keys[j];

                    Assert.AreEqual(keyFrame.InTangent, originKeyframe.inTangent);
                    Assert.AreEqual(keyFrame.OutTangent, originKeyframe.outTangent);
                    Assert.AreEqual(keyFrame.TangentMode, originKeyframe.tangentMode);
                    Assert.AreEqual(keyFrame.Time, originKeyframe.time);
                    Assert.AreEqual(keyFrame.Value, originKeyframe.value);
                }
            }
        }
Exemple #3
0
 public KeyFrame GetKeyFrames(KeyFrame obj, int j)
 {
     int o = __offset(4); return(o != 0 ? obj.__init(__vector(o) + j * 20, bb) : null);
 }