Beispiel #1
0
        public void Write(SceneWriter writer, object component)
        {
            AnimationCurve curve = component as AnimationCurve;
            if (curve == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            writer.WriteElement("PreLoop", ConvertLoopType(curve.preWrapMode));
            writer.WriteElement("PostLoop", ConvertLoopType(curve.postWrapMode));
            StringBuilder sb = new StringBuilder();

            // NOTE: Keyframe.tangentMode might say something about if the tangetn is smooth or broken?

            Keyframe[] normalizedKeys = new Keyframe[curve.keys.Length];
            for (int i = 0; i < curve.keys.Length; i++)
            {
                Keyframe k = curve.keys[i];
                normalizedKeys[i] = new Keyframe(k.time, k.value, k.inTangent, k.outTangent);
                if (i > 0)
                {
                    Keyframe j = curve.keys[i - 1];
                    normalizedKeys[i - 1].outTangent = DenormalizeTangent(j.time, k.time, j.outTangent);
                    normalizedKeys[i].inTangent = DenormalizeTangent(j.time, k.time, k.inTangent);
                }
            }

            foreach (Keyframe item in normalizedKeys)
            {
                sb.AppendFormat("{0} {1} {2} {3} {4} ", item.time, item.value, item.inTangent, item.outTangent, "Smooth");
            }
            writer.WriteElement("Keys", sb.ToString().TrimEnd());
        }
////////////////////// AnimationCurve ///////////////////////////////////////
// constructors

    static bool AnimationCurve_AnimationCurve1(JSVCall vc, int argc)
    {
        int _this = JSApi.getObject((int)JSApi.GetType.Arg);

        JSApi.attachFinalizerObject(_this);
        --argc;

        int len = argc;

        if (len == 1)
        {
            UnityEngine.Keyframe[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.Keyframe[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new UnityEngine.Keyframe[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (UnityEngine.Keyframe)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            JSMgr.addJSCSRel(_this, new UnityEngine.AnimationCurve(arg0));
        }

        return(true);
    }
Beispiel #3
0
    static public int constructor(IntPtr l)
    {
        int argc = LuaDLL.lua_gettop(l);

        UnityEngine.Keyframe o;
        if (argc == 3)
        {
            System.Single a1;
            checkType(l, 2, out a1);
            System.Single a2;
            checkType(l, 3, out a2);
            o = new UnityEngine.Keyframe(a1, a2);
            pushObject(l, o);
            return(1);
        }
        else if (argc == 5)
        {
            System.Single a1;
            checkType(l, 2, out a1);
            System.Single a2;
            checkType(l, 3, out a2);
            System.Single a3;
            checkType(l, 4, out a3);
            System.Single a4;
            checkType(l, 5, out a4);
            o = new UnityEngine.Keyframe(a1, a2, a3, a4);
            pushObject(l, o);
            return(1);
        }
        LuaDLL.luaL_error(l, "New object failed.");
        return(0);
    }
 static public int constructor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.Keyframe o;
         if (argc == 3)
         {
             System.Single a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             o = new UnityEngine.Keyframe(a1, a2);
             pushValue(l, o);
             return(1);
         }
         else if (argc == 5)
         {
             System.Single a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             System.Single a4;
             checkType(l, 5, out a4);
             o = new UnityEngine.Keyframe(a1, a2, a3, a4);
             pushValue(l, o);
             return(1);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        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));
        }
Beispiel #6
0
        public void AddKeyframe(float t, float val)
        {
            // Simplify keys
            if (ReduceKeyframes && keyframes.Count >= 2) {
            var keyStart = keyframes[keyframes.Count-2];
            var keyEnd = keyframes[keyframes.Count-1];

            // UseReductionThreshold: be wary, traveler. works "ok" but is not a sophisticated keyframe reduction technique
            if (UseReductionThreshold) {
                float deltaStart = Mathf.Abs (keyStart.value - val);
                float deltaEnd = Mathf.Abs (keyEnd.value - val);
                if (   deltaStart < ReductionThreshold
                    && deltaEnd   < ReductionThreshold) {
                    keyEnd.time = t;
                    keyEnd.value = val;
                    return;
                }
            } else {
                if (   Mathf.Approximately (keyStart.value, val)
                    && Mathf.Approximately (keyEnd.value, val)) {
                    keyEnd.time = t;
                    return;
                }
            }
            }

            var k = new Keyframe(t, val);
            keyframes.Add (k);
        }
        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);
                }
            }
        }
// fields

// properties
    static void AnimationCurve_keys(JSVCall vc)
    {
        if (vc.bGet)
        {
            UnityEngine.AnimationCurve _this = (UnityEngine.AnimationCurve)vc.csObj;
            var result = _this.keys;
            var arrRet = result;
            for (int i = 0; arrRet != null && i < arrRet.Length; i++)
            {
                JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, arrRet[i]);
                JSApi.moveSaveID2Arr(i);
            }
            JSApi.setArrayS((int)JSApi.SetType.Rval, (arrRet != null ? arrRet.Length : 0), true);
        }
        else
        {
            UnityEngine.Keyframe[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.Keyframe[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new UnityEngine.Keyframe[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (UnityEngine.Keyframe)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            UnityEngine.AnimationCurve _this = (UnityEngine.AnimationCurve)vc.csObj;
            _this.keys = arg0;
        }
    }
Beispiel #9
0
        public AnimationCurve GetAnimcurve()
        {
            if (ac == null)
            {
                ;
                ac = AnimationCurve.Linear(0, 0, 1, 1);
            }

            if (skey > bkey)
            {
                int acl = ac.length;
                for (int i = 0; i < acl; i++)
                {
                    ac.RemoveKey(0);
                }

                UnityEngine.Keyframe [] kc = new UnityEngine.Keyframe[xkeys.Length];
                for (int i = 0; i < xkeys.Length; i++)
                {
                    kc [i].tangentMode = tkeys [i];
                    kc [i].inTangent   = tikeys [i];
                    kc [i].outTangent  = tokeys [i];
                    kc [i].time        = xkeys [i];
                    kc [i].value       = ykeys [i];
                    ac.AddKey(kc [i]);
                }

                bkey = skey;
            }

            return(ac);
        }
Beispiel #10
0
 public TreeGroup()
 {
     Keyframe[] keys = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.distributionCurve = new AnimationCurve(keys);
     this.distributionNodes = 5;
     this.distributionTwirl = 0f;
     this.distributionPitch = 0f;
     Keyframe[] keyframeArray2 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.distributionPitchCurve = new AnimationCurve(keyframeArray2);
     this.distributionScale = 1f;
     Keyframe[] keyframeArray3 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 0.3f) };
     this.distributionScaleCurve = new AnimationCurve(keyframeArray3);
     this.showAnimationProps = true;
     this.animationPrimary = 0.5f;
     this.animationSecondary = 0.5f;
     this.animationEdge = 1f;
     this.visible = true;
     this.lockFlags = 0;
     this.nodeIDs = new int[0];
     this.parentGroupID = -1;
     this.childGroupIDs = new int[0];
     this.nodes = new List<TreeNode>();
     this.parentGroup = null;
     this.childGroups = new List<TreeGroup>();
 }
Beispiel #11
0
        public static void AddKeyIfChanged(this AnimationCurve curve, Keyframe keyframe)
        {
            var keys = curve.keys;
            //If this is the first key on this curve, always add
            //NOTE: Add TWO copies of the first frame, then we adjust the last frame as we move along
            //This guarantees a minimum of two keys in each curve
            if (keys.Length == 0)
            {
                curve.AddKey(keyframe);
                keyframe.time += float.Epsilon;
                curve.AddKey(keyframe);
            }
            else
            {
                //TODO: This method of keyframe reduction causes artifacts in animations that are supposed to deliberately pause
                //Find the last keyframe
                Keyframe lastKey = keys[keys.Length - 1];
                if (lastKey.time >= keyframe.time)
                    Debug.LogError("Keyframes not supplied in consecutive order!!!");

                //Grab 2 frames ago
                var last2Key = keys[keys.Length - 2];

                //If the previous 2 frames were different, add a new frame
                if (lastKey.value != last2Key.value)
                {
                    curve.AddKey(keyframe);
                }
                //The previous frame is redundant - just move it
                else
                {
                    curve.MoveKey(keys.Length - 1, keyframe);
                }
            }
        }
 static public int ctor__Single__Single__Single__Single__Single__Single_s(IntPtr l)
 {
     try {
         UnityEngine.Keyframe o;
         System.Single        a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         System.Single a3;
         checkType(l, 3, out a3);
         System.Single a4;
         checkType(l, 4, out a4);
         System.Single a5;
         checkType(l, 5, out a5);
         System.Single a6;
         checkType(l, 6, out a6);
         o = new UnityEngine.Keyframe(a1, a2, a3, a4, a5, a6);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
        {
            Keyframe[] keyframes;

            AnimationCurve curve=new AnimationCurve();

            //	curve.preWrapMode=(WrapMode)info.GetValue("preWrapMode",typeof(WrapMode));
            //	curve.postWrapMode=(WrapMode)info.GetValue("postWrapMode",typeof(WrapMode));

            int numKeys=info.GetInt32("keysn");

            keyframes=new Keyframe[numKeys];

            Keyframe keyframeCurrent;
            for (int i=0; i<numKeys; i++) {
                keyframeCurrent=keyframes[i]=new Keyframe(info.GetSingle("keyt"+i),
                info.GetSingle("keyv"+i));
                keyframeCurrent.tangentMode=info.GetInt32("keymod"+i);
                keyframeCurrent.inTangent=info.GetSingle("keyin"+i);
                keyframeCurrent.outTangent=info.GetSingle("keyout"+i);
            }

            curve.keys = keyframes;

            // don't know how to make connection between AnimaitonCurver and Keyframes surrogate
            // AnimationCurve surrogate keys are constructed before thoose in Keyframe surrogate resulting in 0,0 Keyframes
            //return new AnimationCurve((Keyframe[])info.GetValue ("keys", typeof(Keyframe[])));

            return curve;
        }
 static public int constructor(IntPtr l)
 {
     LuaDLL.lua_remove(l, 1);
     UnityEngine.Keyframe o;
     if (matchType(l, 1, typeof(System.Single), typeof(System.Single)))
     {
         System.Single a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         o = new UnityEngine.Keyframe(a1, a2);
         pushObject(l, o);
         return(1);
     }
     else if (matchType(l, 1, typeof(System.Single), typeof(System.Single), typeof(System.Single), typeof(System.Single)))
     {
         System.Single a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         System.Single a3;
         checkType(l, 3, out a3);
         System.Single a4;
         checkType(l, 4, out a4);
         o = new UnityEngine.Keyframe(a1, a2, a3, a4);
         pushObject(l, o);
         return(1);
     }
     LuaDLL.luaL_error(l, "New object failed.");
     return(0);
 }
 public static int constructor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.Keyframe o;
         if(argc==3){
             System.Single a1;
             checkType(l,2,out a1);
             System.Single a2;
             checkType(l,3,out a2);
             o=new UnityEngine.Keyframe(a1,a2);
             pushValue(l,o);
             return 1;
         }
         else if(argc==5){
             System.Single a1;
             checkType(l,2,out a1);
             System.Single a2;
             checkType(l,3,out a2);
             System.Single a3;
             checkType(l,4,out a3);
             System.Single a4;
             checkType(l,5,out a4);
             o=new UnityEngine.Keyframe(a1,a2,a3,a4);
             pushValue(l,o);
             return 1;
         }
         LuaDLL.luaL_error(l,"New object failed.");
         return 0;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Beispiel #16
0
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.Keyframe keyframe = new UnityEngine.Keyframe();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "time":
                    keyframe.time = reader.ReadProperty <System.Single>();
                    break;

                case "value":
                    keyframe.value = reader.ReadProperty <System.Single>();
                    break;

                case "inTangent":
                    keyframe.inTangent = reader.ReadProperty <System.Single>();
                    break;

                case "outTangent":
                    keyframe.outTangent = reader.ReadProperty <System.Single>();
                    break;

                case "tangentMode":     // Obsolote
                    reader.ReadProperty <System.Int32>();
                    break;
                }
            }
            return(keyframe);
        }
 public void FromKeyframe(Keyframe k)
 {
     this.inTangent = k.inTangent;
     this.outTangent = k.outTangent;
     this.time = k.time;
     this.value = k.value;
 }
