本文整理汇总了C#中UnityEngine.AnimationClip.SetCurve方法的典型用法代码示例。如果您正苦于以下问题:C# AnimationClip.SetCurve方法的具体用法?C# AnimationClip.SetCurve怎么用?C# AnimationClip.SetCurve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AnimationClip
的用法示例。
在下文中一共展示了AnimationClip.SetCurve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveTo
public static void MoveTo(GameObject obj, 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, obj.transform.localPosition.x, duration, NewPos.x);
AnimationCurve curvey = AnimationCurve.Linear(0, obj.transform.localPosition.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);
}
示例2: 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"];
}
示例3: UpdatePosition
public void UpdatePosition()
{
UpdatePositionChildren();
if (!NewPosition())
return;
float clipLength = 0.4f;
AnimationCurve curve1 = null, curve2 = null, curve3 = null;
AnimationClip clip = null;
clip = new AnimationClip();
curve1 = AnimationCurve.Linear(0, m_platform.localPosition.x, clipLength, m_newPosition.x);
curve2 = AnimationCurve.Linear(0, m_platform.localPosition.y, clipLength, m_newPosition.y);
curve3 = AnimationCurve.Linear(0, m_platform.localPosition.z, clipLength, m_newPosition.z);
clip.legacy = true;
clip.SetCurve("", typeof(Transform), "localPosition.x", curve1);
clip.SetCurve("", typeof(Transform), "localPosition.y", curve2);
clip.SetCurve("", typeof(Transform), "localPosition.z", curve3);
if (!m_platform.gameObject.GetComponent<Animation>())
m_platform.gameObject.AddComponent<Animation>();
m_platform.gameObject.GetComponent<Animation>().AddClip(clip, "AnimationDemo");
foreach (AnimationState state in m_platform.gameObject.GetComponent<Animation>())
state.speed = 1;
m_platform.gameObject.GetComponent<Animation>().Play("AnimationDemo");
}
示例4: 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;
}
示例5: 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;
}
示例6: Start
// Use this for initialization
void Start()
{
GameObject[] ob_cubes;
ob_cubes = GameObject.FindGameObjectsWithTag("ob_cube");
foreach (GameObject obj in ob_cubes)
{
Vector3 move = obj.transform.position;
AnimationClip clip = new AnimationClip();
clip.legacy = true;
Keyframe[] keysX = new Keyframe[2];
keysX[0] = new Keyframe(0f, move.x - 5);
keysX[1] = new Keyframe(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(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(1f, move.z);
AnimationCurve curveZ = new AnimationCurve(keysZ);
clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ);
Animation animation = obj.GetComponent<Animation>();
animation.AddClip(clip, "clip1");
animation.Play("clip1");
}
}
示例7: 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");
}
}
示例8: 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);
}
示例9: moveto
AnimationClip moveto(Vector3 s, Vector3 e)
{
AnimationClip ret = new AnimationClip();
ret.SetCurve("", typeof(Transform), "localPosition.x", AnimationCurve.Linear(0, s.x, 1, e.x));
ret.SetCurve("", typeof(Transform), "localPosition.y", AnimationCurve.Linear(0, s.y, 1, e.y));
ret.SetCurve("", typeof(Transform), "localPosition.z", AnimationCurve.Linear(0, s.z, 1, e.z));
return ret;
}
示例10: MakeClip
public AnimationClip MakeClip(float inDuration, Vector3 inLocalPosition)
{
AnimationClip outClip = new AnimationClip();
outClip.legacy = true;
outClip.SetCurve("", typeof(Transform), "localPosition.x", AnimationCurve.Linear(0, transform.localPosition.x, inDuration, inLocalPosition.x));
outClip.SetCurve("", typeof(Transform), "localPosition.y", AnimationCurve.Linear(0, transform.localPosition.y, inDuration, inLocalPosition.y));
outClip.SetCurve("", typeof(Transform), "localPosition.z", AnimationCurve.Linear(0, transform.localPosition.z, inDuration, inLocalPosition.z));
return outClip;
}
示例11: CreateAnimations
public void CreateAnimations()
{
SpriteAnimator myScript = (SpriteAnimator)target;
Animation myAnimation = myScript.gameObject.GetComponent<Animation>();
Object[] selection = Selection.GetFiltered(typeof(Texture2D), SelectionMode.Unfiltered);
SpriteList[] sheets = new SpriteList[selection.Length];
for (int i = 0; i < selection.Length; i++)
{
Object texture = selection[i];
sheets[i] = new SpriteList();
string textureAssetPath = AssetDatabase.GetAssetPath(texture);
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(textureAssetPath).OfType<Sprite>().ToArray();
sheets[i].sprites = sprites;
sheets[i].name = texture.name;
AnimationClip clip = new AnimationClip();
clip.name = texture.name;
clip.frameRate = sprites.Length + 1;
clip.wrapMode = WrapMode.Once;
float frameDuration = 1.0f / clip.frameRate;
AnimationCurve indexCurve = AnimationCurve.Linear(0.0f, 0.0f, (clip.frameRate - 1) * frameDuration, sprites.Length - 1);
AnimationCurve sheetCurve = AnimationCurve.Linear(0.0f, i, clip.frameRate * frameDuration, i);
indexCurve.AddKey(clip.frameRate * frameDuration, sprites.Length - 1);
clip.SetCurve("", typeof(SpriteAnimator), "index", indexCurve);
clip.SetCurve("", typeof(SpriteAnimator), "sheet", sheetCurve);
// AnimationUtility.SetAnimationType(clip, ModelImporterAnimationType.Legacy);
string prefabFolder = Directory.GetParent(textureAssetPath).ToString();
string clipFile = prefabFolder + "/" + clip.name + ".anim";
AssetDatabase.CreateAsset(clip, clipFile);
myAnimation.AddClip(clip, clip.name);
}
AssetDatabase.SaveAssets();
myScript.sheets = sheets;
}
示例12: Start
void Start()
{
gameObject.AddComponent<Animation>();
gameObject.AddComponent<SkinnedMeshRenderer>();
SkinnedMeshRenderer renderer = GetComponent<SkinnedMeshRenderer>();
Mesh mesh = new Mesh();
mesh.vertices = new Vector3[] { new Vector3(-1, 0, 0), new Vector3(1, 0, 0), new Vector3(-1, 5, 0), new Vector3(1, 5, 0) };
mesh.uv = new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 1) };
mesh.triangles = new int[] { 0, 1, 2, 1, 3, 2 };
mesh.RecalculateNormals();
renderer.material = new Material(Shader.Find(" Diffuse"));
BoneWeight[] weights = new BoneWeight[4];
weights[0].boneIndex0 = 0;
weights[0].weight0 = 1;
weights[1].boneIndex0 = 0;
weights[1].weight0 = 1;
weights[2].boneIndex0 = 1;
weights[2].weight0 = 1;
weights[3].boneIndex0 = 1;
weights[3].weight0 = 1;
mesh.boneWeights = weights;
Transform[] bones = new Transform[2];
Matrix4x4[] bindPoses = new Matrix4x4[2];
bones[0] = new GameObject("Lower").transform;
bones[0].parent = transform;
bones[0].localRotation = Quaternion.identity;
bone0_ratation = bones[0].localRotation;
bones[0].localPosition = Vector3.zero;
bindPoses[0] = bones[0].worldToLocalMatrix * transform.localToWorldMatrix;
bones[1] = new GameObject("Upper").transform;
bones[1].parent = transform;
bones[1].localRotation = new Quaternion(0, 0, 0.717f, 0.717f);
bone1_ratation = bones[1].localRotation;
bones[1].localPosition = new Vector3(0, 5, 0);
bindPoses[1] = bones[1].worldToLocalMatrix * transform.localToWorldMatrix;
mesh.bindposes = bindPoses;
renderer.bones = bones;
renderer.sharedMesh = mesh;
AnimationCurve curve = new AnimationCurve();
curve.keys = new Keyframe[] { new Keyframe(0, 0), new Keyframe(1, 3), new Keyframe(2, 0.0F) };
AnimationClip clip = new AnimationClip();
clip.SetCurve("Lower", typeof(Transform), "m_LocalPosition.y", curve);
AnimationCurve curve1 = new AnimationCurve();
curve1.keys = new Keyframe[] { new Keyframe(0, 5), new Keyframe(1, 3), new Keyframe(2, 5F) };
clip.SetCurve("Upper", typeof(Transform), "m_LocalPosition.y", curve1);
clip.wrapMode = WrapMode.Loop;
animation.AddClip(clip, "test");
animation.Play("test");
}
示例13: Start
void Start()
{
GameObject.Find("GUI Text").guiText.text = "AnimationClip sample";
AnimationClip clipA = new AnimationClip();
AnimationCurve curveA = AnimationCurve.Linear(0f, 3f, 3f, 3f);
Keyframe keyA = new Keyframe(1.5f, 10f);
curveA.AddKey(keyA);
clipA.SetCurve("", typeof(Transform), "localPosition.z", curveA);
clipA.wrapMode = WrapMode.Loop;
animation.AddClip(clipA, "anim1");
AnimationClip clipB = new AnimationClip();
AnimationCurve curveB = AnimationCurve.Linear(0f, 3f, 3f, 3f);
Keyframe key1 = new Keyframe(0.75f, 7f);
curveB.AddKey(key1);
Keyframe key2 = new Keyframe(1.5f, 3f);
curveB.AddKey(key2);
Keyframe key3 = new Keyframe(2.25f,7f);
curveB.AddKey (key3);
clipB.SetCurve("", typeof(Transform), "localPosition.z", curveB);
clipB.wrapMode = WrapMode.Loop;
animation.AddClip(clipB, "anim2");
animation.Play ("anim1");
}
示例14: CreateAnimationClip
void CreateAnimationClip()
{
CameraShakeTool tool = target as CameraShakeTool;
List<Keyframe> keyframeList = new List<Keyframe>();
foreach (Vector2 v in tool.value)
{
Keyframe k = new Keyframe(v.x, v.y);
keyframeList.Add(k);
}
AnimationClip clip = new AnimationClip();
#if UNITY_5
clip.legacy = true;
#endif
clip.wrapMode = WrapMode.Once;
clip.SetCurve("", typeof(Transform), "localPosition.x", new AnimationCurve(keyframeList.ToArray()));
string activePath = AssetDatabase.GetAssetPath(Selection.activeObject);
string directory = Path.GetDirectoryName(activePath);
string filename = Path.GetFileNameWithoutExtension(activePath);
string path = directory + "/" + filename + ".anim";
string clipPath = AssetDatabase.GenerateUniqueAssetPath(path);
AssetDatabase.CreateAsset(clip, clipPath);
}
示例15: create_animation
void create_animation()
{
AnimationCurve curve_height,curve_x,curve_z;
AnimationClip clip;
Animation anim;
tempcount = 4;
time_slice[] height_data = new time_slice[144];
for (int time=0; time<143; time++) {
height_data[time] = new time_slice();
for(int i=0;i<20*20;i++){
height_data[time].height[i] = float.Parse(strArr[tempcount-2]);
height_data[time].x[i] = float.Parse(strArr[tempcount-3]);
height_data[time].z[i] = float.Parse(strArr[tempcount-1]);
tempcount = tempcount+4;
}
}
Debug.Log (height_data.Length);
tempcount = 0;
for (float i=0; i<20; i++) {
for (float j=-0; j<20; j++) {
ammo = GameObject.Find (i.ToString () + "," + j.ToString () + "terrain");
anim = ammo.gameObject.GetComponent<Animation>();
curve_height = new AnimationCurve();
curve_x = new AnimationCurve();
curve_z = new AnimationCurve();
clip = new AnimationClip();
for(int k=0;k<143;k++){
curve_height.AddKey(k*timesclice,height_data[k].height[tempcount]);
curve_x.AddKey(k*timesclice,height_data[k].x[tempcount]);
curve_z.AddKey(k*timesclice,height_data[k].z[tempcount]);
}
tempcount++;
clip.legacy = true;
clip.SetCurve("",typeof(Transform), "localPosition.y", curve_height);
clip.SetCurve("",typeof(Transform),"localPosition.x",curve_x);
clip.SetCurve("",typeof(Transform), "localPosition.z", curve_z);
anim.AddClip(clip,"anim");
anim.Play("anim");
//Debug.Log(clip.length);
anim["anim"].speed =1;
}
}
}