示例#1
0
            public Clip(AseData owner, string name, int s, int e, bool looping)
            {
                this.owner   = owner;
                this.name    = name;
                this.looping = looping;
                start        = s;
                end          = e;

                samples = new int[Count + 1];
                Init();
            }
示例#2
0
        /// <summary>
        /// Reads animation data from an extracted json file.
        /// </summary>
        /// <param name="file"> location of the json file </param>
        /// <returns></returns>
        public static AseData ReadFromJSON(string file)
        {
            AseData  anim   = new AseData();
            JsonData dat    = JsonMapper.ToObject(File.ReadAllText(file));
            JsonData frames = dat["frames"];
            JsonData tags   = dat["meta"]["frameTags"];
            JsonData size   = frames[0]["sourceSize"];

            anim.clips = new List <Clip>();

            anim.durations = new int[frames.Count];
            for (int i = 0; i < frames.Count; i++)
            {
                anim.durations[i] = int.Parse(frames[i]["duration"].ToString());
            }

            anim.dim = new Vector2(float.Parse(size["w"].ToString()),
                                   float.Parse(size["h"].ToString()));

            // load loop names
            if (tags.Count == 0)
            {
                anim.clips.Add(new Clip(anim, "base", 0, frames.Count - 1, true));
            }
            else
            {
                for (int i = 0; i < tags.Count; i++)
                {
                    Clip clip = new Clip(anim,
                                         AseUtils.UppercaseFirst(tags[i]["name"].ToString()),
                                         int.Parse(tags[i]["from"].ToString()),
                                         int.Parse(tags[i]["to"].ToString()),
                                         tags[i]["direction"].ToString().Equals("forward"));
                    //Debug.Log(clip.name + " looping: " + clip.looping);
                    anim.clips.Add(clip);
                }
            }

            return(anim);
        }