Beispiel #18
0
    static int AddKey(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.AnimationCurve obj  = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve));
                UnityEngine.Keyframe       arg0 = StackTraits <UnityEngine.Keyframe> .Check(L, 2);

                int o = obj.AddKey(arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 3)
            {
                UnityEngine.AnimationCurve obj = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                int   o    = obj.AddKey(arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AnimationCurve.AddKey"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 public static SerializableKeyframe[] FromKeyframeArray(Keyframe[] ks)
 {
     SerializableKeyframe[] keys = new SerializableKeyframe[ks.Length];
     for(int i = 0; i < keys.Length; i++)
     keys[i] = new SerializableKeyframe(ks[i]);
     return keys;
 }
 public static Keyframe[] ToKeyframeArray(SerializableKeyframe[] sks)
 {
     Keyframe[] keys = new Keyframe[sks.Length];
     for(int i = 0; i < keys.Length; i++)
     keys[i] = sks[i].ToKeyframe();
     return keys;
 }
        public static AnimationCurve JSONtoAnimationCurve(this tfxJSONArray json_data)
        {
            AnimationCurve anim_curve = new AnimationCurve();

            anim_curve.keys = new Keyframe[0];

            UnityEngine.Keyframe keyframe;
            int frameIndex = 0;

            foreach (tfxJSONValue frame_data in json_data)
            {
                keyframe = new UnityEngine.Keyframe()
                {
                    inTangent  = (float)frame_data.Obj["inTangent"].Number,
                    outTangent = (float)frame_data.Obj["outTangent"].Number,
#if !UNITY_2018_1_OR_NEWER
                    tangentMode = (int)frame_data.Obj["tangentMode"].Number,
#endif
                    time  = (float)frame_data.Obj["time"].Number,
                    value = (float)frame_data.Obj["value"].Number
                };

#if UNITY_2018_1_OR_NEWER && UNITY_EDITOR
                AnimationUtility.SetKeyLeftTangentMode(anim_curve, frameIndex, (AnimationUtility.TangentMode)((int)frame_data.Obj["tangentModeLeft"].Number));
                AnimationUtility.SetKeyRightTangentMode(anim_curve, frameIndex, (AnimationUtility.TangentMode)((int)frame_data.Obj["tangentModeRight"].Number));
#endif

                anim_curve.AddKey(keyframe);

                frameIndex++;
            }

            return(anim_curve);
        }
        /// <summary>
        /// Creates a new Animationcurve that an interpolation between two other curves. Thanks to Oliver for creating this
        /// </summary>
        /// <param name="CurveA"></param>
        /// <param name="CurveB"></param>
        /// <param name="step"></param>
        /// <returns>The new interpolated animation curve</returns>
        public static AnimationCurve Interpolate(AnimationCurve CurveA, AnimationCurve CurveB, float step)
        {
            int I = CurveA.length < CurveB.length ? CurveB.length : CurveA.length;

            var keys = new Keyframe[I];

            for (int i = 0; i < I; ++i)
            {

                var a = GetKey(CurveA, i, I);
                var b = GetKey(CurveB, i, I);

                var time = Mathf.SmoothStep(a.time, b.time, step);
                var value = Mathf.SmoothStep(a.value, b.value, step);
                var inTangent = Mathf.SmoothStep(a.inTangent, b.inTangent, step);
                var outTangent = Mathf.SmoothStep(a.outTangent, b.outTangent, step);

                var c = new Keyframe(time, value, inTangent, outTangent);

                keys[i] = c;

            }

            return new AnimationCurve(keys);
        }
 public TreeGroupBranch()
 {
     Keyframe[] keys = new Keyframe[] { new Keyframe(0f, 1f, -1f, -1f), new Keyframe(1f, 0f, -1f, -1f) };
     this.radiusCurve = new AnimationCurve(keys);
     this.radiusMode = true;
     this.capSmoothing = 0f;
     this.crinklyness = 0.1f;
     Keyframe[] keyframeArray2 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.crinkCurve = new AnimationCurve(keyframeArray2);
     this.seekBlend = 0f;
     Keyframe[] keyframeArray3 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.seekCurve = new AnimationCurve(keyframeArray3);
     this.noise = 0.1f;
     Keyframe[] keyframeArray4 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.noiseCurve = new AnimationCurve(keyframeArray4);
     this.noiseScaleU = 0.2f;
     this.noiseScaleV = 0.1f;
     this.flareSize = 0f;
     this.flareHeight = 0.1f;
     this.flareNoise = 0.3f;
     this.weldHeight = 0.1f;
     this.weldSpreadTop = 0f;
     this.weldSpreadBottom = 0f;
     this.breakingChance = 0f;
     this.breakingSpot = new Vector2(0.4f, 0.6f);
     this.frondCount = 1;
     this.frondWidth = 1f;
     Keyframe[] keyframeArray5 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.frondCurve = new AnimationCurve(keyframeArray5);
     this.frondRange = new Vector2(0.1f, 1f);
     this.frondRotation = 0f;
     this.frondCrease = 0f;
 }
Beispiel #24
0
 public KFProxy(Keyframe _val)
 {
     inTangent = _val.inTangent;
     outTangent = _val.outTangent;
     tangentMode = _val.tangentMode;
     time = _val.time;
     value = _val.value;
 }
			public KeyFrameCopy(int idx, int selectionIdx, Keyframe source)
			{
				this.idx = idx;
				this.selectionIdx = selectionIdx;
				this.time = source.time;
				this.value = source.value;
				this.inTangent = source.inTangent;
				this.outTangent = source.outTangent;
			}
Beispiel #26
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.Keyframe keyframe = (UnityEngine.Keyframe)value;
     writer.WriteProperty("time", keyframe.time);
     writer.WriteProperty("value", keyframe.value);
     writer.WriteProperty("inTangent", keyframe.inTangent);
     writer.WriteProperty("outTangent", keyframe.outTangent);
     //writer.WriteProperty ( "tangentMode", keyframe.tangentMode );
 }
 public AnimationWindowKeyframe(AnimationWindowCurve curve, Keyframe key)
 {
     this.time = key.time;
     this.value = key.value;
     this.curve = curve;
     this.m_InTangent = key.inTangent;
     this.m_OutTangent = key.outTangent;
     this.m_TangentMode = key.tangentMode;
 }
 private float GetAverageKeyValue(Keyframe[] keyFrames)
 {
     float num = 0f;
     foreach (Keyframe keyframe in keyFrames)
     {
         num += keyframe.value;
     }
     return (num / ((float) keyFrames.Length));
 }
 static Keyframe KeyframeConversion(UnityEngine.Keyframe inKey)
 {
     return(new Keyframe
     {
         InTangent = inKey.inTangent,
         OutTangent = inKey.outTangent,
         Value = inKey.value,
         Time = inKey.time
     });
 }
Beispiel #30
0
 public static Boomlagoon.JSON.JSONValue ExportData(this UnityEngine.Keyframe frame)
 {
     Boomlagoon.JSON.JSONObject json_data = new Boomlagoon.JSON.JSONObject();
     json_data["inTangent"]   = frame.inTangent;
     json_data["outTangent"]  = frame.outTangent;
     json_data["tangentMode"] = frame.tangentMode;
     json_data["time"]        = frame.time;
     json_data["value"]       = frame.value;
     return(new Boomlagoon.JSON.JSONValue(json_data));
 }
Beispiel #31
0
 public KeyframeEx(UnityEngine.Keyframe keyframe)
 {
     this.m_Time         = keyframe.time;
     this.m_Value        = keyframe.value;
     this.m_InTangent    = keyframe.inTangent;
     this.m_OutTangent   = keyframe.outTangent;
     this.m_WeightedMode = (int)keyframe.weightedMode;
     this.m_InWeight     = keyframe.inWeight;
     this.m_OutWeight    = keyframe.outWeight;
 }
 // UnityEditor.CurveUtility.cs (c) Unity Technologies
 public static TangentMode GetKeyTangentMode(Keyframe keyframe, int leftRight)
 {
     Type t = typeof( UnityEngine.Keyframe );
     FieldInfo field = t.GetField( "m_TangentMode", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance );
     int tangentMode =  (int)field.GetValue(keyframe);
     if (leftRight == 0)
         return (TangentMode) ((tangentMode & 6) >> 1);
     else
         return (TangentMode) ((tangentMode & 24) >> 3);
 }
    static public int set_inTangent(IntPtr l)
    {
        UnityEngine.Keyframe o = (UnityEngine.Keyframe)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.inTangent = v;
        setBack(l, o);
        return(0);
    }
    static public int set_tangentMode(IntPtr l)
    {
        UnityEngine.Keyframe o = (UnityEngine.Keyframe)checkSelf(l);
        int v;

        checkType(l, 2, out v);
        o.tangentMode = v;
        setBack(l, o);
        return(0);
    }
 public void AddCurve()
 {
     SerializedProperty property = this.Get("curves");
     if ((property != null) && property.isArray)
     {
         property.InsertArrayElementAtIndex(property.arraySize);
         property.GetArrayElementAtIndex(property.arraySize - 1).FindPropertyRelative("name").stringValue = "Curve";
         Keyframe[] keys = new Keyframe[] { new Keyframe(0f, 0f), new Keyframe(1f, 0f) };
         property.GetArrayElementAtIndex(property.arraySize - 1).FindPropertyRelative("curve").animationCurveValue = new AnimationCurve(keys);
     }
 }
        public static AnimationCurve ToAnimationCurve(this string curve_data)
        {
            AnimationCurve curve = new AnimationCurve();

            string[] key_frame_data_parts = curve_data.Split('#');

            if (key_frame_data_parts.Length % 5 != 0)
            {
                return(curve);
            }

            int idx = 0;

            UnityEngine.Keyframe key_frame = new UnityEngine.Keyframe();

            for (idx = 0; idx < key_frame_data_parts.Length; idx++)
            {
                if (idx % 5 == 0)
                {
                    if (idx > 0)
                    {
                        curve.AddKey(key_frame);
                    }

                    key_frame      = new Keyframe();
                    key_frame.time = float.Parse(key_frame_data_parts[idx]);
                }
                if (idx % 5 == 1)
                {
                    key_frame.value = float.Parse(key_frame_data_parts[idx]);
                }
                if (idx % 5 == 2)
                {
                    key_frame.inTangent = float.Parse(key_frame_data_parts[idx]);
                }
                if (idx % 5 == 3)
                {
                    key_frame.outTangent = float.Parse(key_frame_data_parts[idx]);
                }
#if !UNITY_2018_1_OR_NEWER
                if (idx % 5 == 4)
                {
                    key_frame.tangentMode = int.Parse(key_frame_data_parts[idx]);
                }
#endif
            }

            if (idx > 0)
            {
                curve.AddKey(key_frame);
            }

            return(curve);
        }
Beispiel #37
0
 public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
 {
     float single = info.GetSingle("time");
     float single2 = info.GetSingle("value");
     int @int = info.GetInt32("tangentMode");
     float single3 = info.GetSingle("inTangent");
     float single4 = info.GetSingle("outTangent");
     Keyframe keyframe = new Keyframe(single, single2, single3, single4);
     keyframe.tangentMode = @int;
     return keyframe;
 }
    static bool AnimationCurve_AddKey__Keyframe(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.Keyframe arg0 = (UnityEngine.Keyframe)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(((UnityEngine.AnimationCurve)vc.csObj).AddKey(arg0)));
        }

        return(true);
    }
 public static float CalculateSmoothTangent(Keyframe key)
 {
     if (key.inTangent == float.PositiveInfinity)
     {
         key.inTangent = 0f;
     }
     if (key.outTangent == float.PositiveInfinity)
     {
         key.outTangent = 0f;
     }
     return ((key.outTangent + key.inTangent) * 0.5f);
 }
		public static AnimationCurve Clamp(this AnimationCurve curve, float minTime, float maxTime, float minValue, float maxValue) {
			for (int i = 0; i < curve.keys.Length; i++) {
				Keyframe key = curve.keys[i];
				if (key.time < minTime || key.time > maxTime || key.value < minValue || key.value > maxValue) {
					var newKey = new Keyframe(Mathf.Clamp(key.time, minTime, maxTime), Mathf.Clamp(key.value, minValue, maxValue));
					newKey.inTangent = key.inTangent;
					newKey.outTangent = key.outTangent;
					curve.MoveKey(i, newKey);
				}
			}
			return curve;
		}
