public AnimDef GetActiveAnimation(out float position) { if (Object.op_Inequality((Object)this.mAnimation, (Object)null)) { IEnumerator enumerator = this.mAnimation.GetEnumerator(); try { while (enumerator.MoveNext()) { AnimationState current = (AnimationState)enumerator.Current; AnimDef animation = this.FindAnimation(current.get_name()); if (!Object.op_Equality((Object)animation, (Object)null)) { position = current.get_wrapMode() != 2 ? current.get_time() : current.get_time() % current.get_length(); return(animation); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } position = 0.0f; return((AnimDef)null); }
private new void Update() { this.mCameraShakeOffset = Quaternion.get_identity(); base.Update(); if (!this.mLoadingAnimation || this.IsLoading) { return; } this.mAnimationLoaded = true; this.mLoadingAnimation = false; ((Component)this).get_transform().set_position(this.mStartPosition); this.mCameraID = 0; this.PlayAnimation(PreviewUnitController.SLOT0, this.mLoopAnimation); AnimDef animation = this.GetAnimation(PreviewUnitController.SLOT0); if (Object.op_Inequality((Object)this.mCameraAnimation, (Object)null)) { ((Animation)((Component)this.mCameraPos).GetComponent <Animation>()).AddClip(this.mCameraAnimation, PreviewUnitController.SLOT0); ((Animation)((Component)this.mCameraPos).GetComponent <Animation>()).Play(PreviewUnitController.SLOT0); ((Animation)((Component)this.mCameraPos).GetComponent <Animation>()).get_Item(PreviewUnitController.SLOT0).set_speed((float)(1.0 / (double)this.mCameraAnimation.get_length() * 1.0) / animation.Length); } else { ((Animation)((Component)this.mCameraPos).GetComponent <Animation>()).AddClip(animation.animation, PreviewUnitController.SLOT0); ((Animation)((Component)this.mCameraPos).GetComponent <Animation>()).Play(PreviewUnitController.SLOT0); ((Animation)((Component)this.mCameraPos).GetComponent <Animation>()).get_Item(PreviewUnitController.SLOT0).set_speed(1f); } ((Animation)((Component)this.mEnemyPos).GetComponent <Animation>()).AddClip(animation.animation, PreviewUnitController.SLOT0); ((Animation)((Component)this.mEnemyPos).GetComponent <Animation>()).Play(PreviewUnitController.SLOT0); }
public void PlayAnimation(string id, bool loop, float interpTime, float startTime = 0.0f) { if ((double)interpTime <= 0.0) { this.StopAll(); } if (!this.mLoadedAnimations.ContainsKey(id)) { DebugUtility.LogError("Unknown animation ID: " + id); } else { AnimDef mLoadedAnimation = this.mLoadedAnimations[id]; if (Object.op_Equality((Object)mLoadedAnimation, (Object)null) || Object.op_Equality((Object)mLoadedAnimation.animation, (Object)null)) { DebugUtility.LogError("Animation not loaded: " + id); } else { AnimationPlayer.AnimationStateSource animationStateSource = (AnimationPlayer.AnimationStateSource)null; for (int index = 0; index < this.mAnimationStates.Count; ++index) { if (this.mAnimationStates[index].Name == id) { animationStateSource = this.mAnimationStates[index]; break; } } if (animationStateSource == null) { animationStateSource = new AnimationPlayer.AnimationStateSource(); animationStateSource.Clip = mLoadedAnimation; this.mAnimationStates.Add(animationStateSource); } animationStateSource.Time = startTime; animationStateSource.Name = id; animationStateSource.WrapMode = !loop ? (WrapMode)0 : (WrapMode)2; if ((double)interpTime > 0.0) { animationStateSource.Weight = 0.0f; animationStateSource.DesiredWeight = 1f; animationStateSource.BlendRate = 1f / interpTime; for (int index = 0; index < this.mAnimationStates.Count; ++index) { if (this.mAnimationStates[index] != animationStateSource) { this.mAnimationStates[index].DesiredWeight = 0.0f; this.mAnimationStates[index].BlendRate = animationStateSource.BlendRate; } } } else { animationStateSource.Weight = 1f; animationStateSource.DesiredWeight = 1f; } } } }
public float GetLength(string id) { AnimDef animation = this.FindAnimation(id); if (Object.op_Equality((Object)animation, (Object)null)) { return(0.0f); } return(animation.Length); }
private void ProcessAnimationEvents() { for (int index1 = 0; index1 < this.mAnimationStates.Count; ++index1) { AnimationPlayer.AnimationStateSource mAnimationState = this.mAnimationStates[index1]; AnimDef clip = mAnimationState.Clip; float length = clip.Length; if ((double)mAnimationState.Weight > 0.0 && clip.events != null) { for (int index2 = 0; index2 < clip.events.Length; ++index2) { AnimEvent e = clip.events[index2]; if (!Object.op_Equality((Object)e, (Object)null) && this.IsEventAllowed(e)) { float num1 = Mathf.Min(e.Start, length); float num2 = Mathf.Min(e.End, length); float num3 = mAnimationState.WrapMode != 2 || (double)mAnimationState.Time >= (double)mAnimationState.TimeOld ? mAnimationState.TimeOld : mAnimationState.TimeOld - length; if ((double)num1 < (double)length) { if ((double)num3 <= (double)num1 && (double)num1 < (double)mAnimationState.Time) { this.OnEventStart(e, mAnimationState.Weight); e.OnStart(((Component)this).get_gameObject()); } } else if ((double)num3 < (double)num1 && (double)num1 <= (double)mAnimationState.Time) { this.OnEventStart(e, mAnimationState.Weight); e.OnStart(((Component)this).get_gameObject()); } if ((double)num1 <= (double)mAnimationState.Time && (double)mAnimationState.Time < (double)num2) { float num4 = e.End - e.Start; this.OnEvent(e, mAnimationState.Time, mAnimationState.Weight); e.OnTick(((Component)this).get_gameObject(), (double)num4 <= 0.0 ? 0.0f : (mAnimationState.Time - e.Start) / num4); } if ((double)num2 < (double)length) { if ((double)num3 <= (double)num2 && (double)num2 < (double)mAnimationState.Time) { this.OnEventEnd(e, mAnimationState.Weight); e.OnEnd(((Component)this).get_gameObject()); } } else if ((double)num3 < (double)num2 && (double)num2 <= (double)mAnimationState.Time) { this.OnEventEnd(e, mAnimationState.Weight); e.OnEnd(((Component)this).get_gameObject()); } } } } } }
protected AnimDef FindAnimation(string id) { if (!this.mLoadedAnimations.ContainsKey(id)) { return((AnimDef)null); } AnimDef mLoadedAnimation = this.mLoadedAnimations[id]; if (Object.op_Equality((Object)mLoadedAnimation, (Object)null) || Object.op_Equality((Object)mLoadedAnimation.animation, (Object)null)) { return((AnimDef)null); } return(mLoadedAnimation); }
public AnimDef LoadAnimDef(string directory) { var animDef = AnimDef.LoadAnimDef(directory); if (animDef != null && animDef.kanims.Length > 0) { animDefs.Add(animDef); currentKanim = animDef.kanims[0]; frameIdx = 0; frameProgress = -1; updateFrame = true; } return(animDef); }
private void UpdateFaceAnimation() { if (Object.op_Equality((Object)this.mFaceAnimation, (Object)null)) { return; } if (this.mPlayingFaceAnimation) { this.mFaceAnimation.PlayAnimation = true; this.mPlayingFaceAnimation = false; if (this.mFaceAnimation.Animation0.Curve == null) { this.mFaceAnimation.Face0 = 0; } if (this.mFaceAnimation.Animation1.Curve == null) { this.mFaceAnimation.Face1 = 0; } } float position; AnimDef activeAnimation = this.GetActiveAnimation(out position); if (!Object.op_Inequality((Object)activeAnimation, (Object)null)) { return; } AnimationCurve customCurve1 = activeAnimation.FindCustomCurve("FAC0"); if (customCurve1 != null) { this.mFaceAnimation.Face0 = Mathf.FloorToInt(customCurve1.Evaluate(position)) - 1; this.mPlayingFaceAnimation = true; } AnimationCurve customCurve2 = activeAnimation.FindCustomCurve("FAC1"); if (customCurve2 != null) { this.mFaceAnimation.Face1 = Mathf.FloorToInt(customCurve2.Evaluate(position)) - 1; this.mPlayingFaceAnimation = true; } if (!this.mPlayingFaceAnimation) { return; } this.mFaceAnimation.PlayAnimation = false; }
public static AnimDef LoadAnimDef(string directory) { var fullFileName = directory + Path.DirectorySeparatorChar + "animation.xml"; if (File.Exists(fullFileName)) { var animDef = new AnimDef(); animDef.InitWatcher(directory); if (LoadAnimDef(animDef, directory) != null) { // Begin watching. animDef.watcher.EnableRaisingEvents = true; return(animDef); } } return(null); }
public static AnimDef LoadAnimDef(AnimDef animDef, string directory) { var fullFileName = directory + Path.DirectorySeparatorChar + "animation.xml"; if (File.Exists(fullFileName)) { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; settings.IgnoreProcessingInstructions = true; XmlReader reader = XmlReader.Create(fullFileName, settings); XmlDocument anim = new XmlDocument(); anim.Load(reader); animDef.kanims = new Kanim[anim.DocumentElement.ChildNodes.Count]; int aIdx = 0; foreach (XmlNode animXml in anim.DocumentElement.ChildNodes) { var kanim = new Kanim(); kanim.name = animXml.Attributes.GetNamedItem("name").InnerText; kanim.frames = new Kanim.Frame[animXml.ChildNodes.Count]; animDef.kanims[aIdx] = kanim; aIdx++; int i = 0; foreach (XmlNode frame in animXml.ChildNodes) { var frameObj = new Kanim.Frame(); kanim.frames[i] = frameObj; frameObj.elements = new Kanim.Frame.Element[frame.ChildNodes.Count]; i++; int j = 0; foreach (XmlNode element in frame.ChildNodes) { var elem = new Kanim.Frame.Element(); frameObj.elements[j] = elem; j++; elem.name = element.Attributes.GetNamedItem("name").InnerText; elem.frame = int.Parse(element.Attributes.GetNamedItem("frame").InnerText); // Parent Transform var p_a = float.Parse(element.Attributes.GetNamedItem("m0_a").InnerText, CultureInfo.InvariantCulture); var p_b = float.Parse(element.Attributes.GetNamedItem("m0_b").InnerText, CultureInfo.InvariantCulture); var p_c = float.Parse(element.Attributes.GetNamedItem("m0_c").InnerText, CultureInfo.InvariantCulture); var p_d = float.Parse(element.Attributes.GetNamedItem("m0_d").InnerText, CultureInfo.InvariantCulture); var p_tx = float.Parse(element.Attributes.GetNamedItem("m0_tx").InnerText, CultureInfo.InvariantCulture); var p_ty = float.Parse(element.Attributes.GetNamedItem("m0_ty").InnerText, CultureInfo.InvariantCulture); // Child Transform var c_a = float.Parse(element.Attributes.GetNamedItem("m1_a").InnerText, CultureInfo.InvariantCulture); var c_b = float.Parse(element.Attributes.GetNamedItem("m1_b").InnerText, CultureInfo.InvariantCulture); var c_c = float.Parse(element.Attributes.GetNamedItem("m1_c").InnerText, CultureInfo.InvariantCulture); var c_d = float.Parse(element.Attributes.GetNamedItem("m1_d").InnerText, CultureInfo.InvariantCulture); var c_tx = float.Parse(element.Attributes.GetNamedItem("m1_tx").InnerText, CultureInfo.InvariantCulture); var c_ty = float.Parse(element.Attributes.GetNamedItem("m1_ty").InnerText, CultureInfo.InvariantCulture); // P * C elem.a = p_a * c_a + p_c * c_b; elem.b = p_b * c_a + p_d * c_b; elem.c = p_a * c_c + p_c * c_d; elem.d = p_b * c_c + p_d * c_d; elem.tx = p_a * c_tx + p_c * c_ty + p_tx; elem.ty = p_b * c_tx + p_d * c_ty + p_ty; var r = float.Parse(element.Attributes.GetNamedItem("c_00").InnerText, CultureInfo.InvariantCulture); var g = float.Parse(element.Attributes.GetNamedItem("c_11").InnerText, CultureInfo.InvariantCulture); var b = float.Parse(element.Attributes.GetNamedItem("c_22").InnerText, CultureInfo.InvariantCulture); var alpha = float.Parse(element.Attributes.GetNamedItem("c_33").InnerText, CultureInfo.InvariantCulture); elem.colorMult = new Color(r, g, b, alpha); var rAdd = float.Parse(element.Attributes.GetNamedItem("c_04").InnerText, CultureInfo.InvariantCulture); var gAdd = float.Parse(element.Attributes.GetNamedItem("c_14").InnerText, CultureInfo.InvariantCulture); var bAdd = float.Parse(element.Attributes.GetNamedItem("c_24").InnerText, CultureInfo.InvariantCulture); var aAdd = float.Parse(element.Attributes.GetNamedItem("c_34").InnerText, CultureInfo.InvariantCulture); elem.colorAdd = new Color(rAdd, gAdd, bAdd, aAdd); } } } return(animDef); } return(null); }
public static AnimDef Clone(AnimDef animDef) { return(new AnimDef(animDef.CellXstartIndex, animDef.CellYstartIndex, animDef.FramesPerRotation, animDef.AnimName)); }
public void AddAnimation(string id, AnimDef anim) { this.mLoadedAnimations[id] = anim; }
protected void UpdateAnimationStates(float dt, bool forceUpdate) { if (Object.op_Equality((Object)this.mAnimation, (Object)null) || this.mDetectedInifiteLoop) { return; } if ((double)dt > 0.0) { this.mResampleTimer += dt; } Vector3 vector3 = Vector3.get_zero(); Transform transform1 = ((Component)this).get_transform(); Vector3 zero = Vector3.get_zero(); int num1 = 0; bool flag; do { flag = false; ++num1; if (num1 > 100) { Debug.LogError((object)(((Object)this).get_name() + " >>> INFINITE LOOP DETECTED!!!")); this.mDetectedInifiteLoop = true; IEnumerator enumerator = this.mAnimation.GetEnumerator(); try { while (enumerator.MoveNext()) { AnimationState current = (AnimationState)enumerator.Current; Debug.LogError((object)string.Format("CLIP name:{0} clip:{1} clipname:{2} clipInstance:{3}", new object[4] { (object)current.get_name(), (object)current.get_clip(), (object)((Object)current.get_clip()).get_name(), (object)((Object)current.get_clip()).GetInstanceID() })); } return; } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { IEnumerator enumerator = this.mAnimation.GetEnumerator(); try { if (enumerator.MoveNext()) { AnimationState current = (AnimationState)enumerator.Current; flag = true; this.mAnimation.RemoveClip(current.get_clip()); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } }while (flag); float mResampleTimer = this.mResampleTimer; this.mResampleTimer = 0.0f; float num2 = 0.0f; for (int index = 0; index < this.mAnimationStates.Count; ++index) { AnimationPlayer.AnimationStateSource mAnimationState = this.mAnimationStates[index]; mAnimationState.Weight = Mathf.MoveTowards(mAnimationState.Weight, mAnimationState.DesiredWeight, mAnimationState.BlendRate * mResampleTimer); num2 += mAnimationState.Weight; } for (int index = 0; index < this.mAnimationStates.Count; ++index) { AnimationPlayer.AnimationStateSource mAnimationState = this.mAnimationStates[index]; AnimDef clip = mAnimationState.Clip; float length = clip.Length; if ((double)mAnimationState.Weight <= 0.0 && (double)mAnimationState.DesiredWeight <= 0.0) { this.mAnimationStates.RemoveAt(index); --index; } else { float time = mAnimationState.Time; mAnimationState.TimeOld = time; mAnimationState.Time += mResampleTimer * mAnimationState.Speed; float num3 = mAnimationState.Weight / num2; if (mAnimationState.WrapMode == 2) { mAnimationState.Time %= length; } else if ((double)mAnimationState.Time > (double)length) { mAnimationState.Time = length; } if (clip.UseRootMotion && this.mRootMotionMode == AnimationPlayer.RootMotionModes.Velocity && this.RootMotionBoneName == clip.rootBoneName) { if (clip.rootTranslationX != null) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local1 = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local1).x = (__Null)((^ local1).x + (double)this.EvaluateCurveValue(clip.rootTranslationX, time, mAnimationState.Time, length) * (double)num3); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local2 = @zero; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local2).x = (__Null)((^ local2).x - (double)clip.rootTranslationX.Evaluate(mAnimationState.Time) * (double)num3); } if (clip.rootTranslationY != null) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local1 = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local1).y = (__Null)((^ local1).y + (double)this.EvaluateCurveValue(clip.rootTranslationY, time, mAnimationState.Time, length) * (double)num3); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local2 = @zero; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local2).y = (__Null)((^ local2).y - (double)clip.rootTranslationY.Evaluate(mAnimationState.Time) * (double)num3); } if (clip.rootTranslationZ != null) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local1 = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local1).z = (__Null)((^ local1).z + (double)this.EvaluateCurveValue(clip.rootTranslationZ, time, mAnimationState.Time, length) * (double)num3); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local2 = @zero; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local2).z = (__Null)((^ local2).z - (double)clip.rootTranslationZ.Evaluate(mAnimationState.Time) * (double)num3); } } string name = ((Object)mAnimationState.Clip.animation).get_name(); ((Object)mAnimationState.Clip.animation).set_name(mAnimationState.Name); this.mAnimation.AddClip(mAnimationState.Clip.animation, mAnimationState.Name); AnimationState animationState = this.mAnimation.get_Item(mAnimationState.Name); animationState.set_name(animationState.get_name()); animationState.set_time(mAnimationState.Time); animationState.set_weight(mAnimationState.Weight); animationState.set_enabled(true); mAnimationState.CopiedStateRef = animationState; ((Object)mAnimationState.Clip.animation).set_name(name); } } if (this.mAnimationStates.Count > 0) { this.mAnimation.Sample(); for (int index = 0; index < this.mAnimationStates.Count; ++index) { this.mAnimationStates[index].CopiedStateRef.set_enabled(false); } if (this.OnAnimationUpdate != null) { this.OnAnimationUpdate(((Component)this).get_gameObject()); } } this.RootMotionInverse = Vector3.get_zero(); if (this.mRootMotionMode == AnimationPlayer.RootMotionModes.Velocity) { // ISSUE: explicit reference operation if ((double)((Vector3)@vector3).get_sqrMagnitude() > 0.0) { vector3 = Vector3.op_Multiply(vector3, this.RootMotionScale); if ((double)Mathf.Sign((float)transform1.get_lossyScale().x) < 0.0) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local).x = (__Null)((^ local).x * -1.0); } if ((double)Mathf.Sign((float)transform1.get_lossyScale().z) < 0.0) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local).z = (__Null)((^ local).z * -1.0); } vector3.y = (__Null)0.0; Transform transform2 = transform1; transform2.set_position(Vector3.op_Addition(transform2.get_position(), Quaternion.op_Multiply(transform1.get_rotation(), vector3))); } Transform childRecursively = GameUtility.findChildRecursively(transform1, this.RootMotionBoneName); if (Object.op_Inequality((Object)childRecursively, (Object)null)) { Transform transform2 = childRecursively; transform2.set_localPosition(Vector3.op_Addition(transform2.get_localPosition(), zero)); this.RootMotionInverse = Quaternion.op_Multiply(childRecursively.get_parent().get_rotation(), zero); } } else if (this.mRootMotionMode == AnimationPlayer.RootMotionModes.Discard) { Transform childRecursively = GameUtility.findChildRecursively(transform1, this.RootMotionBoneName); if (Object.op_Inequality((Object)childRecursively, (Object)null)) { childRecursively.set_localPosition(new Vector3(0.0f, (float)childRecursively.get_localPosition().y, 0.0f)); } } this.ProcessAnimationEvents(); }
// Update is called once per frame void Update() { idxTxt.text = "Frame Idx: " + kanim.GetFrameIdx(); rateTxt.text = "Frames Per Second: " + kanim.frameRate; idxSlider.maxValue = kanim.GetAnimLength() - 1; idxSlider.value = kanim.GetFrameIdx(); if (Input.GetMouseButtonDown(0) && !eventSystem.IsPointerOverGameObject()) { dragging = true; lastMousePosition = Input.mousePosition; } else if (!Input.GetMouseButton(0)) { dragging = false; } else if (dragging) { Vector3 mousePos = Input.mousePosition; Vector3 delta = lastMousePosition - mousePos; orthoCamera.transform.position += 2 * delta * orthoCamera.orthographicSize / Screen.height; lastMousePosition = mousePos; } float scroll = Input.mouseScrollDelta.y; if (scroll != 0) { float oldSize = orthoCamera.orthographicSize; float targetX = Input.mousePosition.x / Screen.height - 0.5f * orthoCamera.aspect; float targetY = Input.mousePosition.y / Screen.height - 0.5f; zoomSlider.value = Mathf.Clamp(zoomSlider.value + scroll, zoomSlider.minValue, zoomSlider.maxValue); ZoomChanged(zoomSlider.value); float newX = targetX * oldSize / orthoCamera.orthographicSize; float newY = targetY * oldSize / orthoCamera.orthographicSize; orthoCamera.transform.position += new Vector3(newX - targetX, newY - targetY) * 2 * orthoCamera.orthographicSize; } if (updatedAnimDef != null) { List <Dropdown.OptionData> options = dropdown.options; int i = dropdown.value; int j = 0; modifyingDropDown = true; var currentOption = options[i].text; foreach (var file in listedFiles) { if (file.kanims != null) { if (file.animDef == updatedAnimDef) { kanim.SetCurrentKanim(file.kanims[i]); } if (i < file.kanims.Length) { if (file.animDef == updatedAnimDef) { options.RemoveRange(j, file.kanims.Length); for (int k = file.animDef.kanims.Length - 1; k >= 0; k--) { options.Insert(j, new Dropdown.OptionData(file.animDef.kanims[k].name)); } file.kanims = file.animDef.kanims; if (i < file.kanims.Length) { kanim.SetCurrentKanim(file.kanims[i]); j += i; } else if (file.kanims.Length > 0) { kanim.SetCurrentKanim(file.kanims[0]); } break; } } else { i -= file.kanims.Length; j += file.kanims.Length; } } } dropdown.options = options; dropdown.value = j; updatedAnimDef = null; modifyingDropDown = false; } }
public void RemoveAnimDef(AnimDef anim) { updateFrame = true; animDefs.Remove(anim); anim.Dispose(); }