/// <summary> /// Add a new frame to the given animation /// </summary> public PAFrame AddFrame(PAAnimation animation) { var frame = new PAFrame(this) { id = System.Guid.NewGuid().ToString(), animation = animation, order = frames.Count }; frames.Add(frame); return(frame); }
/// <summary> /// Insert a new frame at the given index within the animation /// </summary> public PAFrame InsertFrame(PAAnimation animation, int index) { var frame = AddFrame(animation); if (index == -1 || index >= frame.order) { return(frame); } foreach (var f in frames) { if (f.order >= index) { f.order++; } } frame.order = index; return(frame); }
/// <summary> /// Add a new animation with the given name to the file /// </summary> public PAAnimation AddAnimation(string name) { // ensure name is unique var prefix = name; for (var index = 1; null != FindAnimationByName(name); index++) { name = $"{prefix} {index}"; } var animation = new PAAnimation { id = System.Guid.NewGuid().ToString(), name = name }; animations.Add(animation); // Add a single frame for the animation AddFrame(animation); return(animation); }
public PAAnimationOptions(PAWorkspace worksapce, PAAnimation animation) { _workspace = worksapce; _animation = animation; }
/// <summary> /// Load a pixel edtior file from the given filename /// </summary> public static PAFile Load(string filename) { var file = new PAFile { name = Path.GetFileNameWithoutExtension(filename) }; using (var reader = new BinaryReader(File.OpenRead(filename))) { file.version = reader.ReadInt32(); file.width = reader.ReadInt32(); file.height = reader.ReadInt32(); var textureSize = 4 * file.width * file.height; // Read the layers var layerCount = reader.ReadInt32(); for (var layerIndex = 0; layerIndex < layerCount; layerIndex++) { var layer = new PALayer(file); layer.id = reader.ReadString(); layer.name = reader.ReadString(); layer.opacity = reader.ReadSingle(); layer.order = reader.ReadInt32(); layer.visible = reader.ReadBoolean(); file.layers.Add(layer); } // Read the animations var animationCount = reader.ReadInt32(); for (var animationIndex = 0; animationIndex < animationCount; animationIndex++) { var animation = new PAAnimation(); animation.id = reader.ReadString(); animation.name = reader.ReadString(); if (file.version < 3) { animation.fps = 10; } else { animation.fps = reader.ReadInt32(); } file.animations.Add(animation); } // Read the frames var frameCount = reader.ReadInt32(); for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) { var frame = new PAFrame(file); frame.id = reader.ReadString(); frame.animation = file.FindAnimation(reader.ReadString()); frame.order = reader.ReadInt32(); file.frames.Add(frame); } // Read the textures var imageCount = reader.ReadInt32(); for (var imageIndex = 0; imageIndex < imageCount; imageIndex++) { var image = new PAImage(); image.frame = file.FindFrame(reader.ReadString()); image.layer = file.FindLayer(reader.ReadString()); if (reader.ReadBoolean()) { image.texture = new Texture2D(file.width, file.height, TextureFormat.RGBA32, false); image.texture.LoadRawTextureData(reader.ReadBytes(textureSize)); image.texture.filterMode = FilterMode.Point; image.texture.Apply(); } file.images.Add(image); } } return(file); }