public FGAnimationKeyFrame LoopAnimationPlay(FGAnimation animation, double dt) { bool reset = animatorTimer >= animation.duration; if (reset) { animatorTimer -= animation.duration; } float adjustedTime = (float)animatorTimer; if (animation.type == FGAnimationType.REVERSE) { adjustedTime = animation.duration - adjustedTime; } currentFrame = AnimationPlayer.GetCurrentFrame(animation, adjustedTime); FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame); animatorTimer += dt; if (keyFrame != null) { ApplyFrame(keyFrame); } if (_currentKeyFrame != null) { return(_currentKeyFrame); } return(animation.frames[0]); }
void ShowAnimationPreview() { FGAnimation data = (FGAnimation)target; if (data.frames.Length > 0) { if (spriteToShow != null) { if (spriteToShow.type == FGAnimationStageType.ACTIVE) { Texture2D sprite = GenerateTextureFromSprite(spriteToShow.sprite); AddRectToTexture(ref sprite, spriteToShow.hitBox, Color.red); GUILayout.Label(sprite); } else { GUILayout.Label(GenerateTextureFromSprite(spriteToShow.sprite)); } } } if (play) { if (GUILayout.Button("Stop")) { play = false; if (anim != null) { anim.Reset(); } } } else { if (GUILayout.Button("Play")) { play = true; if (anim != null) { anim.Reset(); } } if (GUILayout.Button("Move To Next Frame")) { anim.NextFrame((FGAnimation)target); spriteToShow = anim.GetCurrent(); } if (GUILayout.Button("Back To Last Frame")) { anim.LastFrame((FGAnimation)target); spriteToShow = anim.GetCurrent(); } } if (anim != null) { GUILayout.Label(new GUIContent("Frame number: " + anim.GetCurrentFrame().ToString())); } }
//! public void AddFrame(FGAnimationKeyFrame frame) { FGAnimHelper.AddFrame(ref frames); frames[frames.Length - 1] = frame; for (int i = 0; i < frame.frameCount; i++) { _frameToKeyFrame.Add(frames.Length - 1); } totalFrameCount += frame.frameCount; }
void OnEnable() { EditorAnimator anim = new EditorAnimator(); FGAnimation data = (FGAnimation)target; play = false; _time = EditorApplication.timeSinceStartup; if (data.frames.Length > 0) { spriteToShow = data.frames[0]; } EditorApplication.update += Update; }
//! public void UpdateAnimator(float dt) { bool reset = _animatorTime >= _animations[_currentAnimation].duration; bool bounceAnimationReverse = false; //check what type of animation we're dealing with switch (_animations[_currentAnimation].type) { case FGAnimationType.BOUNCE: case FGAnimationType.LOOP: if (reset) { _animatorTime -= _animations[_currentAnimation].duration; } break; case FGAnimationType.REVERSE: case FGAnimationType.ONCE: if (reset) { if (_animations[_currentAnimation].nextAnimation != "") { Play(_animations[_currentAnimation].nextAnimation); } else { Play(_defaultAnimation); } } break; } FGAnimation current = _animations[_currentAnimation]; float adjustedTime = _animatorTime; if (current.type == FGAnimationType.REVERSE) { adjustedTime = current.duration - adjustedTime; } int currFrame = AnimationPlayer.GetCurrentFrame(_animations[_currentAnimation], adjustedTime); FGAnimationKeyFrame keyFrame = _animations[_currentAnimation].GetKeyFrame(currFrame); if (_currentKeyFrame != keyFrame) { ApplyFrame(keyFrame); } //at end of update, update animator's time _animatorTime += dt; }
public void LastFrame(FGAnimation animation) { if ((currentFrame - 1) < 0) { currentFrame = animation.totalFrameCount - 1; } else { currentFrame--; } FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame); ApplyFrame(keyFrame); }
public void NextFrame(FGAnimation animation) { if (animation.totalFrameCount == (currentFrame + 1)) { currentFrame = 0; } else { currentFrame++; } FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame); ApplyFrame(keyFrame); }
private void Awake() { if (anim == null) { anim = new EditorAnimator(); } FGAnimation data = (FGAnimation)target; play = false; _time = EditorApplication.timeSinceStartup; if (data.frames.Length > 0) { spriteToShow = data.frames[0]; } }
private void ApplyFrame(FGAnimationKeyFrame frame) { _mainLayer.sprite = frame.sprite; _currentStage = frame.type; _currentKeyFrame = frame; /*if (frame.type == FGAnimationStageType.ACTIVE) * { * hitBoxActive = true; * _activeHitBox = new Rect(frame.hitBox.position + _currentOffset, frame.hitBox.size); * } * else * { * hitBoxActive = false; * }*/ }
public static void AddFrame(ref FGAnimationKeyFrame[] frameList) { if (frameList == null) { frameList = new FGAnimationKeyFrame[1]; } else { FGAnimationKeyFrame[] cpy = new FGAnimationKeyFrame[frameList.Length + 1]; for (int i = 0; i < frameList.Length; i++) { cpy[i] = frameList[i]; } frameList = cpy; } frameList[frameList.Length - 1] = new FGAnimationKeyFrame(); }
void Update() { if (play) { double currTime = EditorApplication.timeSinceStartup; if ((currTime - _time) >= FGAnimationKeyFrame.FrameTime * 2) { if (anim == null) { anim = new EditorAnimator(); } spriteToShow = anim.LoopAnimationPlay((FGAnimation)target, (currTime - _time)); //call animator update here _time = currTime; Repaint(); } } }
public static void RemoveFrame(ref FGAnimationKeyFrame[] frameList, int index) { if (frameList != null && index < frameList.Length) { FGAnimationKeyFrame[] cpy = new FGAnimationKeyFrame[frameList.Length - 1]; for (int i = 0; i < frameList.Length; i++) { if (i < index) { cpy[i] = frameList[i]; } else if (i > index) { cpy[i - 1] = frameList[i]; } } frameList = cpy; } }
//! public void Play(string animationName) { if (_animations.ContainsKey(animationName) && animationName != _currentAnimation) { if (_animations[animationName].type == FGAnimationType.ONCE) { _currentState = AnimatorState.IN_ATTACK; _currentStage = FGAnimationStageType.STARTUP; } else { _currentState = AnimatorState.FREE; } for (int i = 0; i < _layerRenderers.Length; i++) { Vector2 rendererPosition = _layerRenderers[i].rectTransform.anchoredPosition; //_layerRenderers[i].rectTransform.anchoredPosition = rendererPosition + (_animations[animationName].positionOffset - _currentOffset); if (_reversed) { _layerRenderers[i].rectTransform.localScale = new Vector3(-1, 1, 1); _layerRenderers[i].rectTransform.anchoredPosition = _animations[animationName].imageOffset * _layerRenderers[i].rectTransform.localScale; } else { _layerRenderers[i].rectTransform.localScale = new Vector3(1, 1, 1); _layerRenderers[i].rectTransform.anchoredPosition = _animations[animationName].imageOffset; } _layerRenderers[i].rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _animations[animationName].imageSize.x); _layerRenderers[i].rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _animations[animationName].imageSize.y); } _currentOffset = _animations[animationName].imageOffset - _originalOffset; _currentKeyFrame = null; _animatorTime = 0; _currentAnimation = animationName; } }
private void ApplyFrame(FGAnimationKeyFrame frame) { _currentKeyFrame = frame; }
public EditorAnimator() { animatorTimer = 0; _currentKeyFrame = null; }
public FGAnimation() { frames = new FGAnimationKeyFrame[0]; //positionOffset = Vector2.zero; }