public AnimationTransform GetCurrentMotion()
        {
            var motion = new AnimationTransform();


            if (loaderSequence.hasMovement() && loaderSequence.positions.Count > positionKeyFrameId + 1)
            {
                motion.currentPosition = loaderSequence.positions[positionKeyFrameId];
                motion.nextPosition    = loaderSequence.positions[positionKeyFrameId + 1];
            }

            if (loaderSequence.hasRotation() && loaderSequence.rotations.Count > rotationKeyFrameId + 1)
            {
                motion.currentRotation = new Quaternion(loaderSequence.rotations[rotationKeyFrameId].y,
                                                        loaderSequence.rotations[rotationKeyFrameId].z,
                                                        loaderSequence.rotations[rotationKeyFrameId].w,
                                                        -1 * loaderSequence.rotations[rotationKeyFrameId].x);

                motion.nextRotation = new Quaternion(loaderSequence.rotations[rotationKeyFrameId + 1].y,
                                                     loaderSequence.rotations[rotationKeyFrameId + 1].z,
                                                     loaderSequence.rotations[rotationKeyFrameId + 1].w,
                                                     -1 * loaderSequence.rotations[rotationKeyFrameId + 1].x);
            }

            if (loaderSequence.hasScale() && loaderSequence.scales.Count > scaleKeyFrameId + 1)
            {
                motion.currentScale = loaderSequence.scales[scaleKeyFrameId];
                motion.nextScale    = loaderSequence.scales[scaleKeyFrameId + 1];
            }

            return(motion);
        }
    public void Play(string stateName)
    {
        LastPlay = stateName;

        if (anim != null && anim.runtimeAnimatorController != null)
        {
//			Debug.Log ("playing " + stateName);
            anim.Play(stateName);
        }
        else
        {
//			Debug.Log ("no animator on " + name);
        }

        //check to see if any children have animation transforms, and call closest animator on them as well.
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform          child = transform.GetChild(i);
            AnimationTransform at    = child.GetComponent <AnimationTransform> ();
            if (at != null)
            {
                at.Play(stateName);
            }
        }
    }
    public Animator ClosestAnimator()
    {
        if (anim != null)
        {
            return(anim);
        }

        //check to see if any children have animators.  return in you find one
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child = transform.GetChild(i);
            Animator  a     = child.GetComponent <Animator> ();
            if (a != null)
            {
                return(a);
            }
        }

        //check to see if any children have animation transforms, and call closest animator on them as well.
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform          child = transform.GetChild(i);
            AnimationTransform at    = child.GetComponent <AnimationTransform> ();
            if (at != null)
            {
                Animator a = at.ClosestAnimator();
                if (a != null)
                {
                    return(a);
                }
            }
        }

        return(null);
    }
Beispiel #4
0
        protected AnimationTransform ApplyBoneTransforms(MainlineKey p_main, Reference p_reference)
        {
            if ((p_reference.BoneId >= 0) && m_boneTransforms.ContainsKey(p_reference.BoneId))
            {
                return(m_boneTransforms[p_reference.BoneId]);
            }

            AnimationTransform l_baseTransform;

            if ((p_reference.Parent != -1))
            {
                l_baseTransform = ApplyBoneTransforms(p_main, p_main.Bones[p_reference.Parent]);
            }
            else
            {
                //Apply global transforms to objects without parents (location is added later)
                l_baseTransform = new AnimationTransform(Vector2.Zero, Rotation, Vector2.Zero, new Vector2(Math.Abs(Scale)));
            }
            AnimationTransform l_transform = ApplyTransform(GetFrameTransition(p_reference), l_baseTransform);

            if (p_reference.BoneId >= 0)
            {
                m_boneTransforms.Add(p_reference.BoneId, l_transform);
            }

            return(l_transform);
        }
Beispiel #5
0
        private void CombineAnimationContent(AnimationNodeContent c1, AnimationNodeContent c2)
        {
            if (c1 == null || c2 == null)
            {
                return;
            }
            AnimationFrame empty = new AnimationFrame();

            empty.Transform = new AnimationTransform("", new Vector3(), new Vector3(1), new Quaternion(0, 0, 0, 1));
            for (int i = 0; i < Math.Max(c1.Frames.Count, c2.Frames.Count); i++)
            {
                AnimationFrame f1 = i < c1.Frames.Count?c1.Frames[i]:empty;
                AnimationFrame f2 = i < c2.Frames.Count?c2.Frames[i]:empty;
                if (f1 == empty)
                {
                    c1.Frames.Add(f2);
                }
                else
                {
                    AnimationTransform t1 = f1.Transform;
                    AnimationTransform t2 = f2.Transform;
                    f1.Transform = t1 + t2;
                }
            }
        }
    void Awake()
    {
        animationTransform   = GetComponent <AnimationTransform> ();
        tileMovement         = GetComponent <TileMovement> ();
        characterAudioSource = GetComponent <AudioSource>();

        animationTransform.OnAnimationEvent += HandleAnimationEvent;
    }
 void Awake()
 {
     rootAnimationTransform = GetComponent <AnimationTransform> ();
     root = rootAnimationTransform.ClosestAnimator();
     foreach (EquipmentAnimatorMapping anim in animators)
     {
         anim.current = EquipmentAnimationControllerName.NOT_SET;
     }
 }
    // Use this for initialization
    void Start()
    {
        animationTransform = GetComponent <AnimationTransform> ();
        rootBody           = animationTransform.ClosestAnimator();
        animationTransform.OnAnimationEvent += AnimationEventHappened;

        //animationTransform.SetTrigger ("walkDown");
        //rootBody.speed = 0f;
    }
    void Awake()
    {
        animationTransform = GetComponent <AnimationTransform> ();
        infoHook           = animationTransform.ClosestAnimator();

        currentPath = new List <string> ();
        RoundPositionToNearestWhole();

        animationTransform.OnAnimationEvent += AnimationEventHappened;
    }
 public void OnEachChild(PerformOnChildren action)
 {
     for (int i = 0; i < transform.childCount; i++)
     {
         Transform          child = transform.GetChild(i);
         AnimationTransform at    = child.GetComponent <AnimationTransform> ();
         if (at != null)
         {
             action(at);
         }
     }
 }
Beispiel #11
0
            public RenderMatrix(AnimationTransform p_at)
            {
                Alpha    = p_at.Alpha;
                Location = p_at.Location;
                Rotation = p_at.Rotation;
                Pivot    = p_at.Pivot;
                Scale    = p_at.Scale;

                Effects = SpriteEffects.None;
                File    = 0;
                Folder  = 0;
                ZOrder  = 0;
            }
Beispiel #12
0
        public void CalculateCombinedTransforms()
        {
            //UpdateCachedValues();

            AnimationTransform.Decompose(out FScale, out FRotation, out FTranslation);

            if (Parent != null)
            {
                FCombinedTransform = AnimationTransform * BaseTransform * Parent.CombinedTransform;
            }
            else
            {
                FCombinedTransform = AnimationTransform * BaseTransform;
            }
        }
Beispiel #13
0
 private void UpdateCachedValues()
 {
     if (IsDirty())
     {
         AnimationTransform.Decompose(out FCachedScale, out FCachedRotation, out FCachedTranslation);
         if (Parent != null)
         {
             FCachedCombinedTransform = AnimationTransform * BaseTransform * Parent.CombinedTransform;
         }
         else
         {
             FCachedCombinedTransform = AnimationTransform * BaseTransform;
         }
         FDirty = false;
     }
 }
Beispiel #14
0
        protected AnimationTransform ApplyTransform(AnimationTransform p_transform, AnimationTransform p_baseTransform)
        {
            //  Create a tranformation matrix so we can find out the location of the bone \ body
            Matrix l_matrix = Matrix.CreateScale(p_baseTransform.Scale.X, p_baseTransform.Scale.Y, 0) *
                              Matrix.CreateRotationZ(p_baseTransform.Rotation) *
                              Matrix.CreateTranslation(p_baseTransform.Location.X, p_baseTransform.Location.Y, 0);

            AnimationTransform l_result = new AnimationTransform();

            //  Apply the scaling, rotation and tranform matrix to current structure
            l_result.Scale    = p_transform.Scale * p_baseTransform.Scale;
            l_result.Rotation = p_transform.Rotation + p_baseTransform.Rotation;
            l_result.Location = Vector2.Transform(p_transform.Location, l_matrix);
            l_result.Alpha    = p_transform.Alpha * p_baseTransform.Alpha;
            l_result.Pivot    = p_transform.Pivot;

            return(l_result);
        }
    /// <summary>
    /// Used by all animation events as the function to call from editor settings.
    /// </summary>
    /// <param name="type">Type.</param>
    public void EventFired(AnimationEventType type)
    {
//		if(anim != null)
//			Debug.Log ("event fired by "+ name + ": " + type + "@"+ anim.GetNextAnimatorStateInfo(0).normalizedTime);

        if (OnAnimationEvent != null)
        {
            OnAnimationEvent(type, LastPlay);
        }

        if (transform.parent != null)
        {
            AnimationTransform paren = transform.parent.GetComponent <AnimationTransform> ();

            if (paren != null)
            {
                paren.EventFired(type);
            }
        }
    }
Beispiel #16
0
        void NewData()
        {
            _chart.BeginUpdate();

            AnimationTransform at = (AnimationTransform)_cbTrans.SelectedIndex;
            AnimationOrigin    ao = (AnimationOrigin)_cbOrigin.SelectedIndex;
            Easing             ea = (Easing)_cbEasing.SelectedIndex;

            _chart.Data.LoadAnimation = CreateAnimation(at, ao, _cbDelay.IsChecked == true, ea);

            int nser = _rnd.Next(2, 6);
            int npts = _rnd.Next(5, 10);

            _chart.Data.Children.Clear();
            for (int i = 0; i < nser; i++)
            {
                _chart.Data.Children.Add(ChartSampleData.CreateDataSeries(npts));
            }
            _chart.EndUpdate();
        }
Beispiel #17
0
        public void ApplyAnimation(float time, float maxTime)
        {
            Sort();
            int            frameIndex = Math.Max(Frames.FindIndex(f => f.Frame >= time) - 1, 0);
            AnimationFrame frame      = Frames[frameIndex];
            AnimationFrame nextFrame  = null;

            if (Repeat)
            {
                nextFrame = Frames[(frameIndex + 1) % Frames.Count];
            }
            else if (frameIndex < Frames.Count - 1)
            {
                nextFrame = Frames[frameIndex + 1];
            }
            else
            {
                return;
            }

            float diff      = time - frame.Frame;
            float frameTime = nextFrame.Frame - frame.Frame;

            /*if (diff == 0)
             * {
             *  Node.LocalTransform = frame.Transform.ToMatrix();
             * }
             * else if (diff > 0)*/
            float percent = diff / frameTime;

            if (Node.Name.Contains("$"))
            {
                Console.WriteLine(frameIndex + " - " + percent);
            }
            {
                //Matrix m1 = frame.Transform.ToMatrix();
                //Matrix m2 = nextFrame.Transform.ToMatrix();
                //Node.LocalTransform = Matrix.Lerp(m1,m2,percent);
                Node.LocalTransform = AnimationTransform.Lerp(frame.Transform, nextFrame.Transform, percent).ToMatrix();
            }
        }
        public static PlotElementAnimation CreateAnimation(AnimationTransform transform, AnimationOrigin origin, Easing easing, bool indexDelay)
        {
            var sb = new Storyboard();
              var duration = new Duration(TimeSpan.FromSeconds(0.5));

              var style = new Style();
              style.TargetType = typeof(PlotElement);
              style.Setters.Add(new Setter(PlotElement.OpacityProperty, 0.0));

              if (transform == AnimationTransform.Scale)
            style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new ScaleTransform() { ScaleX = 0, ScaleY = 0 }));
              else if (transform == AnimationTransform.Rotation)
            style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new RotateTransform() { Angle = 180 }));

              var point = new Point(0.5, 0.5);
              switch (origin)
              {
            case AnimationOrigin.Bottom:
              point = new Point(0.5, 2);
              break;
            case AnimationOrigin.Top:
              point = new Point(0.5, -2);
              break;
            case AnimationOrigin.Left:
              point = new Point(-2, 0.5);
              break;
            case AnimationOrigin.Right:
              point = new Point(2, 0.5);
              break;
            case AnimationOrigin.TopLeft:
              point = new Point(2, -2);
              break;
            case AnimationOrigin.TopRight:
              point = new Point(-2, -2);
              break;
            case AnimationOrigin.BottomLeft:
              point = new Point(2, 2);
              break;
            case AnimationOrigin.BottomRight:
              point = new Point(-2, 2);
              break;
            default:
              break;
              }

              style.Setters.Add(new Setter(PlotElement.RenderTransformOriginProperty, point));

              var da = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
              Storyboard.SetTargetProperty(da, new PropertyPath("Opacity"));
              sb.Children.Add(da);

              if (transform == AnimationTransform.Scale)
              {
            var da2 = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
            Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).ScaleX"));

            var da3 = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
            Storyboard.SetTargetProperty(da3, new PropertyPath("(RenderTransform).ScaleY"));

            sb.Children.Add(da2);
            sb.Children.Add(da3);
              }
              else if (transform == AnimationTransform.Rotation)
              {
            var da2 = new DoubleAnimation() { To = 0, Duration = duration };
            Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).Angle"));
            sb.Children.Add(da2);
              }

              if (indexDelay)
              {
            foreach (var anim in sb.Children)
              PlotElementAnimation.SetIndexDelay(anim, 0.5);
              }

            #if CLR40
              if (easing != Easing.None)
              {
            IEasingFunction ef = null;

            switch (easing)
            {
              case Easing.BackEase:
            ef = new BackEase(); break;
              case Easing.BounceEase:
            ef = new BounceEase(); break;
              case Easing.CircleEase:
            ef = new CircleEase(); break;
              case Easing.CubicEase:
            ef = new CubicEase(); break;
              case Easing.ElasticEase:
            ef = new ElasticEase(); break;
              case Easing.ExponentialEase:
            ef = new ExponentialEase(); break;
              case Easing.PowerEase:
            ef = new PowerEase(); break;
              case Easing.QuadraticEase:
            ef = new QuadraticEase(); break;
              case Easing.QuarticEase:
            ef = new QuarticEase(); break;
              case Easing.QuinticEase:
            ef = new QuinticEase(); break;
              case Easing.SineEase:
            ef = new SineEase(); break;

              default:
            break;
            }

            foreach (DoubleAnimation anim in sb.Children)
              anim.EasingFunction = ef;
              }
            #endif

              return new PlotElementAnimation() { Storyboard = sb, SymbolStyle = style };
        }
Beispiel #19
0
        protected AnimationTransform GetFrameTransition(Reference p_ref)
        {
            Timeline l_timeline = m_current.TimeLines[p_ref.Timeline];

            // Find the current frame.
            // The one referenced by mainline is not neccesarily the correct one
            // I guess the Spriter editor sometimes messes things up
            // I'm not sure how to reproduce this problem but better safe than sorry? For the reference XSpriter does something similar

            int l_keyCur = l_timeline.KeyAtOrBefore(m_elapsedTime), l_keyNext = 0;
            int l_thisTime = m_elapsedTime - l_timeline.Keys[l_keyCur].Time, l_nextTime = 0;

            // Find the next frame.
            if ((l_keyCur + 1) < l_timeline.Keys.Count)
            {
                l_keyNext  = l_keyCur + 1;
                l_nextTime = l_timeline.Keys[l_keyNext].Time;
            }
            else if (m_current.Looping)
            {
                // Assume that there is a frame at time = 0
                l_keyNext  = 0;
                l_nextTime = m_current.Length;
            }
            else
            {
                l_keyNext  = l_keyCur;
                l_nextTime = m_current.Length;
            }

            //  Figure out where we are in the timeline...
            l_nextTime = l_nextTime - l_timeline.Keys[l_keyCur].Time;

            TimelineKey l_now = l_timeline.Keys[l_keyCur], l_next = l_timeline.Keys[l_keyNext];
            float       l_timeRatio = MathHelper.Clamp((float)l_thisTime / (float)l_nextTime, 0.0f, 1.0f);

            /// Tween EVERYTHING... Gonna have to add an option for it not to...
            /// Rotations are handled differently depending on which way they're supposed to spin
            AnimationTransform l_render = new AnimationTransform();

            float l_angleA = l_now.Rotation, l_angleB = l_next.Rotation;

            if (l_now.Spin == SpinDirection.None)
            {
                l_angleA = l_angleB = l_now.Rotation;
            }
            else if (l_now.Spin == SpinDirection.Clockwise)
            {
                if ((l_angleB - l_angleA) < 0.0f)
                {
                    l_angleB += MathHelper.TwoPi;
                }
                else
                {
                    l_angleA %= MathHelper.TwoPi;
                    l_angleB %= MathHelper.TwoPi;
                }
            }
            else if (l_now.Spin == SpinDirection.CounterClockwise)
            {
                if ((l_angleB - l_angleA) > 0.0f)
                {
                    l_angleB -= MathHelper.TwoPi;
                }
                else
                {
                    l_angleA %= MathHelper.TwoPi;
                    l_angleB %= MathHelper.TwoPi;
                }
            }

            l_render.Rotation = MathHelper.Lerp(l_angleA, l_angleB, l_timeRatio);
            l_render.Scale    = Vector2.Lerp(l_now.Scale, l_next.Scale, l_timeRatio);
            l_render.Location = Vector2.Lerp(l_now.Location, l_next.Location, l_timeRatio);
            l_render.Pivot    = Vector2.Lerp(l_now.Pivot, l_next.Pivot, l_timeRatio);
            l_render.Alpha    = MathHelper.Lerp(l_now.Alpha, l_next.Alpha, l_timeRatio);

            // So, how far are we between frames?
            return(l_render);
        }
Beispiel #20
0
 void SubscribeToEvent(LerpVector3 lerpVector3, AnimationTransform animationTransform)
 {
     lerpVector3.OnEndEvent.AddListener(animationTransform.StartAnimation);
 }
Beispiel #21
0
        public static PlotElementAnimation CreateAnimation(AnimationTransform transform, AnimationOrigin origin, Easing easing, bool indexDelay)
        {
            var sb       = new Storyboard();
            var duration = new Duration(TimeSpan.FromSeconds(0.5));

            var style = new Style();

            style.TargetType = typeof(PlotElement);
            style.Setters.Add(new Setter(PlotElement.OpacityProperty, 0.0));

            if (transform == AnimationTransform.Scale)
            {
                style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new ScaleTransform()
                {
                    ScaleX = 0, ScaleY = 0
                }));
            }
            else if (transform == AnimationTransform.Rotation)
            {
                style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new RotateTransform()
                {
                    Angle = 180
                }));
            }

            var point = new Point(0.5, 0.5);

            switch (origin)
            {
            case AnimationOrigin.Bottom:
                point = new Point(0.5, 2);
                break;

            case AnimationOrigin.Top:
                point = new Point(0.5, -2);
                break;

            case AnimationOrigin.Left:
                point = new Point(-2, 0.5);
                break;

            case AnimationOrigin.Right:
                point = new Point(2, 0.5);
                break;

            case AnimationOrigin.TopLeft:
                point = new Point(2, -2);
                break;

            case AnimationOrigin.TopRight:
                point = new Point(-2, -2);
                break;

            case AnimationOrigin.BottomLeft:
                point = new Point(2, 2);
                break;

            case AnimationOrigin.BottomRight:
                point = new Point(-2, 2);
                break;

            default:
                break;
            }

            style.Setters.Add(new Setter(PlotElement.RenderTransformOriginProperty, point));

            var da = new DoubleAnimation()
            {
                From = 0, To = 1, Duration = duration
            };

            Storyboard.SetTargetProperty(da, new PropertyPath("Opacity"));
            sb.Children.Add(da);

            if (transform == AnimationTransform.Scale)
            {
                var da2 = new DoubleAnimation()
                {
                    From = 0, To = 1, Duration = duration
                };
                Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).ScaleX"));

                var da3 = new DoubleAnimation()
                {
                    From = 0, To = 1, Duration = duration
                };
                Storyboard.SetTargetProperty(da3, new PropertyPath("(RenderTransform).ScaleY"));

                sb.Children.Add(da2);
                sb.Children.Add(da3);
            }
            else if (transform == AnimationTransform.Rotation)
            {
                var da2 = new DoubleAnimation()
                {
                    To = 0, Duration = duration
                };
                Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).Angle"));
                sb.Children.Add(da2);
            }

            if (indexDelay)
            {
                foreach (var anim in sb.Children)
                {
                    PlotElementAnimation.SetIndexDelay(anim, 0.5);
                }
            }

#if CLR40
            if (easing != Easing.None)
            {
                IEasingFunction ef = null;

                switch (easing)
                {
                case Easing.BackEase:
                    ef = new BackEase(); break;

                case Easing.BounceEase:
                    ef = new BounceEase(); break;

                case Easing.CircleEase:
                    ef = new CircleEase(); break;

                case Easing.CubicEase:
                    ef = new CubicEase(); break;

                case Easing.ElasticEase:
                    ef = new ElasticEase(); break;

                case Easing.ExponentialEase:
                    ef = new ExponentialEase(); break;

                case Easing.PowerEase:
                    ef = new PowerEase(); break;

                case Easing.QuadraticEase:
                    ef = new QuadraticEase(); break;

                case Easing.QuarticEase:
                    ef = new QuarticEase(); break;

                case Easing.QuinticEase:
                    ef = new QuinticEase(); break;

                case Easing.SineEase:
                    ef = new SineEase(); break;

                default:
                    break;
                }

                foreach (DoubleAnimation anim in sb.Children)
                {
                    anim.EasingFunction = ef;
                }
            }
#endif

            return(new PlotElementAnimation()
            {
                Storyboard = sb, SymbolStyle = style
            });
        }