Beispiel #41
0
    static int _CreateUnityEngine_Keyframe(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 1);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 2);
                UnityEngine.Keyframe obj = new UnityEngine.Keyframe(arg0, arg1);
                ToLua.PushValue(L, obj);
                return(1);
            }
            else if (count == 4)
            {
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 1);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
                UnityEngine.Keyframe obj = new UnityEngine.Keyframe(arg0, arg1, arg2, arg3);
                ToLua.PushValue(L, obj);
                return(1);
            }
            else if (count == 6)
            {
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 1);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
                float arg4 = (float)LuaDLL.luaL_checknumber(L, 5);
                float arg5 = (float)LuaDLL.luaL_checknumber(L, 6);
                UnityEngine.Keyframe obj = new UnityEngine.Keyframe(arg0, arg1, arg2, arg3, arg4, arg5);
                ToLua.PushValue(L, obj);
                return(1);
            }
            else if (count == 0)
            {
                UnityEngine.Keyframe obj = new UnityEngine.Keyframe();
                ToLua.PushValue(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: UnityEngine.Keyframe.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 static public int ctor_s(IntPtr l)
 {
     try {
         UnityEngine.Keyframe o;
         o = new UnityEngine.Keyframe();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #43
0
		public static Keyframe GetNew(float time, float value, TangentMode left, TangentMode right){
			object boxed = new Keyframe(time,value); // cant use struct in reflection			
			
			SetKeyBroken(boxed, true);
			SetKeyTangentMode(boxed, 0, left);
			SetKeyTangentMode(boxed, 1, right);
			
			Keyframe keyframe = (Keyframe)boxed;
			if (left == TangentMode.Stepped )
				keyframe.inTangent = float.PositiveInfinity;
			if (right == TangentMode.Stepped )
				keyframe.outTangent = float.PositiveInfinity;
			
			return keyframe;
		}
        public static tfxJSONValue ExportData(this UnityEngine.Keyframe frame, AnimationCurve curve, int keyIndex)
        {
            tfxJSONObject json_data = new tfxJSONObject();

            json_data["inTangent"]  = frame.inTangent;
            json_data["outTangent"] = frame.outTangent;
#if UNITY_2018_1_OR_NEWER && UNITY_EDITOR
            json_data["leftTangentMode"]  = (int)AnimationUtility.GetKeyLeftTangentMode(curve, keyIndex);
            json_data["rightTangentMode"] = (int)AnimationUtility.GetKeyRightTangentMode(curve, keyIndex);
#elif !UNITY_2018_1_OR_NEWER
            json_data["tangentMode"] = frame.tangentMode;
#endif
            json_data["time"]  = frame.time;
            json_data["value"] = frame.value;
            return(new tfxJSONValue(json_data));
        }
Beispiel #45
0
 static void Keyframe_tangentMode(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.Keyframe _this = (UnityEngine.Keyframe)vc.csObj;
         var result = _this.tangentMode;
         JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(result));
     }
     else
     {
         System.Int32         arg0  = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
         UnityEngine.Keyframe _this = (UnityEngine.Keyframe)vc.csObj;
         _this.tangentMode = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
Beispiel #46
0
 static int _get_this(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.AnimationCurve obj = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         UnityEngine.Keyframe o = obj[arg0];
         ToLua.PushValue(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #47
0
 static void Keyframe_value(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.Keyframe _this = (UnityEngine.Keyframe)vc.csObj;
         var result = _this.value;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single        arg0  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.Keyframe _this = (UnityEngine.Keyframe)vc.csObj;
         _this.value = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
 public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve curve, object value, System.Type type, AnimationKeyTime time)
 {
     AnimationWindowKeyframe keyframe = curve.FindKeyAtTime(time);
     if (keyframe != null)
     {
         keyframe.value = value;
         return keyframe;
     }
     AnimationWindowKeyframe key = new AnimationWindowKeyframe {
         time = time.time
     };
     if (curve.isPPtrCurve)
     {
         key.value = value;
         key.curve = curve;
         curve.AddKeyframe(key, time);
         return key;
     }
     if ((type == typeof(bool)) || (type == typeof(float)))
     {
         AnimationCurve curve2 = curve.ToAnimationCurve();
         Keyframe keyframe3 = new Keyframe(time.time, (float) value);
         if (type == typeof(bool))
         {
             CurveUtility.SetKeyTangentMode(ref keyframe3, 0, TangentMode.Stepped);
             CurveUtility.SetKeyTangentMode(ref keyframe3, 1, TangentMode.Stepped);
             CurveUtility.SetKeyBroken(ref keyframe3, true);
             key.m_TangentMode = keyframe3.tangentMode;
             key.m_InTangent = float.PositiveInfinity;
             key.m_OutTangent = float.PositiveInfinity;
         }
         else
         {
             int keyIndex = curve2.AddKey(keyframe3);
             if (keyIndex != -1)
             {
                 CurveUtility.SetKeyModeFromContext(curve2, keyIndex);
                 Keyframe keyframe4 = curve2[keyIndex];
                 key.m_TangentMode = keyframe4.tangentMode;
             }
         }
         key.value = value;
         key.curve = curve;
         curve.AddKeyframe(key, time);
     }
     return key;
 }
 static public int ctor__Single__Single_s(IntPtr l)
 {
     try {
         UnityEngine.Keyframe o;
         System.Single        a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         o = new UnityEngine.Keyframe(a1, a2);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     char[] separator = new char[] { '\n' };
     string[] strArray = ((string) value).Split(separator);
     Keyframe[] keys = new Keyframe[strArray.Length - 2];
     for (int i = 0; i < keys.Length; i++)
     {
         char[] chArray2 = new char[] { ',' };
         string[] keyvals = strArray[i + 2].Split(chArray2);
         keys[i] = new Keyframe(ParseKeyVal(keyvals, Val.Time), ParseKeyVal(keyvals, Val.Value), ParseKeyVal(keyvals, Val.InTangent), ParseKeyVal(keyvals, Val.OutTangent));
     }
     AnimationCurve curve = new AnimationCurve(keys);
     EnumConverter converter = new EnumConverter(typeof(WrapMode));
     curve.postWrapMode = (WrapMode) converter.ConvertFromString(strArray[0]);
     curve.preWrapMode = (WrapMode) converter.ConvertFromString(strArray[1]);
     return curve;
 }
 static int MoveKey(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.AnimationCurve obj = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         UnityEngine.Keyframe arg1 = (UnityEngine.Keyframe)ToLua.CheckObject(L, 3, typeof(UnityEngine.Keyframe));
         int o = obj.MoveKey(arg0, arg1);
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int get_tangentMode(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Keyframe obj = (UnityEngine.Keyframe)o;
            int ret = obj.tangentMode;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index tangentMode on a nil value"));
        }
    }
    static int get_value(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Keyframe obj = (UnityEngine.Keyframe)o;
            float ret = obj.value;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index value on a nil value"));
        }
    }
 public float CalculateLinearTangent(Keyframe from, Keyframe to, int component)
 {
   float t = 0.01f;
   Vector3 eulerCurvesDirectly1 = this.EvaluateEulerCurvesDirectly(to.time);
   Vector3 eulerCurvesDirectly2 = this.EvaluateEulerCurvesDirectly(from.time);
   Vector3 eulerFromQuaternion = QuaternionCurveTangentCalculation.GetEulerFromQuaternion(Quaternion.Slerp(Quaternion.Euler(eulerCurvesDirectly1), Quaternion.Euler(eulerCurvesDirectly2), t), eulerCurvesDirectly1);
   switch (component)
   {
     case 0:
       return (float) (((double) eulerFromQuaternion.x - (double) eulerCurvesDirectly1.x) / (double) t / -((double) to.time - (double) from.time));
     case 1:
       return (float) (((double) eulerFromQuaternion.y - (double) eulerCurvesDirectly1.y) / (double) t / -((double) to.time - (double) from.time));
     case 2:
       return (float) (((double) eulerFromQuaternion.z - (double) eulerCurvesDirectly1.z) / (double) t / -((double) to.time - (double) from.time));
     default:
       return 0.0f;
   }
 }
Beispiel #55
0
        void Start()
        {
            // TODO these values and animation itself are affected by other camera scripts (e.g. MouseOrbit)

            // Create 'S' shaped curve to adjust pitch
            // Varies from 0 (looking forward) at 0, to 90 (looking straight down) at 1
            _pitchCurve = AnimationCurve.EaseInOut(0.0f, 0.0f, 1.0f, 90.0f);

            // Create exponential shaped curve to adjust distance
            // So zoom control will be more accurate at closer distances, and more coarse further away
            Keyframe[] ks = new Keyframe[2];
            // At zoom=0, offset by 2 units
            ks[0] = new Keyframe(0, 2f);
            ks[0].outTangent = 0;
            // At zoom=1, offset by Distance units
            ks[1] = new Keyframe(1, Distance);
            ks[1].inTangent = 90;
            _distanceCurve = new AnimationCurve(ks);
        }
 private float GetMaxKeyValue(Keyframe[] keyFrames)
 {
     float negativeInfinity = float.NegativeInfinity;
     float positiveInfinity = float.PositiveInfinity;
     foreach (Keyframe keyframe in keyFrames)
     {
         if (keyframe.value > negativeInfinity)
         {
             negativeInfinity = keyframe.value;
         }
         if (keyframe.value < positiveInfinity)
         {
             positiveInfinity = keyframe.value;
         }
     }
     if (Mathf.Abs(positiveInfinity) > negativeInfinity)
     {
         return positiveInfinity;
     }
     return negativeInfinity;
 }
        public float CalculateLinearTangent(Keyframe from, Keyframe to, int component)
        {
            float t = 0.01f;
            Vector3 euler = this.EvaluateEulerCurvesDirectly(to.time);
            Vector3 vector2 = this.EvaluateEulerCurvesDirectly(from.time);
            Quaternion a = Quaternion.Euler(euler);
            Quaternion b = Quaternion.Euler(vector2);
            Vector3 eulerFromQuaternion = GetEulerFromQuaternion(Quaternion.Slerp(a, b, t), euler);
            switch (component)
            {
                case 0:
                    return (((eulerFromQuaternion.x - euler.x) / t) / -(to.time - from.time));

                case 1:
                    return (((eulerFromQuaternion.y - euler.y) / t) / -(to.time - from.time));

                case 2:
                    return (((eulerFromQuaternion.z - euler.z) / t) / -(to.time - from.time));
            }
            return 0f;
        }
		public float CalculateLinearTangent(Keyframe from, Keyframe to, int component)
		{
			float num = 0.01f;
			Vector3 vector = this.EvaluateEulerCurvesDirectly(to.time);
			Vector3 euler = this.EvaluateEulerCurvesDirectly(from.time);
			Quaternion from2 = Quaternion.Euler(vector);
			Quaternion to2 = Quaternion.Euler(euler);
			Quaternion q = Quaternion.Slerp(from2, to2, num);
			Vector3 eulerFromQuaternion = QuaternionCurveTangentCalculation.GetEulerFromQuaternion(q, vector);
			switch (component)
			{
			case 0:
				return (eulerFromQuaternion.x - vector.x) / num / -(to.time - from.time);
			case 1:
				return (eulerFromQuaternion.y - vector.y) / num / -(to.time - from.time);
			case 2:
				return (eulerFromQuaternion.z - vector.z) / num / -(to.time - from.time);
			default:
				return 0f;
			}
		}
 public AnimationCurve loadAnimationCurve(string[] curveData)
 {
     char[] cParams = new char[] { ' ', ',', ';', '\t' };
     AnimationCurve animationCurve = new AnimationCurve();
     try
     {
         for (int i = 0; i < curveData.Length; i++)
         {
             string[] keyTmp = curveData[i].Split(cParams, StringSplitOptions.RemoveEmptyEntries);
             if (keyTmp.Length == 4)
             {
                 print("*RSS* " + keyTmp[0] + " " + keyTmp[1] + " " + keyTmp[2] + " " + keyTmp[3]);
                 Keyframe key = new Keyframe();
                 key.time = float.Parse(keyTmp[0]);
                 key.value = float.Parse(keyTmp[1]);
                 key.inTangent = float.Parse(keyTmp[2]);
                 key.outTangent = float.Parse(keyTmp[3]);
                 animationCurve.AddKey(key);
             }
             else if (keyTmp.Length == 2)
             {
                 print("*RSS* " + keyTmp[0] + " " + keyTmp[1]);
                 Keyframe key = new Keyframe();
                 key.time = float.Parse(keyTmp[0]);
                 key.value = float.Parse(keyTmp[1]);
                 animationCurve.AddKey(key);
             }
             else
             {
                 MonoBehaviour.print("*RSS* Invalid animationCurve data: animationCurve data must have exactly two or four parameters!");
             }
         }
         return animationCurve;
     }
     catch (Exception e)
     {
         print("Caught exception while parsing animationcurve: " + e.Message);
         return null;
     }
 }
        /// <summary>
        /// Adds the keyframe to curve.
        /// </summary>
        /// <param name="animationCurve">Animation curve.</param>
        /// <param name="animatedClip">Animated clip.</param>
        /// <param name="binding">Binding.</param>
        /// <param name="value">Value.</param>
        /// <param name="type">Type.</param>
        /// <param name="time">Time.</param>
        public static void AddKeyframeToCurve(AnimationCurve animationCurve, AnimationClip animatedClip, EditorCurveBinding binding, float value, Type type, float time)
        {
            //frame comparing (frame=(int)(time*animatedClip.frameRate)
                        int keyframeIndex = Array.FindIndex (animationCurve.keys, (itm) => (int)(itm.time * animatedClip.frameRate) == (int)(time * animatedClip.frameRate));
                        Keyframe key = default(Keyframe);
                        if (keyframeIndex < 0) {
                                if (type == typeof(bool) || type == typeof(float)) {

                                        key = new Keyframe (time, value);
                                        if (type == typeof(bool)) {
                                                //CurveUtility.SetKeyTangentMode (ref key, 0, TangentMode.Stepped);
                                                //CurveUtility.SetKeyTangentMode (ref key, 1, TangentMode.Stepped);
                                                //CurveUtility.SetKeyBroken (ref key, true);
                                                key.SetKeyTangentMode (0, TangentMode.Stepped);
                                                key.SetKeyTangentMode (1, TangentMode.Stepped);
                                                key.SetKeyBroken (true);

                                        } else {
                                                int num = animationCurve.AddKey (key);
                                                if (num != -1) {
                                                        animationCurve.SetKeyModeFromContext (num);

                                                }
                                        }

                                }

                        } else {

                                //??? maybe I should add new time too
                                //animationCurve.keys[keyframeIndex].value=value;
                                key = animationCurve.keys [keyframeIndex];
                                key.value = value;
                                animationCurve.MoveKey (keyframeIndex, key);

                        }

                        //Save changes
                        SaveCurve (animationCurve, animatedClip, binding);
        }