/// <summary> /// Reads and creates Animations from the prototype xml. /// For now, this requires an idle animation and a flying animation state. /// </summary> private void ReadAnimationXml(XmlReader animationReader) { while (animationReader.Read()) { if (animationReader.Name == "Animation") { string state = animationReader.GetAttribute("state"); float fps = 1; float.TryParse(animationReader.GetAttribute("fps"), out fps); bool looping = true; bool.TryParse(animationReader.GetAttribute("looping"), out looping); bool valueBased = false; // read frames XmlReader frameReader = animationReader.ReadSubtree(); List <string> framesSpriteNames = new List <string>(); while (frameReader.Read()) { if (frameReader.Name == "Frame") { framesSpriteNames.Add(frameReader.GetAttribute("name")); } } SpritenameAnimation animation = new SpritenameAnimation(state, framesSpriteNames.ToArray(), fps, looping, false, valueBased); Animations.Add(state, animation); } } }
public static Dictionary <string, SpritenameAnimation> ReadAnimations(JToken animationsToken) { Dictionary <string, SpritenameAnimation> animations = new Dictionary <string, SpritenameAnimation>(); if (animationsToken != null) { foreach (JProperty animationToken in animationsToken) { SpritenameAnimation animation = new SpritenameAnimation(); animation.ReadJson(animationToken); animations.Add(animation.State, animation); } } return(animations); }
public void Init(Vector3 leavingCoords, Vector3 landingCoords, float speed, Trader trader, SpritenameAnimation animationIdle, SpritenameAnimation animationFlying, SpriteRenderer renderer, float destinationReachedThreshold = 0.1f) { this.LeavingCoordinates = leavingCoords; this.LandingCoordinates = landingCoords; this.Speed = speed; this.DestinationReachedThreshold = destinationReachedThreshold; this.Trader = trader; this.AnimationIdle = animationIdle; this.AnimationFlying = animationFlying; this.Renderer = renderer; }