当前位置: 首页>>代码示例>>C#>>正文


C# AnimationCurve.SmoothTangents方法代码示例

本文整理汇总了C#中UnityEngine.AnimationCurve.SmoothTangents方法的典型用法代码示例。如果您正苦于以下问题:C# AnimationCurve.SmoothTangents方法的具体用法?C# AnimationCurve.SmoothTangents怎么用?C# AnimationCurve.SmoothTangents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.AnimationCurve的用法示例。


在下文中一共展示了AnimationCurve.SmoothTangents方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: defineCurve

    //Create default curve for the dynamic bias
    private AnimationCurve defineCurve()
    {
        AnimationCurve temp = new AnimationCurve();
        temp.AddKey(-1, -1);
        temp.AddKey(-0.55f, -0.95f);
        temp.AddKey(-0.001f, -0.5f);
        temp.AddKey(0.001f, 0.5f);
        temp.AddKey(0.55f, 0.95f);
        temp.AddKey(1, 1);
        temp.SmoothTangents(2, 1);
        temp.SmoothTangents(3, -1);

        return temp;
    }
开发者ID:Ed-McD,项目名称:Unity-Editor-Maze-Generator,代码行数:15,代码来源:MazeMenu.cs

示例2: SetLinear

		public static void SetLinear(ref AnimationCurve curve) {

			for (int i = 0; i < curve.length; i++) {

				Keyframe boxed = curve.keys[i]; // getting around the fact that Keyframe is a struct by pre-boxing
				boxed.tangentMode = GetNewTangentKeyMode(boxed.tangentMode, TangentDirection.Left, TangentMode.Linear);
				boxed.tangentMode = GetNewTangentKeyMode(boxed.tangentMode, TangentDirection.Right, TangentMode.Linear);
				curve.MoveKey(i, (Keyframe)boxed);
				curve.SmoothTangents(i, 0f);

			}

		}
开发者ID:Cyberbanan,项目名称:Unity3d.UI.Windows,代码行数:13,代码来源:AnimationCurveUtility.cs

示例3: UpdateTangentsFromMode

 // UnityEditor.CurveUtility.cs (c) Unity Technologies
 public static void UpdateTangentsFromMode(AnimationCurve curve, int index)
 {
     if (index < 0 || index >= curve.length)
         return;
     Keyframe key = curve [index];
     if (KeyframeUtil.GetKeyTangentMode (key, 0) == TangentMode.Linear && index >= 1) {
         key.inTangent = CalculateLinearTangent (curve, index, index - 1);
         curve.MoveKey (index, key);
     }
     if (KeyframeUtil.GetKeyTangentMode (key, 1) == TangentMode.Linear && index + 1 < curve.length) {
         key.outTangent = CalculateLinearTangent (curve, index, index + 1);
         curve.MoveKey (index, key);
     }
     if (KeyframeUtil.GetKeyTangentMode (key, 0) != TangentMode.Smooth && KeyframeUtil.GetKeyTangentMode (key, 1) != TangentMode.Smooth)
         return;
     curve.SmoothTangents (index, 0.0f);
 }
开发者ID:ootake,项目名称:SpriteStudioForUnity,代码行数:18,代码来源:CurveExtension.cs

示例4: CreateCurve

	public static AnimationCurve CreateCurve( float[] values, float[] times, bool smooth = true)
	{
		D.Assert( values != null && times != null, "Param == null" );
		D.Assert( values.Length == times.Length, "Size not same" );
		if ( values.Length != times.Length ){
			D.Log("values.Length: {0}   times.Length: {1}", values.Length, times.Length);
		}
		
		AnimationCurve result;
		Keyframe[] ks = new Keyframe[values.Length];
		for( int i = 0; i < values.Length; i ++ ) {
			ks[ i ] = new Keyframe( times[ i ], values[ i ] );
		}
		result = new AnimationCurve( ks );
		if ( smooth){
			for( int i = 0; i < result.length; i++ ) {
				result.SmoothTangents( i, 0 );
			}
		}
		return result;
	}
开发者ID:fengqk,项目名称:Art,代码行数:21,代码来源:ChpAnimation.cs

