本文整理汇总了C#中UnityEngine.AnimationClip类的典型用法代码示例。如果您正苦于以下问题:C# AnimationClip类的具体用法?C# AnimationClip怎么用?C# AnimationClip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnimationClip类属于UnityEngine命名空间,在下文中一共展示了AnimationClip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MovePlayer
IEnumerator MovePlayer()
{
Spell rootSpell = gameObject.GetComponent<Spell>();
Transform player = rootSpell.m_myCaster.transform;
// Change animation curves relative to the player's current position
for (int i = 0; i < x.keys.Length; ++i) {
x.keys[i].value += player.position.x;
}
for (int i = 0; i < y.keys.Length; ++i) {
y.keys[i].value += player.position.y;
}
for (int i = 0; i < z.keys.Length; ++i) {
z.keys[i].value += player.position.z;
}
// Create the clip
AnimationClip clip = new AnimationClip();
clip.ClearCurves();
clip.SetCurve("", typeof(Transform), "localPosition.x", x);
clip.SetCurve("", typeof(Transform), "localPosition.y", y);
clip.SetCurve("", typeof(Transform), "localPosition.z", z);
PlayerController controller = player.GetComponent<PlayerController>();
player.networkView.RPC("LockPlayer", player.networkView.owner);
float startTime = Time.time;
while(Time.time < startTime + duration) {
}
return null;
}
示例2: AssignAnimationToCharacter
/// <summary>
/// Assigns the animation to the character.
/// </summary>
static void AssignAnimationToCharacter(AnimationClip clip, GameObject character)
{
//create a new controller
UnityEditorInternal.AnimatorController my_controller = new UnityEditorInternal.AnimatorController();
my_controller.name = "generic_controller";
//check if the animator component is already attached to the character
if (character.GetComponent<Animator>() == null)
character.AddComponent<Animator>();
//create the state machine with the animation clip
StateMachine sm = new StateMachine();
sm.AddState("default_state");
sm.GetState(0).SetMotion(0, clip);
//check if the controller already has a based layer
if (my_controller.GetLayerCount() == 0)
my_controller.AddLayer("Base Layer");
//set the state machine
my_controller.SetLayerStateMachine(0, sm);
//assign the controller
Animator animator = (Animator)character.GetComponent<Animator>();
UnityEditorInternal.AnimatorController.SetAnimatorController(animator,my_controller);
}
示例3: CaptureTransform
void CaptureTransform(Transform transform, string path, AnimationClip clip)
{
path += transform.name;
//Debug.Log(path);
if (position.Value)
{
CapturePosition(transform, path, clip);
}
if (rotation.Value)
{
CaptureRotation(transform, path, clip);
}
if (scale.Value)
{
CaptureScale(transform, path, clip);
}
foreach (Transform child in transform)
{
CaptureTransform(child, path + "/", clip);
}
}
示例4: MoveGO
public static void MoveGO(GameObject TempGO, Vector3 StartPos, Vector3 EndPos, float length)
{
AnimationCurve curve1 = null, curve2 = null, curve3 = null;
curve1 = AnimationCurve.EaseInOut(0, StartPos.x, length, EndPos.x);
curve2 = AnimationCurve.EaseInOut(0, StartPos.y, length, EndPos.y);
curve3 = AnimationCurve.EaseInOut(0, StartPos.z, length, EndPos.z);
AnimationClip clip = new AnimationClip();
clip.SetCurve("", typeof(Transform), "localPosition.x", curve1);
clip.SetCurve("", typeof(Transform), "localPosition.y", curve2);
clip.SetCurve("", typeof(Transform), "localPosition.z", curve3);
clip.legacy = true;
if (TempGO.GetComponent<Animation>() == null)
{
TempGO.AddComponent<Animation>();
}
string clipName = "MoveAnimation";
Animation animation = TempGO.GetComponent<Animation>();
if (animation.IsPlaying(clipName))
{
//TempGO.animation["AnimationDemo"].time = 0.5f ;
animation.Sample();
animation.RemoveClip(clipName);
}
animation.AddClip(clip, clipName);
animation["MoveAnimation"].speed = 1.0F;
animation.Play("MoveAnimation");
//TempGO.animation.wrapMode=WrapMode.PingPong;
}
示例5: ExtractFromPreviewClip
public void ExtractFromPreviewClip(AnimationClip clip)
{
AnimationClipSettings animationClipSettings = AnimationUtility.GetAnimationClipSettings(clip);
if ((this.firstFrame / clip.frameRate) != animationClipSettings.startTime)
{
this.firstFrame = this.FixPrecisionErrors(animationClipSettings.startTime * clip.frameRate);
}
if ((this.lastFrame / clip.frameRate) != animationClipSettings.stopTime)
{
this.lastFrame = this.FixPrecisionErrors(animationClipSettings.stopTime * clip.frameRate);
}
this.orientationOffsetY = animationClipSettings.orientationOffsetY;
this.level = animationClipSettings.level;
this.cycleOffset = animationClipSettings.cycleOffset;
this.loopTime = animationClipSettings.loopTime;
this.loopBlend = animationClipSettings.loopBlend;
this.loopBlendOrientation = animationClipSettings.loopBlendOrientation;
this.loopBlendPositionY = animationClipSettings.loopBlendPositionY;
this.loopBlendPositionXZ = animationClipSettings.loopBlendPositionXZ;
this.keepOriginalOrientation = animationClipSettings.keepOriginalOrientation;
this.keepOriginalPositionY = animationClipSettings.keepOriginalPositionY;
this.keepOriginalPositionXZ = animationClipSettings.keepOriginalPositionXZ;
this.heightFromFeet = animationClipSettings.heightFromFeet;
this.mirror = animationClipSettings.mirror;
this.hasAdditiveReferencePose = animationClipSettings.hasAdditiveReferencePose;
if ((this.additiveReferencePoseFrame / clip.frameRate) != animationClipSettings.additiveReferencePoseTime)
{
this.additiveReferencePoseFrame = this.FixPrecisionErrors(animationClipSettings.additiveReferencePoseTime * clip.frameRate);
}
}
示例6: Start
// Use this for initialization
void Start()
{
m_InitialPosition = gameObject.transform.localPosition;
m_RelPosition.Set(0, 0, 0);
m_Translations = new Vector3[3];
m_Translations[0].Set(m_Speed, 0, 0);
m_Translations[1].Set(0, m_Speed, 0);
m_Translations[2].Set(0, 0, m_Speed);
gameObject.AddComponent<Animation>();
gameObject.animation.animatePhysics = true;
m_Forward = new AnimationClip();
var curvex = new AnimationCurve();
var curvey = new AnimationCurve();
var curvez = new AnimationCurve();
var minpos = m_InitialPosition+m_MinIncrement;
var maxpos = m_InitialPosition-m_MaxIncrement;
float dist = (minpos-maxpos).magnitude;
m_MaxTime = dist/m_Speed;
curvex.AddKey(0f, minpos.x);
curvex.AddKey(dist/m_Speed, maxpos.x);
curvey.AddKey(0f, minpos.y);
curvey.AddKey(dist/m_Speed, maxpos.y);
curvez.AddKey(0f, minpos.z);
curvez.AddKey(dist/m_Speed, maxpos.z);
m_Forward.wrapMode = WrapMode.ClampForever;
m_Forward.SetCurve("", typeof(Transform), "localPosition.x", curvex);
m_Forward.SetCurve("", typeof(Transform), "localPosition.y", curvey);
m_Forward.SetCurve("", typeof(Transform), "localPosition.z", curvez);
this.animation.AddClip(m_Forward, "Forward");
this.animation.Play("Forward");
m_ForwardState = this.animation["Forward"];
}
示例7: createAnimation
public static void createAnimation()
{
GameObject go = GameObject.Find(GAME_OBJECT_NAME);
if (go != null)
removeGameObjectAndComponents(go);
Animator animator;
go = createGameObjects(out animator);
AnimationClip animationClip = new AnimationClip();
AnimationUtility.SetAnimationType(animationClip, ModelImporterAnimationType.Generic);
AnimationCurve activeCurve = new AnimationCurve();
AnimationCurve positionLineCurve = new AnimationCurve();
AnimationCurve positionSmoothCurve = new AnimationCurve();
for (int i = 0; i < stepValues.Length; i++) {
float time = stepTime * i;
activeCurve .AddKey(KeyframeUtil.GetNew(time, stepValues[i] , TangentMode.Stepped));
positionLineCurve .AddKey(KeyframeUtil.GetNew(time, stepValues[i] + 2, TangentMode.Linear));
positionSmoothCurve.AddKey(KeyframeUtil.GetNew(time, stepValues[i] - 2, TangentMode.Smooth));
}
//this will be linear curve, so need to update tangents (should be after keyframes assignments)
positionLineCurve.UpdateAllLinearTangents();
animationClip.SetCurve(CUBE1_NAME, typeof(GameObject),"m_IsActive", activeCurve);
animationClip.SetCurve(CUBE2_NAME, typeof(Transform),"localPosition.x", positionLineCurve);
animationClip.SetCurve(CUBE2_NAME, typeof(Transform),"localPosition.y", positionSmoothCurve);
AssetDatabase.CreateAsset(animationClip, ANIMATION_CLIP_PATH);
AssetDatabase.SaveAssets();
AddClipToAnimatorComponent(go, animator, animationClip);
}
示例8: Criate
static void Criate()
{
string dir = "Assets/";
Object selected = Selection.activeObject;
if (selected != null) {
string assetDir = AssetDatabase.GetAssetPath(selected.GetInstanceID());
if (assetDir.Length > 0 && Directory.Exists(assetDir))
dir = assetDir + "/";
}
AnimationClip clip = new AnimationClip ();
clip.frameRate = 30.0f;
clip.legacy = true;
string name = "New Animation (Legacy)";
string extension = ".anim";
if (AssetDatabase.LoadAssetAtPath<AnimationClip> (string.Format (dir+name+extension)) != null) {
int prefix = 1;
while (AssetDatabase.LoadAssetAtPath<AnimationClip> (string.Format (dir+name+" {0:0}" + extension, prefix)) != null) {
prefix++;
}
name = string.Format (name+" {0:0}", prefix);
}
AssetDatabase.CreateAsset(clip, dir + name + extension);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = clip;
}
示例9: SetEveryBone
static void SetEveryBone(AnimationClip clip, string[] allNeedPath)
{
Debug.Log("allNeedPath count: " + allNeedPath.Length);
var AllData = AnimationUtility.GetAllCurves(clip);
List<string> existedPath = new List<string>();
foreach (AnimationClipCurveData data in AllData)
{
if (!existedPath.Contains(data.path)) { existedPath.Add(data.path);}// Debug.Log(data.path); }
}
List<string> needKeyPath = new List<string>();
foreach (var p in allNeedPath)
{
if (!existedPath.Contains(p))
{
needKeyPath.Add(p);
}
}
foreach (var p in needKeyPath)
{
Debug.Log(p);
}
}
示例10: Start
void Start()
{
moves[0] = new Vector3( 0f, 1f, 0f);
moves[1] = new Vector3(-3f, 1f, 5f);
moves[2] = new Vector3( 3f, 1f, 5f);
moves[3] = new Vector3(-3f, 1f, -3f);
moves[4] = new Vector3( 3f, 1f, -3f);
for(int i=0;i<5;i++){
cubes[i] = GameObject.Find ("BoardCube"+i);
Vector3 move = cubes[i].transform.position;
AnimationClip clip = new AnimationClip();
Keyframe[] keysX = new Keyframe[2];
keysX[0] = new Keyframe( 0f, move.x-3);
keysX[1] = new Keyframe(i+1f, move.x+3);
AnimationCurve curveX = new AnimationCurve(keysX);
clip.SetCurve("", typeof(Transform), "localPosition.x", curveX);
clip.wrapMode = WrapMode.PingPong;
Keyframe[] keysY = new Keyframe[2];
keysY[0] = new Keyframe( 0f, move.y);
keysY[1] = new Keyframe(i+1f, move.y);
AnimationCurve curveY = new AnimationCurve(keysY);
clip.SetCurve("", typeof(Transform), "localPosition.y", curveY);
Keyframe[] keysZ = new Keyframe[2];
keysZ[0] = new Keyframe( 0f, move.z);
keysZ[1] = new Keyframe(i+1f, move.z);
AnimationCurve curveZ = new AnimationCurve(keysZ);
clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ);
cubes[i].animation.AddClip(clip, "clip1");
cubes[i].animation.Play("clip1");
}
}
示例11: GetCurveState
public static State GetCurveState(AnimationClip clip, EditorCurveBinding[] selection)
{
State state;
state.allAreNonBaked = true;
state.allAreBaked = false;
state.allAreRotations = false;
foreach (EditorCurveBinding binding in selection)
{
switch (GetModeFromCurveData(binding))
{
case Mode.NonBaked:
state.allAreNonBaked = false;
break;
case Mode.Baked:
state.allAreBaked = false;
break;
default:
state.allAreRotations = false;
break;
}
}
return state;
}
示例12: CopyClip
void CopyClip(string importedPath, string copyPath)
{
AnimationClip newClip = new AnimationClip();
newClip.name = outputName;
AssetDatabase.CreateAsset(newClip, copyPath);
AssetDatabase.Refresh();
}
示例13: MoveTo
public static void MoveTo(GameObject obj, Vector2 startpos, Vector2 NewPos, float duration, float z)
{
Animation anim = obj.GetComponent<Animation>();
//if (anim.GetClipCount() > 1)
//{
// anim.RemoveClip("Moveto");
//}
anim.enabled = true;
AnimationClip animclip = new AnimationClip();
#if UNITY_5
animclip.legacy = true;
#endif
AnimationCurve curvex = AnimationCurve.Linear(0, startpos.x, duration, NewPos.x);
AnimationCurve curvey = AnimationCurve.Linear(0, startpos.y, duration, NewPos.y);
AnimationCurve curvez = AnimationCurve.Linear(0, z, duration, z);
AnimationCurve curvenable = AnimationCurve.Linear(0, 1, duration, 0);
animclip.SetCurve("", typeof(Transform), "localPosition.x", curvex);
animclip.SetCurve("", typeof(Transform), "localPosition.y", curvey);
animclip.SetCurve("", typeof(Transform), "localPosition.z", curvez);
animclip.SetCurve("", typeof(Animation), "m_Enabled", curvenable);
anim.AddClip(animclip, "Moveto");
anim.Play("Moveto");
Destroy(animclip, duration);
}
示例14: Play
public static void Play(this Animator animator, AnimationClip clip, float normalizedTime=0f)
{
AnimatorOverrideController animatorOverrideController;
AnimationClip clipOverride = null;
if (animator.runtimeAnimatorController is AnimatorOverrideController) {
//animator.runtimeAnimatorController is already overrided just take reference
animatorOverrideController = animator.runtimeAnimatorController as AnimatorOverrideController;
clipOverride = animatorOverrideController.clips [0].originalClip;
} else {
//AS RuntimeAnimatorController can't be created at runtime
RuntimeAnimatorController dummyController = AnimatorUtilityEx.DUMMY_CONTROLLER;
clipOverride = dummyController.animationClips [0];
animatorOverrideController = new AnimatorOverrideController ();
//bind all clips from animator.runtimeAnimatorController to overrider
animatorOverrideController.runtimeAnimatorController = dummyController;
}
animatorOverrideController [clipOverride] = clip;
//to avoid nesting
if (animator.runtimeAnimatorController is AnimatorOverrideController) {
animator.runtimeAnimatorController = animatorOverrideController.runtimeAnimatorController;
}
//rebind back
animator.runtimeAnimatorController = animatorOverrideController;
animator.Play ("Override", 0, normalizedTime);
}
示例15: AddCurves
public void AddCurves(AnimationClip animClip)
{
foreach(var kvp in curveCache)
{
var curves = kvp.Value.Curves;
//Position curves
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localPosition.x", curves[(int)AnimationCurveIndex.LocalPositionX]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localPosition.y", curves[(int)AnimationCurveIndex.LocalPositionY]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localPosition.z", curves[(int)AnimationCurveIndex.LocalPositionZ]);
//Rotation curves
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localRotation.x", curves[(int)AnimationCurveIndex.LocalRotationX]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localRotation.y", curves[(int)AnimationCurveIndex.LocalRotationY]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localRotation.z", curves[(int)AnimationCurveIndex.LocalRotationZ]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localRotation.w", curves[(int)AnimationCurveIndex.LocalRotationW]);
//Scale curves
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localScale.x", curves[(int)AnimationCurveIndex.LocalScaleX]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localScale.y", curves[(int)AnimationCurveIndex.LocalScaleY]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(Transform), "localScale.z", curves[(int)AnimationCurveIndex.LocalScaleZ]);
//IsActive curve
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(GameObject), "m_IsActive", curves[(int)AnimationCurveIndex.IsActive]);
if (kvp.Value.IsSpriteKey)
{
//Color Tint curve
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(SpriteRenderer), "m_Color.r", curves[(int)AnimationCurveIndex.ColorR]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(SpriteRenderer), "m_Color.g", curves[(int)AnimationCurveIndex.ColorG]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(SpriteRenderer), "m_Color.b", curves[(int)AnimationCurveIndex.ColorB]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(SpriteRenderer), "m_Color.a", curves[(int)AnimationCurveIndex.ColorA]);
SetCurveIfNotEmpty(ref animClip, kvp.Key, typeof(SortingOrderUpdate), "SortingOrder", curves[(int)AnimationCurveIndex.ZIndex]);
}
}
}