static void AddShapeInstanceToFrame( SwfLibrary library, SwfDisplayShapeInstance inst, Matrix4x4 inst_matrix, SwfBlendModeData inst_blend_mode, SwfColorTransData inst_color_transform, ushort parent_masked, ushort parent_mask, List <SwfInstanceData> parent_masks, List <SwfInstanceData> self_masks, SwfFrameData frame) { var shape_def = library.FindDefine <SwfLibraryShapeDefine>(inst.Id); if (shape_def != null) { for (var i = 0; i < shape_def.Bitmaps.Length; ++i) { var bitmap_id = shape_def.Bitmaps[i]; var bitmap_matrix = i < shape_def.Matrices.Length ? shape_def.Matrices[i] : SwfMatrix.identity; var bitmap_def = library.FindDefine <SwfLibraryBitmapDefine>(bitmap_id); if (bitmap_def != null) { var frame_inst_type = (parent_mask > 0 || inst.ClipDepth > 0) ? SwfInstanceData.Types.Mask : (parent_masked > 0 || self_masks.Count > 0) ? SwfInstanceData.Types.Masked : SwfInstanceData.Types.Group; var frame_inst_clip_depth = (parent_mask > 0) ? parent_mask : (inst.ClipDepth > 0) ? inst.ClipDepth : parent_masked + self_masks.Count; frame.Instances.Add(new SwfInstanceData { Type = frame_inst_type, ClipDepth = (ushort)frame_inst_clip_depth, Bitmap = bitmap_id, Matrix = SwfMatrixData.FromUMatrix(inst_matrix * bitmap_matrix.ToUMatrix()), BlendMode = inst_blend_mode, ColorTrans = inst_color_transform }); if (parent_mask > 0) { parent_masks.Add(frame.Instances[frame.Instances.Count - 1]); } else if (inst.ClipDepth > 0) { self_masks.Add(frame.Instances[frame.Instances.Count - 1]); } } } } }
static void AddBitmapInstanceToFrame( SwfLibrary library, SwfDisplayBitmapInstance inst, Matrix4x4 inst_matrix, SwfBlendModeData inst_blend_mode, SwfColorTransData inst_color_transform, ushort parent_masked, ushort parent_mask, List <SwfInstanceData> parent_masks, List <SwfInstanceData> self_masks, SwfFrameData frame) { var bitmap_def = library.FindDefine <SwfLibraryBitmapDefine>(inst.Id); if (bitmap_def != null) { var frame_inst_type = (parent_mask > 0 || inst.ClipDepth > 0) ? SwfInstanceData.Types.Mask : (parent_masked > 0 || self_masks.Count > 0) ? SwfInstanceData.Types.Masked : SwfInstanceData.Types.Group; var frame_inst_clip_depth = (parent_mask > 0) ? parent_mask : (inst.ClipDepth > 0) ? inst.ClipDepth : parent_masked + self_masks.Count; frame.Instances.Add(new SwfInstanceData { Type = frame_inst_type, ClipDepth = (ushort)frame_inst_clip_depth, Bitmap = inst.Id, Matrix = SwfMatrixData.FromUMatrix(inst_matrix * Matrix4x4.Scale(new Vector3(20, 20, 1))), BlendMode = inst_blend_mode, ColorTrans = inst_color_transform }); if (parent_mask > 0) { parent_masks.Add(frame.Instances[frame.Instances.Count - 1]); } else if (inst.ClipDepth > 0) { self_masks.Add(frame.Instances[frame.Instances.Count - 1]); } } }
static void AddSpriteInstanceToFrame( SwfLibrary library, SwfDisplaySpriteInstance inst, Matrix4x4 inst_matrix, SwfBlendModeData inst_blend_mode, SwfColorTransData inst_color_transform, ushort parent_masked, ushort parent_mask, List <SwfInstanceData> parent_masks, List <SwfInstanceData> self_masks, SwfFrameData frame, System.Action <string> warning_log) { var sprite_def = library.FindDefine <SwfLibrarySpriteDefine>(inst.Id); if (sprite_def != null) { AddDisplayListToFrame( library, inst.DisplayList, inst_matrix, inst_blend_mode, inst_color_transform, (ushort)(parent_masked + self_masks.Count), (ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (ushort)0)), parent_mask > 0 ? parent_masks : (inst.ClipDepth > 0 ? self_masks : null), frame, warning_log); } }
static SwfFrameData AddDisplayListToFrame( SwfLibrary library, SwfDisplayList display_list, Matrix4x4 parent_matrix, SwfBlendModeData parent_blend_mode, SwfColorTransData parent_color_transform, ushort parent_masked, ushort parent_mask, List <SwfInstanceData> parent_masks, SwfFrameData frame, System.Action <string> warning_log) { if (warning_log != null) { var inst_filter_types = display_list.Instances.Values .Where(p => p.Visible && p.FilterList.Filters.Count > 0) .SelectMany(p => p.FilterList.Filters) .Select(p => p.Type) .Distinct(); foreach (var filter_type in inst_filter_types) { warning_log(string.Format( "Unsupported filter type '{0}'", filter_type)); } } var self_masks = new List <SwfInstanceData>(); foreach (var inst in display_list.Instances.Values.Where(p => p.Visible)) { CheckSelfMasks(self_masks, inst.Depth, frame); var child_matrix = parent_matrix * inst.Matrix.ToUMatrix(); var child_blend_mode = parent_blend_mode * inst.BlendMode.ToBlendModeData(warning_log); var child_color_transform = parent_color_transform * inst.ColorTransform.ToColorTransData(); switch (inst.Type) { case SwfDisplayInstanceType.Shape: AddShapeInstanceToFrame( library, inst as SwfDisplayShapeInstance, child_matrix, child_blend_mode, child_color_transform, parent_masked, parent_mask, parent_masks, self_masks, frame); break; case SwfDisplayInstanceType.Bitmap: AddBitmapInstanceToFrame( library, inst as SwfDisplayBitmapInstance, child_matrix, child_blend_mode, child_color_transform, parent_masked, parent_mask, parent_masks, self_masks, frame); break; case SwfDisplayInstanceType.Sprite: AddSpriteInstanceToFrame( library, inst as SwfDisplaySpriteInstance, child_matrix, child_blend_mode, child_color_transform, parent_masked, parent_mask, parent_masks, self_masks, frame, warning_log); break; default: throw new UnityException(string.Format( "unsupported SwfDisplayInstanceType: {0}", inst.Type)); } } CheckSelfMasks(self_masks, ushort.MaxValue, frame); return(frame); }