public AnimationSequence(string name, AnimationStep[] steps, Vector2 size, Vector2 offset, int vertex_buffer, AnimationDirections direction = AnimationDirections.All) { Name = name; Steps = steps; Direction = direction; _stepat = 0; Size = size; Offset = offset; _vertbuffer = vertex_buffer; }
public void UseSequence(string sequence_name, AnimationDirections direction) { for (int i = 0; i < Sequences.Length; ++i) { if (Sequences[i].Direction == direction && Sequences[i].Name == sequence_name) { _atsequence = i; break; } } }
private void PlayAnimation(AnimationDirections direction) { isDirty = true; if (animationCoroutine != null) { StopCoroutine(animationCoroutine); } animationCoroutine = StartCoroutine(AnimateButton(direction)); }
public void Update(double delta_time) { if (isanimated && !Physics.IsSleeping()) { var pos = GetPosition() - lastposition; if (pos.LengthSquared() >= 0.01f) { lastposition = GetPosition(); pos.Normalize(); var dir = pos.CalcDirection(); if (dir != lastdirection) { ((Animation)Image).UseSequence("idle", dir); lastdirection = dir; } } } if (IsMoving) { var pos = GetPosition(); var dif = TargetPosition - pos.CreateVector2(); var len = dif.LengthFast; if (len > 0.01) { var scale = Speed; // * (float)delta_time; if (len > scale * (float)delta_time) { dif.NormalizeFast(); dif *= scale; } else { dif /= (float)delta_time; } Physics.SetLinearVelocity(dif.CreateVec2()); //Position += dif; } else { IsMoving = false; if (!Collides) { Physics.SetLinearVelocity(Vec2.Zero); } } } }
private IEnumerator AnimateButton(AnimationDirections direction) { float start, end; switch (direction) { case AnimationDirections.ScaleUp: start = shrinkScale; end = initialScale; break; case AnimationDirections.ScaleDown: start = initialScale; end = shrinkScale; break; default: start = shrinkScale; end = initialScale; break; } elapsedTime = 0; float newScale = start; while (elapsedTime <= 1) { newScale = Mathf.Lerp(start, end, elapsedTime); animationTarget.localScale = newScale * Vector3.one; yield return(null); elapsedTime += animationSpeed * Time.deltaTime; } //The complete animation cycle has ended (scale down -> up) if (direction == AnimationDirections.ScaleUp) { isDirty = false; } animationCoroutine = null; }
/// <summary> /// Instantiates a new AnimationSet with a list of animations and initial state and direction /// </summary> /// <param name="animations"></param> /// <param name="initialState"></param> /// <param name="initialDirection"></param> public AnimationSet(List <Animation> animations, AnimationStates initialState, AnimationDirections initialDirection) { Animations = animations; AnimationState = initialState; AnimationDirection = initialDirection; }
private void GenerateRandomAnimation(float startTimeForSlice, float returnKeyTime, Vector2 startPosition, Transform slice, AnimationClip clip, bool reveal, AnimationDirections animationDirection) { if (animationDirection == AnimationDirections.Both || animationDirection == AnimationDirections.Horizontal) { GenerateRandomXAnimation(startTimeForSlice, returnKeyTime, startPosition.x, slice, clip, reveal); } if (animationDirection == AnimationDirections.Both || animationDirection == AnimationDirections.Vertical) { GenerateRandomYAnimation(startTimeForSlice, returnKeyTime, startPosition.y, slice, clip, reveal); } }