public static Dictionary <string, AnimClipInfo> GetAnimClipInfos() { Debug.Log("Getting anim clip info!"); string rawXml = PathMan.GetModInternalFile(PathMan.ANIM_CLIPS_PATH, "AnimClips.xml", "AssemblyCSharp.LadybugTestMod.mm.InitialAnimClipXml.xml"); XmlReader xmlReader = XmlReader.Create(new StringReader(rawXml)); Dictionary <string, AnimClipInfo> animClipInfos = new Dictionary <string, AnimClipInfo>(); if (xmlReader.ReadToDescendant("AnimClips") && xmlReader.ReadToDescendant("AnimClip")) { // we're now parallel to the anim clip elements. do { string id = xmlReader.GetAttribute("id"); animClipInfos[id] = new AnimClipInfo(); XmlReader subtree = xmlReader.ReadSubtree(); while (subtree.Read()) { string tag = subtree.Name; switch (tag) { case "KeyFrameLength": subtree.Read(); animClipInfos[id].keyFrameLength = subtree.ReadContentAsFloat(); break; } } } while (xmlReader.ReadToNextSibling("AnimClip")); } return(animClipInfos); }
public void LoadCustomAnimClips() { Debug.Log("LOADING THE ANIM CLIPS!!!!!"); List <string> paths = PathMan.GetModFiles(PathMan.ANIM_CLIPS_PATH, ".png"); Dictionary <string, AnimClipInfo> clipInfos = Utils.GetAnimClipInfos(); AnimClipInfo defaultClipInto = new AnimClipInfo(); // if it is not defined in the XML // Pattern to be considered a frame: alphanumeric "ID" portion and the frame number, seperated with an underscore. Regex frameMatchRegex = new Regex(@"(\w+)_([0-9]+)", RegexOptions.IgnoreCase); // The key is the id of the anim clip, the value is the list of frames for that clip. Dictionary <string, List <AnimClipFrame> > animClips = new Dictionary <string, List <AnimClipFrame> >(); foreach (string path in paths) { Match result = frameMatchRegex.Match(path); if (result.Success) { AnimClipFrame newAnimClipFrame = new AnimClipFrame(path, result.Groups[1].Value, int.Parse(result.Groups[2].Value)); // Make a new list for the anim clip key if it doesn't exist already if (!animClips.ContainsKey(newAnimClipFrame.key)) { animClips[newAnimClipFrame.key] = new List <AnimClipFrame>(); } animClips[newAnimClipFrame.key].Add(newAnimClipFrame); } } foreach (string key in animClips.Keys) { Debug.Log(String.Format("Getting files for anim clip {0} ", key)); List <AnimClipFrame> currentFrames = animClips[key]; // sorting is required since the files could be like // Sprite_9.png, Sprite_10.png (the 10 would be first in lexographic sort!) currentFrames.Sort(); // Make an anim clip now. List <string> fullPaths = new List <string>(); foreach (AnimClipFrame clip in currentFrames) { fullPaths.Add(clip.fullPath); } AnimClipInfo newInfo; if (!clipInfos.ContainsKey(key)) { newInfo = defaultClipInto; } else { newInfo = clipInfos[key]; } SpriteAnimationClip newClip = Utils.LoadNewSpriteAnimationClip(fullPaths.ToArray(), newInfo); this.spriteAnimClips[key] = newClip; Debug.Log("Done with this anim clip!"); } }
public static SpriteAnimationClip LoadNewSpriteAnimationClip(string[] FilePaths, AnimClipInfo theInfo) { Debug.Log("Hi, welcome to LoadNewSpriteAnimationClip!"); List <Sprite> sprites = new List <Sprite>(); List <float> numbers = new List <float>(); for (int i = 0; i < FilePaths.Length; i++) { numbers.Add((float)i); Debug.Log(String.Format("FRAME {0} IMAGE {1}", i, FilePaths[i])); sprites.Add(LoadNewSprite(FilePaths[i])); } SpriteAnimationClip newClip = new SpriteAnimationClip(theInfo.keyFrameLength, numbers.ToArray(), sprites.ToArray()); return(newClip); }