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; }
public void Cleanup() { ab.Unload(true); originClip = null; ab = null; clip = null; }
static public int constructor(IntPtr l) { UnityEngine.AnimationClip o; o = new UnityEngine.AnimationClip(); pushObject(l, o); return(1); }
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; }
/** * The drawing function */ void OnGUI() { // Display the field for which animation clip we should inspect _AnimClip = EditorGUILayout.ObjectField( _AnimClip, typeof(AnimationClip), false ) as AnimationClip; if ( _AnimClip == null ) { EditorGUILayout.HelpBox( "Drag an Animation Clip onto the slot above", MessageType.Info, true ); return; } // If we've changed animation clips... recache our data if ( GUI.changed ) { PopulateCurves(); GUI.changed = false; Repaint(); } // Draw the path tree for all curves in a scrollable area _ScrollPosition = EditorGUILayout.BeginScrollView( _ScrollPosition ); DrawPathTree( _RootPathNode ); EditorGUILayout.EndScrollView(); // Save the changes if we're done if ( GUILayout.Button("Save Changes") ) { SaveCurveChanges(); Repaint(); } }
/// <summary> /// 监测动作状态变迁。 /// </summary> /// <param name="StateChanged">动画状态变化事件。 /// String: 动画名称。 /// Boolean: 动画变化状态。true: 动画开始;false: 动画结束。 /// </param> /// <returns>迭代器。</returns> public IEnumerator CheckAnimationChange(Action<String, Boolean> StateChanged) { while (true) { var state = m_animator.GetCurrentAnimationClipState(0);//获取当前播放动作状态 if (state.Length != 0) if (state[0].weight != 1)//当前动作正在融合 { if (m_isNotFadeing)//判断已标记为融合,如果不是融合,则表示为刚开始融合,此刻为下一个动作的开始点 { var nextState = m_animator.GetNextAnimationClipState(0); if (StateChanged != null && nextState.Length != 0) StateChanged(nextState[0].clip.name, true);//LoggerHelper.Debug(nextState[0].clip.name + " start..."); m_currentMark = state[0].clip;//更新当前动作 m_isNotFadeing = false;//标记为融合状态 yield return new WaitForFixedUpdate(); } } else { if (m_currentMark != state[0].clip)//在动作变迁时,state会瞬间变为新动作,weight变为1,所以需判断state是否已改变,此刻为旧动作结束点 { if (m_currentMark != null && StateChanged != null) StateChanged(m_currentMark.name, false);//LoggerHelper.Debug(currentMark.name + " end..."); m_currentMark = state[0].clip;//更新当前动作 m_isNotFadeing = true;//标记为非融合状态 yield return new WaitForFixedUpdate(); } } yield return new WaitForFixedUpdate(); } }
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; }
void SetLoupiotteAproach() { AnimationClip clip = new AnimationClip(); Keyframe[] xValues = new Keyframe[5]; Keyframe[] yValues = new Keyframe[5]; Keyframe[] zValues = new Keyframe[5]; Keyframe[] stateValues = new Keyframe[5]; for (int i = 0; i<5; i++) { xValues[i] = new Keyframe(i * 3.0f, i < 4 ? Random.Range(-20.0f / (2 * i + 1), 20.0f / (2 * i + 1)) : xReference); zValues[i] = new Keyframe(i * 3.0f, i < 4 ? Random.Range(-20.0f / (2 * i + 1), 20.0f / (2 * i + 1)) : zReference); stateValues[i] = new Keyframe(i * 3.0f, i < 4 ? 0.0f : 1.0f); } yValues[0] = new Keyframe(0.0f, 50.0f); yValues[1] = new Keyframe(3.0f, 35.0f); yValues[2] = new Keyframe(6.0f, 25.0f); yValues[3] = new Keyframe(9.0f, 15.0f); yValues[4] = new Keyframe(12.0f, yReference); AnimationCurve xCurve = new AnimationCurve(xValues); AnimationCurve yCurve = new AnimationCurve(yValues); AnimationCurve zCurve = new AnimationCurve(zValues); AnimationCurve stateCurve = new AnimationCurve(stateValues); clip.legacy = true; clip.SetCurve("", typeof(Loupiotte), "positionToPlayer.x", xCurve); clip.SetCurve("", typeof(Loupiotte), "positionToPlayer.y", yCurve); clip.SetCurve("", typeof(Loupiotte), "positionToPlayer.z", zCurve); clip.SetCurve("", typeof(Loupiotte), "state", stateCurve); anim.AddClip(clip, "Approche"); }
/// <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); }
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); }
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); } }
static void AnimationClip_events(JSVCall vc) { if (vc.bGet) { UnityEngine.AnimationClip _this = (UnityEngine.AnimationClip)vc.csObj; var result = _this.events; 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.AnimationEvent[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.AnimationEvent[]>(() => { int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg); int length = JSApi.getArrayLength(jsObjID); var ret = new UnityEngine.AnimationEvent[length]; for (var i = 0; i < length; i++) { JSApi.getElement(jsObjID, i); ret[i] = (UnityEngine.AnimationEvent)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove); } return(ret); }); UnityEngine.AnimationClip _this = (UnityEngine.AnimationClip)vc.csObj; _this.events = arg0; } }
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; }
static void AnimationClip_humanMotion(JSVCall vc) { UnityEngine.AnimationClip _this = (UnityEngine.AnimationClip)vc.csObj; var result = _this.humanMotion; JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(result)); }
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"); }
/// <summary> /// Find all idle animations. /// </summary> void Start () { mAnim = GetComponentInChildren<Animation>(); if (mAnim == null) { Debug.LogWarning(NGUITools.GetHierarchy(gameObject) + " has no Animation component"); Destroy(this); } else { foreach (AnimationState state in mAnim) { if (state.clip.name == "idle") { state.layer = 0; mIdle = state.clip; mAnim.Play(mIdle.name); } else if (state.clip.name.StartsWith("idle")) { state.layer = 1; mBreaks.Add(state.clip); } } // No idle breaks found -- this script is unnecessary if (mBreaks.Count == 0) Destroy(this); } }
public EventLineContextMenuObject(GameObject animated, AnimationClip clip, float time, int index) { this.m_Animated = animated; this.m_Clip = clip; this.m_Time = time; this.m_Index = index; }
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); } }
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]); } } }
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); } }
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); }
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); }
public AnimationClipSerialization(System.Object value, string fieldName, bool arrayItem, NodeBase rootNode) { this.animationClip = value as UnityEngine.AnimationClip; this.fieldName = fieldName; this.arrayItem = arrayItem; this.rootNode = rootNode; }
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)); }
public static void SampleAnimationClip(GameObject rootGameObject, AnimationClip clip, float time) { if ((UnityEngine.Object) rootGameObject != (UnityEngine.Object) null) AnimationMode.SampleAnimationClip(rootGameObject, clip, time); else CurveBindingUtility.SampleAnimationClip(clip, time); }
public void AddClip(AnimationClip clip, string newName, float speed, WrapMode wrapMode) { if (GetAnimationData(newName) != null) Debug.LogWarning("An animation with the name '" + newName + "' already exists."); LegacyAnimationData animData = new LegacyAnimationData(); animData.clip = (AnimationClip)Instantiate(clip); if (wrapMode == WrapMode.Default) wrapMode = animator.wrapMode; animData.clip.wrapMode = wrapMode; animData.clip.name = newName; animData.clipName = newName; animData.speed = speed; animData.originalSpeed = speed; animData.length = clip.length; animData.wrapMode = wrapMode; List<LegacyAnimationData> animationDataList = new List<LegacyAnimationData>(animations); animationDataList.Add(animData); animations = animationDataList.ToArray(); animator.AddClip(clip, newName); animator[newName].speed = speed; animator[newName].wrapMode = wrapMode; foreach (AnimationState animState in animator) { if (animState.name == newName) animData.animState = animState; } }
void CreateAnimatorController(AnimationClip inAnim, AnimationClip outAnim, string animName) { AnimatorController rac = AnimatorController.CreateAnimatorControllerAtPath("Assets/WindowStateManagement/PageAnimations/Controllers/"+ animName + ".controller"); //get state machine var stateMachine = rac.layers[0].stateMachine; //create parameters rac.AddParameter("Opening", AnimatorControllerParameterType.Bool); //add states stateMachine.AddState(inAnim.name); stateMachine.AddState(outAnim.name); //place clips into states AnimatorState inState = stateMachine.states[0].state; inState.motion = inAnim; inState.speed = inAnimSpeed; AnimatorState outState = stateMachine.states[1].state; outState.motion = outAnim; outState.speed = outAnimSpeed; //create transitions var inStateExitTransition = inState.AddTransition(outState); inStateExitTransition.AddCondition(AnimatorConditionMode.IfNot, 0, "Opening"); }
// fields // properties static void AnimationClip_length(JSVCall vc) { UnityEngine.AnimationClip _this = (UnityEngine.AnimationClip)vc.csObj; var result = _this.length; JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result)); }
private static void Internal_CallAnimationClipAwake(AnimationClip clip) { if (AnimationUtility.onCurveWasModified != null) { AnimationUtility.onCurveWasModified(clip, default(EditorCurveBinding), AnimationUtility.CurveModifiedType.ClipModified); } }
public void OnGUI() { clip = EditorGUILayout.ObjectField ("Clip", clip, typeof (AnimationClip), false) as AnimationClip; EditorGUILayout.LabelField ("Curves:"); if (clip != null) { foreach (var binding in AnimationUtility.GetCurveBindings (clip)) { AnimationCurve curve = AnimationUtility.GetEditorCurve (clip, binding); EditorGUILayout.LabelField (binding.path + "/" + binding.propertyName + ", Keys: " + curve.keys.Length); for(int i=0;i<curve.keys.Length;i++) { EditorGUILayout.LabelField (curve.keys[i].inTangent +" " + curve.keys[i].outTangent); curve.keys[i].inTangent = Mathf.Infinity; curve.keys[i].outTangent = Mathf.Infinity; curve.keys[i].tangentMode = 3; } AnimationUtility.SetEditorCurve(clip,binding,curve); } } }
void CopyClip(string importedPath, string copyPath) { AnimationClip newClip = new AnimationClip(); newClip.name = outputName; AssetDatabase.CreateAsset(newClip, copyPath); AssetDatabase.Refresh(); }
void CaptureRotation(Transform transform, string path, AnimationClip clip) { SetConstantCurve(clip, path, "localRotation.x", transform.localRotation.x); SetConstantCurve(clip, path, "localRotation.y", transform.localRotation.y); SetConstantCurve(clip, path, "localRotation.z", transform.localRotation.z); SetConstantCurve(clip, path, "localRotation.w", transform.localRotation.w); }
public void doAttack(BotController bot, AnimationClip attackAnimation) { this.attackAnimation = attackAnimation; if (bot != null) { impactBot(bot, attackAnimation); } }
// 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"]; }
public static RotationCurveInterpolation.State GetCurveState(AnimationClip clip, EditorCurveBinding[] selection) { RotationCurveInterpolation.State result; result.allAreNonBaked = true; result.allAreBaked = false; result.allAreRotations = false; for (int i = 0; i < selection.Length; i++) { EditorCurveBinding data = selection[i]; RotationCurveInterpolation.Mode modeFromCurveData = RotationCurveInterpolation.GetModeFromCurveData(data); if (modeFromCurveData == RotationCurveInterpolation.Mode.NonBaked) { result.allAreNonBaked = false; } else { if (modeFromCurveData == RotationCurveInterpolation.Mode.Baked) { result.allAreBaked = false; } else { result.allAreRotations = false; } } } return result; }
void Start() { if (Timer == null) Timer = GetComponent<CountdownTimer>(); if (Timer == null) { enabled = false; return; } if (Target == null) Target = animation; if (Target == null) { enabled = false; return; } cl = animation.GetClip(AnimationName); if (cl == null) { Debug.LogError("Animation " + AnimationName + " not found on object"); return; } if (!Blend) { animation.Play(AnimationName); } else { animation.Blend(AnimationName, BlendWeight, 0f); } st = animation[AnimationName]; st.speed = 0; }
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"); } }
public static string GetAnimationClipPath(UnityEngine.AnimationClip clip) { var path = UnityEditor.AssetDatabase.GetAssetPath(clip); path = path.Substring(0, path.LastIndexOf(".")) + "_" + clip.name + ".ani.bin"; path = PathHelper.CheckFileName(path); return(path); }
static public int set_wrapMode(IntPtr l) { UnityEngine.AnimationClip o = (UnityEngine.AnimationClip)checkSelf(l); UnityEngine.WrapMode v; checkEnum(l, 2, out v); o.wrapMode = v; return(0); }
static public int set_localBounds(IntPtr l) { UnityEngine.AnimationClip o = (UnityEngine.AnimationClip)checkSelf(l); UnityEngine.Bounds v; checkType(l, 2, out v); o.localBounds = v; return(0); }
static public void FastSetter(this UnityEngine.Animation o, string propertyName, UnityEngine.AnimationClip value) { switch (propertyName) { case "clip": o.clip = value; return; } LBoot.LogUtil.Error("UnityEngine.Animation no Setter Found : " + propertyName); }
protected override void Serialize(UnityEngine.Object sourceAsset) { this._animationClip = sourceAsset as UnityEngine.AnimationClip; this._animationTargets.Clear(); this._bufferWriter = new BinaryWriter(new MemoryStream()); _exportAnimation(_animationClip); }
static public int set_frameRate(IntPtr l) { UnityEngine.AnimationClip o = (UnityEngine.AnimationClip)checkSelf(l); float v; checkType(l, 2, out v); o.frameRate = v; return(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.AnimationClip animationClip = (UnityEngine.AnimationClip)value; writer.WriteProperty("frameRate", animationClip.frameRate); writer.WriteProperty("wrapMode", animationClip.wrapMode); writer.WriteProperty("localBounds", animationClip.localBounds); writer.WriteProperty("legacy", animationClip.legacy); writer.WriteProperty("events", animationClip.events); writer.WriteProperty("name", animationClip.name); writer.WriteProperty("hideFlags", animationClip.hideFlags); }
static public int get_wrapMode(IntPtr l) { try { UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); pushEnum(l, (int)self.wrapMode); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int get_events(IntPtr l) { try { UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); pushValue(l, true); pushValue(l, self.events); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int ClearCurves(IntPtr l) { try{ UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); self.ClearCurves(); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int get_events(IntPtr l) { try { UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); pushValue(l, self.events); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int EnsureQuaternionContinuity(IntPtr l) { try{ UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); self.EnsureQuaternionContinuity(); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static bool Animation_RemoveClip__AnimationClip(JSVCall vc, int argc) { int len = argc; if (len == 1) { UnityEngine.AnimationClip arg0 = (UnityEngine.AnimationClip)JSMgr.datax.getObject((int)JSApi.GetType.Arg); ((UnityEngine.Animation)vc.csObj).RemoveClip(arg0); } return(true); }
static public int get_wrapMode(IntPtr l) { try { UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); pushValue(l, true); pushEnum(l, (int)self.wrapMode); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int EnsureQuaternionContinuity(IntPtr l) { try { UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); self.EnsureQuaternionContinuity(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int ClearCurves(IntPtr l) { try { UnityEngine.AnimationClip self = (UnityEngine.AnimationClip)checkSelf(l); self.ClearCurves(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
public void OneTimeSetup() { var skeletonNodes = new[] { new SkeletonNode { ParentIndex = -1, Id = string.Empty, AxisIndex = -1 }, new SkeletonNode { ParentIndex = 0, Id = "Child1", AxisIndex = -1 }, new SkeletonNode { ParentIndex = 0, Id = "Child2", AxisIndex = -1 } }; RigDefinition = RigBuilder.CreateRigDefinition(skeletonNodes); var r = new Mathematics.Random(0x12345678); var range = new float3(100); var fullClip = new UnityEngine.AnimationClip(); // add some error into the clip, so it is not perfectly frame aligned float clipDuration = clipFrames / fullClip.frameRate + 0.123f / fullClip.frameRate; CreateLinearTranslate(fullClip, string.Empty, float3.zero, new float3(0, 1, 0), clipDuration); CreateLinearTranslate(fullClip, "Child1", r.NextFloat3(-range, range), r.NextFloat3(-range, range), clipDuration); CreateLinearTranslate(fullClip, "Child2", r.NextFloat3(-range, range), r.NextFloat3(-range, range), clipDuration); CreateRotation(fullClip, string.Empty, quaternion.identity, r.NextQuaternionRotation(), clipDuration); CreateRotation(fullClip, "Child1", r.NextQuaternionRotation(), r.NextQuaternionRotation(), clipDuration); CreateRotation(fullClip, "Child2", r.NextQuaternionRotation(), r.NextQuaternionRotation(), clipDuration); CreateScale(fullClip, string.Empty, new float3(1), new float3(1), clipDuration); CreateScale(fullClip, "Child1", new float3(1), new float3(2), clipDuration); CreateScale(fullClip, "Child2", new float3(2), new float3(3), clipDuration); FullAnimationClip = ClipBuilder.AnimationClipToDenseClip(fullClip); var partialClip = new UnityEngine.AnimationClip(); CreateLinearTranslate(partialClip, "Child1", r.NextFloat3(-range, range), r.NextFloat3(-range, range), clipDuration); CreateRotation(partialClip, string.Empty, quaternion.identity, r.NextQuaternionRotation(), clipDuration); CreateRotation(partialClip, "Child2", quaternion.identity, r.NextQuaternionRotation(), clipDuration); CreateScale(partialClip, string.Empty, float3.zero, new float3(1), clipDuration); PartialAnimationClip = ClipBuilder.AnimationClipToDenseClip(partialClip); var alignedClip = new UnityEngine.AnimationClip(); CreateLinearTranslate(alignedClip, string.Empty, float3.zero, new float3(0, 1, 0), 1.0f); CreateLinearTranslate(alignedClip, "Child1", r.NextFloat3(-range, range), r.NextFloat3(-range, range), 1.0f); CreateLinearTranslate(alignedClip, "Child2", r.NextFloat3(-range, range), r.NextFloat3(-range, range), 1.0f); CreateRotation(alignedClip, string.Empty, quaternion.identity, r.NextQuaternionRotation(), 1.0f); AlignedClip = ClipBuilder.AnimationClipToDenseClip(alignedClip); }
static public int constructor(IntPtr l) { try { UnityEngine.AnimationClip o; o = new UnityEngine.AnimationClip(); pushValue(l, o); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static bool Animation_AddClip__AnimationClip__String(JSVCall vc, int argc) { int len = argc; if (len == 2) { UnityEngine.AnimationClip arg0 = (UnityEngine.AnimationClip)JSMgr.datax.getObject((int)JSApi.GetType.Arg); System.String arg1 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); ((UnityEngine.Animation)vc.csObj).AddClip(arg0, arg1); } return(true); }
static public int constructor(IntPtr l) { LuaDLL.lua_remove(l, 1); UnityEngine.AnimationClip o; if (matchType(l, 1)) { o = new UnityEngine.AnimationClip(); pushObject(l, o); return(1); } LuaDLL.luaL_error(l, "New object failed."); return(0); }
static public int constructor(IntPtr l) { try { UnityEngine.AnimationClip o; o = new UnityEngine.AnimationClip(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
static bool GameObject_SampleAnimation__AnimationClip__Single(JSVCall vc, int argc) { int len = argc; if (len == 2) { UnityEngine.AnimationClip arg0 = (UnityEngine.AnimationClip)JSMgr.datax.getObject((int)JSApi.GetType.Arg); System.Single arg1 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg); ((UnityEngine.GameObject)vc.csObj).SampleAnimation(arg0, arg1); } return(true); }
// public static AnimationCurve[] GetAllCurvesForClip (UnityEngine.AnimationClip clip) // { // if (s_curvesPerClip.ContainsKey (clip)) { // return s_curvesPerClip [clip].ToArray (); // } else { // return new AnimationCurve[0]; // } // } public static void RemovePositionCurves(UnityEngine.AnimationClip clip, FrameContainer frames) { foreach (var frame in frames) { string bonePath = frame.Path; // foreach (var translateAxis in s_translateAxes) { // clip.SetCurve (bonePath, typeof(Transform), "localPosition." + translateAxis.Name, null); // } clip.SetCurve(bonePath, typeof(Transform), "m_LocalPosition", null); } }