示例5: Internal_UpdateTangents

 private static void Internal_UpdateTangents(AnimationCurve curve, int index)
 {
     if ((index >= 0) && (index < curve.length))
     {
         Keyframe key = curve[index];
         if ((GetKeyLeftTangentMode(key) == TangentMode.Linear) && (index >= 1))
         {
             key.inTangent = Internal_CalculateLinearTangent(curve, index, index - 1);
             curve.MoveKey(index, key);
         }
         if ((GetKeyRightTangentMode(key) == TangentMode.Linear) && ((index + 1) < curve.length))
         {
             key.outTangent = Internal_CalculateLinearTangent(curve, index, index + 1);
             curve.MoveKey(index, key);
         }
         if ((GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto) || (GetKeyRightTangentMode(key) == TangentMode.ClampedAuto))
         {
             Internal_CalculateAutoTangent(curve, index);
         }
         if ((GetKeyLeftTangentMode(key) == TangentMode.Auto) || (GetKeyRightTangentMode(key) == TangentMode.Auto))
         {
             curve.SmoothTangents(index, 0f);
         }
         if (((GetKeyLeftTangentMode(key) == TangentMode.Free) && (GetKeyRightTangentMode(key) == TangentMode.Free)) && !GetKeyBroken(key))
         {
             key.outTangent = key.inTangent;
             curve.MoveKey(index, key);
         }
         if (GetKeyLeftTangentMode(key) == TangentMode.Constant)
         {
             key.inTangent = float.PositiveInfinity;
             curve.MoveKey(index, key);
         }
         if (GetKeyRightTangentMode(key) == TangentMode.Constant)
         {
             key.outTangent = float.PositiveInfinity;
             curve.MoveKey(index, key);
         }
     }
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:40,代码来源:AnimationUtility.cs

示例6: RemoveKey

        /// <summary>
        /// Remove a key from an AnimationCurve.
        /// </summary>
        /// <param name="curve">The existing AnimationCurve.</param>
        /// <param name="index">The index of the Key to be removed.</param>
        public static void RemoveKey(AnimationCurve curve, int index)
        {
            curve.RemoveKey(index);

            // Update left neighbour.
            if (index > 0)
            {
                // Update tangent data based on tangent mode.
                int tangentMode = curve[index-1].tangentMode;

                if (IsAuto(tangentMode))
                {
                    curve.SmoothTangents(index - 1, 0);
                }
                if (IsBroken(tangentMode))
                {
                    if (IsRightLinear(tangentMode))
                    {
                        SetKeyRightLinear(curve, index - 1);
                    }
                }
            }

            // Update right neighbour.
            if (index < curve.length)
            {
                // Update tangent data based on tangent mode.
                int tangentMode = curve[index].tangentMode;

                if (IsAuto(tangentMode))
                {
                    curve.SmoothTangents(index, 0);
                }
                if (IsBroken(tangentMode))
                {
                    if (IsLeftLinear(tangentMode))
                    {
                        SetKeyLeftLinear(curve, index);
                    }
                }
            }
        }
开发者ID:ArthurRasmusson,项目名称:UofTHacks2016,代码行数:47,代码来源:AnimationCurveHelper.cs

示例7: AddKey

        /// <summary>
        /// Add a new key to an AnimationCurve.
        /// Ensures the integrity of other key's tangent modes.
        /// </summary>
        /// <param name="curve">The existing AnimationCurve.</param>
        /// <param name="keyframe">The new keyframe</param>
        /// <returns>The index of the newly added key.</returns>
        public static int AddKey(AnimationCurve curve, Keyframe keyframe)
        {
            if (curve.length == 0)
            {
                return curve.AddKey(keyframe);
            }
            else if (curve.length == 1)
            {
                // Save the existing keyframe data. (Unity changes the tangent info).
                Keyframe temp = curve[0];
                int newIndex = curve.AddKey(keyframe);
                if(newIndex == -1)
                {
                    return 0;
                }
                else if(newIndex == 0)
                {
                    curve.MoveKey(1, temp);
                }
                else
                {
                    curve.MoveKey(0, temp);
                }
                return newIndex;
            }
            else
            {
                Keyframe left = new Keyframe();
                Keyframe right = new Keyframe();

                for (int i = 0; i < curve.length - 1; i++)
                {
                    Keyframe l = curve[i];
                    Keyframe r = curve[i + 1];

                    if (l.time < keyframe.time && keyframe.time < r.time)
                    {
                        left = l;
                        right = r;
                    }
                }

                int index = curve.AddKey(keyframe);

                // Handle left neighbour.
                if (index > 0)
                {
                    // Restore the saved data.
                    curve.MoveKey(index - 1, left);

                    // Update tangent data based on tangent mode.
                    int tangentMode = curve[index - 1].tangentMode;
                    if (IsAuto(tangentMode))
                    {
                        curve.SmoothTangents(index - 1, 0);
                    }
                    if (IsBroken(tangentMode))
                    {
                        if (IsRightLinear(tangentMode))
                        {
                            SetKeyRightLinear(curve, index - 1);
                        }
                    }
                }

                // Handle the Right neighbour.
                if (index < curve.length - 1)
                {
                    // Restore the saved data.
                    curve.MoveKey(index + 1, right);

                    // Update tangent data based on tangent mode.
                    int tangentMode = curve[index + 1].tangentMode;
                    if (IsAuto(tangentMode))
                    {
                        curve.SmoothTangents(index + 1, 0);
                    }
                    if (IsBroken(tangentMode))
                    {
                        if (IsLeftLinear(tangentMode))
                        {
                            SetKeyLeftLinear(curve, index + 1);
                        }
                    }
                }

                return index;
            }
        }
开发者ID:ArthurRasmusson,项目名称:UofTHacks2016,代码行数:96,代码来源:AnimationCurveHelper.cs

示例8: MoveKey

        /// <summary>
        /// Move/Change an existing key in an AnimationCurve.
        /// Maintains TangentMode and updates neighbours.
        /// </summary>
        /// <param name="curve">The existing AnimationCurve.</param>
        /// <param name="index">The index of the current Keyframe.</param>
        /// <param name="keyframe">The new Keyframe data.</param>
        /// <returns>The index of the Keyframe.</returns>
        public static int MoveKey(AnimationCurve curve, int index, Keyframe keyframe)
        {
            // Save the tangent mode.
            Keyframe old = curve[index];
            keyframe.tangentMode = old.tangentMode;

            int newIndex = curve.MoveKey(index, keyframe);

            // Respect the tangentMode and update as necessary.
            if (IsAuto(keyframe.tangentMode))
            {
                curve.SmoothTangents(newIndex, 0);
            }
            else if (IsBroken(keyframe.tangentMode))
            {
                if (IsLeftLinear(keyframe.tangentMode))
                {
                    SetKeyLeftLinear(curve, newIndex);
                }
                if (IsRightLinear(keyframe.tangentMode))
                {
                    SetKeyRightLinear(curve, newIndex);
                }
            }

            // update the left neighbour
            if (newIndex > 0)
            {
                // Update tangent data based on tangent mode.
                int tangentMode = curve[newIndex - 1].tangentMode;
                if (IsAuto(tangentMode))
                {
                    curve.SmoothTangents(newIndex - 1, 0);
                }
                if (IsBroken(tangentMode))
                {
                    if (IsRightLinear(tangentMode))
                    {
                        SetKeyRightLinear(curve, newIndex - 1);
                    }
                }
            }

            // update the right neighbour
            if (newIndex < curve.length - 1)
            {
                // Update tangent data based on tangent mode.
                int tangentMode = curve[newIndex + 1].tangentMode;
                if (IsAuto(tangentMode))
                {
                    curve.SmoothTangents(newIndex + 1, 0);
                }
                if (IsBroken(tangentMode))
                {
                    if (IsLeftLinear(tangentMode))
                    {
                        SetKeyLeftLinear(curve, newIndex + 1);
                    }
                }
            }

            return newIndex;
        }
开发者ID:ArthurRasmusson,项目名称:UofTHacks2016,代码行数:71,代码来源:AnimationCurveHelper.cs

示例9: UpdateTangentsFromMode

		private static void UpdateTangentsFromMode(AnimationCurve curve, int index)
		{
			if (index < 0 || index >= curve.length)
			{
				return;
			}
			Keyframe key = curve[index];
			if (CurveUtility.GetKeyTangentMode(key, 0) == TangentMode.Linear && index >= 1)
			{
				key.inTangent = CurveUtility.CalculateLinearTangent(curve, index, index - 1);
				curve.MoveKey(index, key);
			}
			if (CurveUtility.GetKeyTangentMode(key, 1) == TangentMode.Linear && index + 1 < curve.length)
			{
				key.outTangent = CurveUtility.CalculateLinearTangent(curve, index, index + 1);
				curve.MoveKey(index, key);
			}
			if (CurveUtility.GetKeyTangentMode(key, 0) == TangentMode.Smooth || CurveUtility.GetKeyTangentMode(key, 1) == TangentMode.Smooth)
			{
				curve.SmoothTangents(index, 0f);
			}
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:22,代码来源:CurveUtility.cs

示例10: ScaleThenOffset

	AnimationCurve ScaleThenOffset(AnimationCurve curve, float length, float scale, float offset)
	{
		List<Keyframe> frames = new List<Keyframe>();

		foreach (Keyframe key in curve.keys)
		{
			Keyframe newKey = key;

			newKey.time = key.time * scale + offset;
			newKey.inTangent = key.inTangent / scale;
			newKey.outTangent = key.outTangent / scale;
			frames.Add(newKey);
		}
		if (frames.Count != 0 && frames[0].time != 0)
		{
			Keyframe f = frames[0];
			f.outTangent = 0;
			f.time = 0;
			frames.Insert(0, f);
		}
		if (frames.Count != 0 && frames[frames.Count - 1].time != length)
		{
			Keyframe f = frames[frames.Count - 1];
			f.time = length;
			frames.Add(f);
		}
		if (frames.Count < 2) { Debug.LogError("keycount <2"); }

		AnimationCurve result = new AnimationCurve(frames.ToArray());

		result.SmoothTangents(0, 0);
		result.SmoothTangents(result.keys.Length - 1, 0);
		return result;
	}
开发者ID:fengqk,项目名称:Art,代码行数:34,代码来源:MaterialFxCreatorInspector.cs

示例11: GenerateCurve

 static AnimationCurve GenerateCurve(EasingFunction easingFunction, int resolution)
 {
     var curve = new AnimationCurve();
     for (var i = 0; i < resolution; ++i)
     {
         var time = i / (resolution - 1f);
         var value = (float)easingFunction(time, 0.0, 1.0, 1.0);
         var key = new Keyframe(time, value);
         curve.AddKey(key);
     }
     for (var i = 0; i < resolution; ++i)
     {
         curve.SmoothTangents(i, 0f);
     }
     return curve;
 }
开发者ID:aureliendrouet,项目名称:EasingCurvePresets,代码行数:16,代码来源:CurveGenerator.cs

示例12: UpdateTangentsFromMode

 private static void UpdateTangentsFromMode(AnimationCurve curve, int index)
 {
     if ((index >= 0) && (index < curve.length))
     {
         Keyframe key = curve[index];
         if ((GetKeyTangentMode(key, 0) == TangentMode.Linear) && (index >= 1))
         {
             key.inTangent = CalculateLinearTangent(curve, index, index - 1);
             curve.MoveKey(index, key);
         }
         if ((GetKeyTangentMode(key, 1) == TangentMode.Linear) && ((index + 1) < curve.length))
         {
             key.outTangent = CalculateLinearTangent(curve, index, index + 1);
             curve.MoveKey(index, key);
         }
         if ((GetKeyTangentMode(key, 0) == TangentMode.Smooth) || (GetKeyTangentMode(key, 1) == TangentMode.Smooth))
         {
             curve.SmoothTangents(index, 0f);
         }
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:21,代码来源:CurveUtility.cs

示例13: GenerateRootTZMotion

	public static AnimationCurve GenerateRootTZMotion (AnimationCurve lFtTZCurve, AnimationCurve rFtTZCurve, int lFtIn, int lFtOut, int rFtIn, int rFtOut)
	{

		int curveLength = lFtTZCurve.keys.Length;

		List<Keyframe> footKeys = new List<Keyframe> ();


		int minIndex = lFtIn;
		AREA area = AREA.RIGHT_FOOT_LEAVE;
		
		if (minIndex > lFtOut) {
			minIndex = lFtOut;
			area = AREA.LEFT_FOOT_ENTER;
		}
		if (minIndex > rFtIn) {
			minIndex = rFtIn;
			area = AREA.LEFT_FOOT_LEAVE;
		}
		if (minIndex > rFtOut) {
			minIndex = rFtOut;
			area = AREA.RIGHT_FOOT_ENTER;
		}
		
		Debug.Log ("start area: " + area);
		
		for (int i=0; i<curveLength; i++) {
			
			if (i == lFtIn) {
				area = AREA.LEFT_FOOT_ENTER;
			} else if (i == lFtOut) {
				area = AREA.LEFT_FOOT_LEAVE;
			} else if (i == rFtIn) {
				area = AREA.RIGHT_FOOT_ENTER;
			} else if (i == rFtOut) {
				area = AREA.RIGHT_FOOT_LEAVE;
			}
			
			Debug.Log ("index: " + i + " current area: " + area);
			
			int preIndex;
			
			switch (area) {
			case AREA.LEFT_FOOT_ENTER:
				preIndex = (i - 1 + curveLength) % curveLength;
				footKeys.Add (new Keyframe (lFtTZCurve.keys [i].time, lFtTZCurve.keys [preIndex].value - lFtTZCurve.keys [i].value));
				break;
			case AREA.RIGHT_FOOT_ENTER:
				preIndex = (i - 1 + curveLength) % curveLength;
				footKeys.Add (new Keyframe (rFtTZCurve.keys [i].time, rFtTZCurve.keys [preIndex].value - rFtTZCurve.keys [i].value));
				break;
			case AREA.LEFT_FOOT_LEAVE:
				preIndex = (lFtOut - 1 + curveLength) % curveLength;
				footKeys.Add (new Keyframe (lFtTZCurve.keys [i].time, lFtTZCurve.keys [preIndex].value - lFtTZCurve.keys [lFtOut].value));
				break;
			case AREA.RIGHT_FOOT_LEAVE:
				preIndex = (rFtOut - 1 + curveLength) % curveLength;
				footKeys.Add (new Keyframe (rFtTZCurve.keys [i].time, rFtTZCurve.keys [preIndex].value - rFtTZCurve.keys [rFtOut].value));
				break;
			}
			
		}

		AnimationCurve rootCurve = new AnimationCurve ();
		
		float value = 0;
		
		for (int i=0; i<curveLength; i++) {
			value += Mathf.Abs (footKeys [i].value);
			rootCurve.AddKey (new Keyframe (footKeys [i].time, value));	
			rootCurve.SmoothTangents (i, 0);
		}

		return rootCurve;

	}
开发者ID:tricsuletz,项目名称:ChubbyHeroesRun,代码行数:76,代码来源:PSMuscleEditorUtil.cs

示例14: UpdateTangentsFromMode

    void UpdateTangentsFromMode(AnimationCurve curve, int index)
    {
        if (index < 0 || index >= curve.length)
            return;
        Keyframe key = curve[index];

        // Adjust linear tangent
        if (GetKeyTangentMode(key, 0) == TangentMode.Linear && index >= 1)
        {
            key.inTangent = CalculateLinearTangent(curve[index], curve[index-1]);
        }
        if (GetKeyTangentMode(key, 1) == TangentMode.Linear && index+1 < curve.length)
        {
            key.outTangent = CalculateLinearTangent(curve[index], curve[index+1]);
        }

        float smoothWeight = 0.0F;
        //		if (index > 0 && index < curve.length - 1)
        //		{
        //			smoothWeight = Mathf.InverseLerp(curve[index - 1].time, curve[index + 1].time, curve[index].time) * 2 - 1;
        //		}

        if (GetKeyTangentMode(key, 0) == TangentMode.Smooth)
        {
            curve.SmoothTangents(index, smoothWeight);
            key.inTangent = curve[index].inTangent;
        }
        if (GetKeyTangentMode(key, 1) == TangentMode.Smooth)
        {
            curve.SmoothTangents(index, smoothWeight);
            key.outTangent = curve[index].outTangent;
        }

        curve.MoveKey(index, key);
    }
开发者ID:Ryohei-Yoshikawa,项目名称:wise9mmo,代码行数:35,代码来源:CurveEditor.cs


注:本文中的UnityEngine.AnimationCurve.SmoothTangents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。