private static void WriteAnimationKey(XAnimationKey animationKey, XofFileSaveData saveData)
        {
            byte[] data;

            using (var ms = new MemoryStream())
                using (var writer = new BinaryWriter(ms))
                {
                    writer.Write((int)animationKey.KeyType);
                    writer.Write(animationKey.Keys.Count);

                    foreach (var key in animationKey.Keys)
                    {
                        writer.Write(key.Item1);
                        writer.Write(key.Item2.Length);

                        for (int i = 0; i < key.Item2.Length; i++)
                        {
                            writer.Write(key.Item2[i]);
                        }
                    }

                    data = ms.ToArray();
                }

            using (saveData.AddData(XofFileDefaultTemplates.AnimationKeyId, animationKey.Name, null, data))
            {
            }
        }
Example #2
0
        private static XAnimationKey ReadAnimationKey(XofFileEnumData enumData)
        {
            var animationKey = new XAnimationKey
            {
                Name = enumData.GetName()
            };

            byte[] data = enumData.GetData();

            using (var ms = new MemoryStream(data, false))
                using (var reader = new BinaryReader(ms))
                {
                    animationKey.KeyType = (XAnimationKeyType)reader.ReadInt32();

                    int nKeys = reader.ReadInt32();
                    animationKey.Keys.Capacity = nKeys;

                    for (int index = 0; index < nKeys; index++)
                    {
                        int time = reader.ReadInt32();

                        int valuesCount = reader.ReadInt32();
                        var values      = new float[valuesCount];

                        for (int i = 0; i < valuesCount; i++)
                        {
                            values[i] = reader.ReadSingle();
                        }

                        animationKey.Keys.Add(Tuple.Create(time, values));
                    }

                    if (ms.Position != ms.Length)
                    {
                        throw new InvalidDataException();
                    }
                }

            if (enumData.GetChildrenCount() != 0)
            {
                throw new InvalidDataException();
            }

            return(animationKey);
        }