Created
March 13, 2017 10:27
-
-
Save takashicompany/17d5a85ef3235a8f41b159a5bef7fa14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace TakashiCompany.Unity.Extension | |
{ | |
using UnityEngine; | |
/// <summary> | |
/// UnityEngine.Animation extension. | |
/// </summary> | |
public static class AnimationSampleExtension | |
{ | |
public static void SampleWithTime( | |
this Animation self, | |
string animationName, | |
float time, | |
float weight = 1f | |
) | |
{ | |
var anim = self[animationName]; | |
anim.enabled = true; | |
anim.time = time; | |
anim.weight = weight; | |
self.Sample(); | |
anim.enabled = false; | |
} | |
public static void SampleWithTime( | |
this Animation self, | |
float time, | |
float weight = 1f | |
) | |
{ | |
self.SampleWithTime(self.clip.name, time, weight); | |
} | |
public static void SampleWithNormalizedTime( | |
this Animation self, | |
string animationName, | |
float normalizedTime, | |
float weight = 1f | |
) | |
{ | |
var anim = self[animationName]; | |
anim.enabled = true; | |
anim.normalizedTime = normalizedTime; | |
anim.weight = weight; | |
self.Sample(); | |
anim.enabled = false; | |
} | |
public static void SampleWithNormalizedTime( | |
this Animation self, | |
float normalizedTime, | |
float weight = 1f | |
) | |
{ | |
self.SampleWithNormalizedTime(self.clip.name, normalizedTime, weight); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment