Пример #1
0
 private void SetNewAnimation(int id)
 {
     if (id < 0)  // no animation found, spawn!
     {
         Play(false);
     }
     else
     {
         iAnimationStep   = -1;
         CurrentAnimation = Animations.GetAnimation(id);
         timer1.Interval  = CurrentAnimation.Start.Interval.GetValue();
     }
 }
Пример #2
0
    // Start Next animation
    public void AnimationsNext()
    {
        // Which animation to play
        switch (AnimationsOrder)
        {
        case TOrder.Order:
            animID++;
            if (animID > Animations.Count - 1)
            {
                animID = 0;
            }
            break;

        case TOrder.PingPong:
            if (!pong)
            {
                animID++;
                if (animID > Animations.Count - 1)
                {
                    animID--;
                    pong = true;
                }
            }
            else
            {
                animID--;
                if (animID < 0)
                {
                    animID++;
                    pong = false;
                }
            }
            break;

        case TOrder.Random:
            animID = Random.Range(0, Animations.Count);
            break;
        }

        // now we have animation in anim
        anim = Animations[animID];
        if (anim.AnimTexture != null && anim.FPS > 0)
        {
            StartCoroutine(AnimationPlay());
        }
    }
Пример #3
0
        public void loadAnimations(Animations animations)
        {
            XmlNodeList nodes = xmlDoc.SelectNodes("//pet:animations/pet:animation", xmlNS);

            foreach (XmlNode node in nodes)
            {
                int        id  = int.Parse(node.Attributes["id"].InnerText);
                TAnimation ani = animations.AddAnimation(id, id.ToString());
                ani.Border  = false;
                ani.Gravity = false;
                foreach (XmlNode node2 in node.ChildNodes)
                {
                    switch (node2.Name)
                    {
                    case "name":
                        ani.Name = node2.InnerText;
                        switch (ani.Name)
                        {
                        case "fall": animations.AnimationFall = id; break;

                        case "drag": animations.AnimationDrag = id; break;

                        case "kill": animations.AnimationKill = id; break;

                        case "sync": animations.AnimationSync = id; break;
                        }
                        break;

                    case "start":
                        ani.Start.X.Compute        = node2.SelectSingleNode(".//pet:x", xmlNS).InnerText;
                        ani.Start.X.Random         = (ani.Start.X.Compute.IndexOf("random") >= 0);
                        ani.Start.X.Value          = parseValue(ani.Start.X.Compute);
                        ani.Start.Y.Compute        = node2.SelectSingleNode(".//pet:y", xmlNS).InnerText;
                        ani.Start.Y.Random         = (ani.Start.Y.Compute.IndexOf("random") >= 0);
                        ani.Start.Y.Value          = parseValue(ani.Start.Y.Compute);
                        ani.Start.Interval.Compute = node2.SelectSingleNode(".//pet:interval", xmlNS).InnerText;
                        ani.Start.Interval.Random  = (ani.Start.Interval.Compute.IndexOf("random") >= 0);
                        ani.Start.Interval.Value   = parseValue(ani.Start.Interval.Compute);
                        break;

                    case "end":
                        ani.End.X.Compute        = node2.SelectSingleNode(".//pet:x", xmlNS).InnerText;
                        ani.End.X.Random         = (ani.End.X.Compute.IndexOf("random") >= 0);
                        ani.End.X.Value          = parseValue(ani.End.X.Compute);
                        ani.End.Y.Compute        = node2.SelectSingleNode(".//pet:y", xmlNS).InnerText;
                        ani.End.Y.Random         = (ani.End.Y.Compute.IndexOf("random") >= 0);
                        ani.End.Y.Value          = parseValue(ani.End.Y.Compute);
                        ani.End.Interval.Compute = node2.SelectSingleNode(".//pet:interval", xmlNS).InnerText;
                        ani.End.Interval.Random  = (ani.End.Interval.Compute.IndexOf("random") >= 0);
                        ani.End.Interval.Value   = parseValue(ani.End.Interval.Compute);
                        break;

                    case "sequence":
                        ani.Sequence.RepeatFrom     = int.Parse(node2.Attributes["repeatfrom"].InnerText);
                        ani.Sequence.Repeat.Compute = node2.Attributes["repeat"].InnerText;
                        if (node2.SelectSingleNode(".//pet:action", xmlNS) != null)
                        {
                            ani.Sequence.Action = node2.SelectSingleNode(".//pet:action", xmlNS).InnerText;
                        }
                        ani.Sequence.Repeat.Random = (ani.Sequence.Repeat.Compute.IndexOf("random") >= 0);
                        ani.Sequence.Repeat.Value  = parseValue(ani.Sequence.Repeat.Compute);
                        foreach (XmlNode node3 in node2.SelectNodes(".//pet:frame", xmlNS))
                        {
                            ani.Sequence.Frames.Add(int.Parse(node3.InnerText));
                        }
                        if (ani.Sequence.RepeatFrom > 0)
                        {
                            ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + (ani.Sequence.Frames.Count - ani.Sequence.RepeatFrom - 1) * ani.Sequence.Repeat.Value;
                        }
                        else
                        {
                            ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + ani.Sequence.Frames.Count * ani.Sequence.Repeat.Value;
                        }
                        foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS))
                        {
                            TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE;
                            if (node3.Attributes["only"] != null)
                            {
                                switch (node3.Attributes["only"].InnerText)
                                {
                                case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                                case "window": where = TNextAnimation.TOnly.WINDOW; break;

                                case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                                case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                                case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;
                                }
                            }
                            ani.EndAnimation.Add(
                                new TNextAnimation(
                                    int.Parse(node3.InnerText),
                                    int.Parse(node3.Attributes["probability"].InnerText),
                                    where
                                    )
                                );
                        }
                        break;

                    case "border":
                        foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS))
                        {
                            TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE;
                            if (node3.Attributes["only"] != null)
                            {
                                switch (node3.Attributes["only"].InnerText)
                                {
                                case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                                case "window": where = TNextAnimation.TOnly.WINDOW; break;

                                case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                                case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                                case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;
                                }
                            }
                            ani.Border = true;
                            ani.EndBorder.Add(
                                new TNextAnimation(
                                    int.Parse(node3.InnerText),
                                    int.Parse(node3.Attributes["probability"].InnerText),
                                    where
                                    )
                                );
                        }
                        break;

                    case "gravity":
                        foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS))
                        {
                            TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE;
                            if (node3.Attributes["only"] != null)
                            {
                                switch (node3.Attributes["only"].InnerText)
                                {
                                case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                                case "window": where = TNextAnimation.TOnly.WINDOW; break;

                                case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                                case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                                case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;
                                }
                            }
                            ani.Gravity = true;
                            ani.EndGravity.Add(
                                new TNextAnimation(
                                    int.Parse(node3.InnerText),
                                    int.Parse(node3.Attributes["probability"].InnerText),
                                    where
                                    )
                                );
                        }
                        break;
                    }
                }
                animations.SaveAnimation(ani, id);
            }

            nodes = xmlDoc.SelectNodes("//pet:animations/pet:spawn", xmlNS);
            foreach (XmlNode node in nodes)
            {
                int    id  = int.Parse(node.Attributes["id"].InnerText);
                TSpawn ani = animations.AddSpawn(id, int.Parse(node.Attributes["probability"].InnerText), id.ToString());

                foreach (XmlNode node2 in node.ChildNodes)
                {
                    switch (node2.Name)
                    {
                    case "x":
                        ani.Start.X.Compute = node2.InnerText;
                        ani.Start.X.Random  = (ani.Start.X.Compute.IndexOf("random") >= 0);
                        ani.Start.X.Value   = parseValue(ani.Start.X.Compute);
                        break;

                    case "y":
                        ani.Start.Y.Compute = node2.InnerText;
                        ani.Start.Y.Random  = (ani.Start.Y.Compute.IndexOf("random") >= 0);
                        ani.Start.Y.Value   = parseValue(ani.Start.Y.Compute);
                        break;

                    case "direction":
                        string sDirection = node2.InnerText;
                        ani.MoveLeft = (sDirection == "left");
                        break;

                    case "next":
                        ani.Next = int.Parse(node2.InnerText);
                        break;
                    }
                }
                animations.SaveSpawn(ani, id);
            }
        }