public static DisplayRegionGridSave FromDisplayRegionGrid( TextureGrid <FloatRectangle> displayRegionGrid) { DisplayRegionGridSave dgs = new DisplayRegionGridSave(); dgs.ReferenceGrid = new FloatRectangle[displayRegionGrid.Textures.Count][]; dgs.FirstPaintedX = displayRegionGrid.FirstPaintedX; dgs.FirstPaintedY = displayRegionGrid.FirstPaintedY; for (int i = 0; i < displayRegionGrid.Textures.Count; i++) { dgs.ReferenceGrid[i] = new FloatRectangle[displayRegionGrid[i].Count]; for (int j = 0; j < displayRegionGrid.Textures[i].Count; j++) { if (displayRegionGrid.Textures[i][j] != null) { dgs.ReferenceGrid[i][j] = displayRegionGrid.Textures[i][j]; } } } return(dgs); }
public List <TextureTile> Generate(TextureGrid grid) { var ni = new Dictionary <CardinalIndex, IntPoint> { { CardinalIndex.North, new IntPoint(0, 0) }, { CardinalIndex.East, new IntPoint(1, 0) }, { CardinalIndex.South, new IntPoint(0, 1) }, { CardinalIndex.West, new IntPoint(1, 1) } }; var reg = new CardinalIndexTileRegistry <string>(new ReflectorRegistry(), TileTagEntries.CreateCardinalIndexTagEntries(), grid.Pattern); var retval = new List <TextureTile>(); foreach (var name in ni) { if (!reg.TryFind(grid.Name, name.Key, out var tileName)) { continue; } retval.Add(new TextureTile(true, name.Value.X, name.Value.Y, tileName) { SelectorHint = name.Key.ToString() }); } return(retval); }
public TextureSetFixture CreateTextureSet(int width, int height, TileType tileType) { var textureSet = new TextureSetFile { Width = width, Height = height, TileType = tileType }; var gridParent = new TileTextureCollection { Parent = textureSet }; var grid = new TextureGrid { MatcherType = MatcherType.Basic }; grid.Tiles.Add(new TextureTile(false, 0, 0)); grid.Tiles.Add(new TextureTile(false, 1, 0)); grid.FormattingMetaData.Border = 1; grid.FormattingMetaData.BorderColor = border; grid.FormattingMetaData.Padding = 1; grid.FormattingMetaData.BackgroundColor = background; grid.TextureTileFormattingMetaData.TileOutlineColor = outline; grid.CellSpacing = 1; gridParent.Grids.Add(grid); return(new TextureSetFixture(textureSet, gridParent, grid)); }
public static AnimationChainGridSave FromAnimationChainGrid( TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> animationChainGrid) { AnimationChainGridSave ags = new AnimationChainGridSave(); int numberOfTextures = animationChainGrid.Textures.Count; ags.ReferenceGrid = new ReferencedAnimationChain[numberOfTextures][]; ags.FirstPaintedX = animationChainGrid.FirstPaintedX; ags.FirstPaintedY = animationChainGrid.FirstPaintedY; for (int i = 0; i < animationChainGrid.Textures.Count; i++) { ags.ReferenceGrid[i] = new ReferencedAnimationChain[animationChainGrid[i].Count]; for (int j = 0; j < animationChainGrid.Textures[i].Count; j++) { if (animationChainGrid.Textures[i][j] != null) { ags.ReferenceGrid[i][j] = ReferencedAnimationChain.FromAnimationChain( animationChainGrid.Textures[i][j]); } } } return(ags); }
public void Size_With_CellSpacing() { var g = new TextureGrid { Parent = new TileTextureCollection { Parent = new TextureSetFile { Width = 64, Height = 32, TileType = TileType.Isometric } }, MatcherType = MatcherType.Basic }; g.Tiles.Add(new TextureTile(false, 0, 0)); g.Tiles.Add(new TextureTile(false, 1, 0)); g.CellSpacing = 1; var node = new TextureGridLayoutNode(prefs, g); node.ContentSize.Should().Be(new IntDimension((64 * 2) + 1, 32), "tile size of 64x32 with 1px spacing"); node.Size.Should().Be(new IntDimension((64 * 2) + 1, 32), "tile size of 64x32 and a 1px cell spacing between the two tiles."); }
public List <TextureTile> Generate(TextureGrid grid) { var keys = new Dictionary <CornerTileSelectionKey, IntPoint>(); for (var i = 0; i < 8; i += 1) { Add(keys, i); } var reg = new CornerTileRegistry <string>(new ReflectorRegistry(), null, null, grid.Pattern); var retval = new List <TextureTile>(); foreach (var name in keys) { if (!reg.TryFind(grid.Name, name.Key, out var tileName)) { continue; } retval.Add(new TextureTile(true, name.Value.X, name.Value.Y, tileName) { SelectorHint = name.Key.ToString() }); } return(retval); }
public FlatRedBall.ManagedSpriteGroups.SpriteGrid ToSpriteGrid(Camera camera, string contentManagerName) // where SpriteGridType : FlatRedBall.ManagedSpriteGroups.SpriteGrid, new() { FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane plane = GetPlaneFromAxis(); // Since the TextureGrid is passed as an argument in the constructor of the SpriteGrid, it // needs to be created before the SpriteGrid is initialized TextureGrid <Texture2D> textureGrid = CreateTextureGrid(contentManagerName); FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid = new FlatRedBall.ManagedSpriteGroups.SpriteGrid( camera, plane, this.Blueprint.ToSprite(contentManagerName), textureGrid); CreateAnimationChainGrid(contentManagerName, spriteGrid); CreateDisplayRegionGrid(spriteGrid); spriteGrid.Name = this.Name; SetBoundsValues(spriteGrid); spriteGrid.GridSpacing = GridSpacing; SetOrderingMode(spriteGrid); spriteGrid.CreatesAutomaticallyUpdatedSprites = CreatesAutomaticallyUpdatedSprites; spriteGrid.CreatesParticleSprites = CreatesParticleSprites; //spriteGrid.DrawDefaultTileNoPopulate = DrawDefaultTile; return(spriteGrid); // do we need this line? // lastBlueprintPosition = Blueprint.ToVector3(); }
public static DisplayRegionGridSave FromDisplayRegionGrid( TextureGrid<FloatRectangle> displayRegionGrid) { DisplayRegionGridSave dgs = new DisplayRegionGridSave(); dgs.ReferenceGrid = new FloatRectangle[displayRegionGrid.Textures.Count][]; dgs.FirstPaintedX = displayRegionGrid.FirstPaintedX; dgs.FirstPaintedY = displayRegionGrid.FirstPaintedY; for (int i = 0; i < displayRegionGrid.Textures.Count; i++) { dgs.ReferenceGrid[i] = new FloatRectangle[displayRegionGrid[i].Count]; for (int j = 0; j < displayRegionGrid.Textures[i].Count; j++) { if (displayRegionGrid.Textures[i][j] != null) { dgs.ReferenceGrid[i][j] = displayRegionGrid.Textures[i][j]; } } } return dgs; }
public void Size_With_Border() { var g = new TextureGrid { Parent = new TileTextureCollection { Parent = new TextureSetFile { Width = 64, Height = 32, TileType = TileType.Isometric } }, MatcherType = MatcherType.Basic }; g.Tiles.Add(new TextureTile(false, 0, 0)); g.Tiles.Add(new TextureTile(false, 1, 0)); g.FormattingMetaData.Border = 1; g.FormattingMetaData.Padding = 2; var node = new TextureGridLayoutNode(prefs, g); node.ContentSize.Should().Be(new IntDimension(64 * 2, 32), "tile size of 64x32"); node.Size.Should().Be(new IntDimension((64 * 2) + (2 * 2) + (1 * 2), 32 + (2 * 2) + (1 * 2)), "tile size of 64x32 and a 1px border around the grid and 2px padding around the grid."); }
public static void Done() { if (inst != null) { inst.DestroyTexture(); inst = null; } }
public TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> ToAnimationChainGrid(string contentManagerName, float gridSpacing) { TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> toReturn = new TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain>(); toReturn.FirstPaintedX = FirstPaintedX; toReturn.LastPaintedX = new List <float>(); toReturn.FirstPaintedY = FirstPaintedY; toReturn.LastPaintedY = toReturn.FirstPaintedY + (ReferenceGrid.Length - 1) * gridSpacing; toReturn.GridSpacingX = gridSpacing; toReturn.GridSpacingY = gridSpacing; int yOn = 0; toReturn.BaseTexture = null; Dictionary <string, FlatRedBall.Graphics.Animation.AnimationChainList> animationChainListCache = new Dictionary <string, FlatRedBall.Graphics.Animation.AnimationChainList>(); foreach (ReferencedAnimationChain[] racArray in ReferenceGrid) { List <FlatRedBall.Graphics.Animation.AnimationChain> newAnimationChainList = new List <FlatRedBall.Graphics.Animation.AnimationChain>(); toReturn.Textures.Add(newAnimationChainList); toReturn.LastPaintedX.Add(toReturn.FirstPaintedX[yOn] + gridSpacing * (racArray.Length - 1)); foreach (ReferencedAnimationChain rac in racArray) { FlatRedBall.Graphics.Animation.AnimationChainList acl = null; if (!string.IsNullOrEmpty(rac.AnimationChainListFileName) && animationChainListCache.ContainsKey(rac.AnimationChainListFileName) == false) { AnimationChainListSave acls = AnimationChainListSave.FromFile(rac.AnimationChainListFileName); animationChainListCache.Add(rac.AnimationChainListFileName, acls.ToAnimationChainList(contentManagerName)); } if (string.IsNullOrEmpty(rac.AnimationChainListFileName)) { acl = null; newAnimationChainList.Add(null); } else { acl = animationChainListCache[rac.AnimationChainListFileName]; newAnimationChainList.Add(acl[rac.AnimationChainName]); } } yOn++; } return(toReturn); }
public List <TextureTile> Generate(TextureGrid grid) { var w = grid.Width ?? 0; var h = grid.Height ?? 0; if (w <= 0 || h <= 0) { return(new List <TextureTile>()); }
public TextureGridLayoutNode(GeneratorPreferences prefs, TextureGrid grid) { this.prefs = prefs; this.grid = grid ?? throw new ArgumentNullException(nameof(grid)); this.Margin = grid.FormattingMetaData.Margin ?? 0; this.ContentSize = ComputeContentSize(); this.TextAreaSize = ComputeTextSize(ContentSize); this.Size = ComputeGridSize(TextAreaSize, ContentSize); }
public static void Draw(Rect rect, Vector2 offset) { if (inst == null) { inst = new TextureGrid(); inst.InitTexture(); } GUI.DrawTextureWithTexCoords(rect, inst.gridTexture, new Rect(-offset.x / textureSize, (offset.y - rect.height) / textureSize, rect.width / textureSize, rect.height / textureSize), false); }
public IntDimension GetTileArea(TextureGrid grid) { var cellMapCount = Math.Max(1, grid.CellMappings.Count); var tileCount = Math.Pow(cellMapCount, 4); var width = (int)Math.Ceiling(Math.Sqrt(tileCount)); var height = (int)Math.Ceiling(tileCount / width); return(new IntDimension(width, height)); }
public void Draw() { if (editorDisplayScale <= 1.0f) { editorDisplayScale = 1.0f; } GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); TextureGrid.Draw(rect); int heightOffset = 50; Handles.color = new Color(1, 1, 0, 0.5f); Handles.DrawLine(new Vector2(rect.x + 10, rect.center.y + heightOffset), new Vector2(rect.x + rect.width - 10, rect.center.y + heightOffset)); Handles.DrawLine(new Vector2(rect.center.x, rect.y + 10), new Vector2(rect.center.x, rect.y + rect.height - 10)); if (CurTexture != null) { // middle mouse drag and scroll zoom if (rect.Contains(Event.current.mousePosition)) { // 拖动时修改偏移量 if (Event.current.type == EventType.MouseDrag) // && Event.current.button == 2) { //放大后调整偏移值 CurFrameData.Offset += Event.current.delta / editorDisplayScale; Event.current.Use(); HandleUtility.Repaint(); } if (Event.current.type == EventType.ScrollWheel) { editorDisplayScale -= Event.current.delta.y * 0.03f; Event.current.Use(); HandleUtility.Repaint(); } } bool alphaBlend = true; textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos, new Rect(0, 0, textureBorderPixels * 2 + (CurTexture.width) * editorDisplayScale, textureBorderPixels * 2 + (CurTexture.height) * editorDisplayScale)); Rect textureRect = new Rect(textureBorderPixels, textureBorderPixels, CurTexture.width * editorDisplayScale, CurTexture.height * editorDisplayScale); // 支持放大后调整偏移值 textureRect.x = rect.width / 2 - textureRect.width / 2 + CurFrameData.Offset.x * editorDisplayScale; textureRect.y = rect.height / 2 + heightOffset - textureRect.height + CurFrameData.Offset.y * editorDisplayScale; CurTexture.filterMode = FilterMode.Point; GUI.DrawTexture(textureRect, CurTexture, ScaleMode.ScaleAndCrop, alphaBlend); GUI.EndScrollView(); } GUILayout.EndVertical(); }
private void ClearAllSelectionsAndHighlightedObjects() { MeshGrid.UnselectAllCells(); MaterialGrid.UnselectAllCells(); TextureGrid.UnselectAllCells(); DataGridUtil.ClearAllHighlighted(MeshGrid); DataGridUtil.ClearAllHighlighted(MaterialGrid); DataGridUtil.ClearAllHighlighted(TextureGrid); }
private void CreateAnimationChainGrid(string contentManagerName, FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid) { #region Create the AnimationChainGrid if (AnimationChainGridSave != null) { TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> animationChainGrid = AnimationChainGridSave.ToAnimationChainGrid(contentManagerName, GridSpacing); spriteGrid.AnimationChainGrid = animationChainGrid; } #endregion }
public void ValidateEmptyTextureGridMetaData() { var tc = new TextureGrid(); var root = TextureSetFileWriter.GenerateGrid(tc); root.Name.Should().Be(Namespace + "grid"); root.Should().HaveAttribute("name", ""); root.Should().HaveAttribute("x", "0"); root.Should().HaveAttribute("y", "0"); root.Attribute("cell-width").Should().BeNull(); root.Attribute("cell-height").Should().BeNull(); root.Should().HaveElement(Namespace + "metadata"); }
public void Corner_Generation() { var grid = new TextureGrid { CellSpacing = 5, MatcherType = MatcherType.Corner }; collection.Grids.Add(grid); TextureTileGenerator.Regenerate(collection); grid.Tiles.Count.Should().Be(32); }
public IntDimension GetTileArea(TextureGrid grid) { var maxX = 0; var maxY = 0; foreach (var textureTile in grid.Tiles) { maxX = Math.Max(Math.Max(0, textureTile.X), maxX); maxY = Math.Max(Math.Max(0, textureTile.Y), maxY); } maxX += 1; maxY += 1; return(new IntDimension(maxX, maxY)); }
public List <TextureTile> Generate(TextureGrid grid) { var ni = new Dictionary <NeighbourMatchPosition, IntPoint>(); if (grid.Parent?.Parent?.TileType == TileType.Isometric) { ni.Add(NeighbourMatchPosition.NorthWest, new IntPoint(1, 0)); ni.Add(NeighbourMatchPosition.North, new IntPoint(2, 0)); ni.Add(NeighbourMatchPosition.NorthEast, new IntPoint(2, 1)); ni.Add(NeighbourMatchPosition.East, new IntPoint(2, 2)); ni.Add(NeighbourMatchPosition.SouthEast, new IntPoint(1, 2)); ni.Add(NeighbourMatchPosition.South, new IntPoint(0, 2)); ni.Add(NeighbourMatchPosition.SouthWest, new IntPoint(0, 1)); ni.Add(NeighbourMatchPosition.West, new IntPoint(0, 0)); ni.Add(NeighbourMatchPosition.Isolated, new IntPoint(1, 1)); } else { ni.Add(NeighbourMatchPosition.NorthWest, new IntPoint(0, 0)); ni.Add(NeighbourMatchPosition.North, new IntPoint(1, 0)); ni.Add(NeighbourMatchPosition.NorthEast, new IntPoint(2, 0)); ni.Add(NeighbourMatchPosition.West, new IntPoint(0, 1)); ni.Add(NeighbourMatchPosition.Isolated, new IntPoint(1, 1)); ni.Add(NeighbourMatchPosition.East, new IntPoint(2, 1)); ni.Add(NeighbourMatchPosition.SouthWest, new IntPoint(0, 2)); ni.Add(NeighbourMatchPosition.South, new IntPoint(1, 2)); ni.Add(NeighbourMatchPosition.SouthEast, new IntPoint(2, 2)); } var reg = new NeighbourIndexTileRegistry <string>(new ReflectorRegistry(), NeighbourIndexTileRegistry <string> .LongSelector(), grid.Pattern); var retval = new List <TextureTile>(); foreach (var name in ni) { if (!reg.TryFind(grid.Name, name.Key, out var tileName)) { continue; } retval.Add(new TextureTile(true, name.Value.X, name.Value.Y, tileName) { SelectorHint = name.Key.ToString() }); } return(retval); }
public void ValidateTextureGridOptionals() { var tc = new TextureGrid { AnchorX = 1, AnchorY = 2, Width = 3, Height = 4 }; var root = TextureSetFileWriter.GenerateGrid(tc); root.Should().HaveAttribute("anchor-x", "1"); root.Should().HaveAttribute("anchor-y", "2"); root.Element(Namespace + "metadata").Should().HaveAttribute("grid-width", "3"); root.Element(Namespace + "metadata").Should().HaveAttribute("grid-height", "4"); }
static bool HasTileAtPosition(TextureGrid g, int x, int y) { foreach (var t in g.Tiles) { if (t.AutoGenerated) { continue; } if (t.X == x && t.Y == y) { return(true); } } return(false); }
public void Draw() { if (editorDisplayScale <= 1.0f) { editorDisplayScale = 1.0f; } GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); TextureGrid.Draw(rect); if (CurTexture != null) { // middle mouse drag and scroll zoom if (rect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseDrag && Event.current.button == 2) { textureScrollPos -= Event.current.delta * editorDisplayScale; Event.current.Use(); HandleUtility.Repaint(); } if (Event.current.type == EventType.ScrollWheel) { editorDisplayScale -= Event.current.delta.y * 0.03f; Event.current.Use(); HandleUtility.Repaint(); } } bool alphaBlend = true; textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos, new Rect(0, 0, textureBorderPixels * 2 + (CurTexture.width) * editorDisplayScale, textureBorderPixels * 2 + (CurTexture.height) * editorDisplayScale)); Rect textureRect = new Rect(textureBorderPixels, textureBorderPixels, CurTexture.width * editorDisplayScale, CurTexture.height * editorDisplayScale); CurTexture.filterMode = FilterMode.Point; GUI.DrawTexture(textureRect, CurTexture, ScaleMode.ScaleAndCrop, alphaBlend); GameEditorUtility.DrawOutline(textureRect, Color.green); GUI.EndScrollView(); GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); GUILayout.Label(string.Format("Name:{0} W: {1} H: {2}", CurTexture.name, CurTexture.width, CurTexture.height)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }
public static ITilePainter CreateTilePainter(this TextureGrid grid, GeneratorPreferences prefs) { var t = grid.Parent?.Parent?.TileType ?? TileType.Grid; switch (t) { case TileType.Grid: return(new TextureGridTilePainter(prefs, grid)); case TileType.Isometric: return(new IsoTilePainter(prefs, grid)); //case TileType.Hex: // return new GridTilePainter(prefs, grid); // todo Hex is not really supported here or in the base library for now. default: throw new ArgumentOutOfRangeException(); } }
public void TextureGridEffectiveSize_When_NotCorner() { var g = new TextureGrid { Parent = new TileTextureCollection { Parent = new TextureSetFile { Width = 64, Height = 32, TileType = TileType.Isometric } }, MatcherType = MatcherType.Basic }; g.EffectiveTileSize.Should().Be(new IntDimension(64, 32)); g.EffectiveCellSize.Should().Be(new IntDimension(64, 32)); }
public static IntDimension ComputeTileDimension(this TextureGrid grid) { var textureFile = grid.Parent?.Parent; if (textureFile == null) { throw new ArgumentException("TextureGrid is not associated with a texture file."); } var w = textureFile.Width; var h = textureFile.Height; if (grid.MatcherType == MatcherType.Corner) { return(new IntDimension(w / 2, h / 2)); } return(new IntDimension(w, h)); }
private void CreateDisplayRegionGrid(FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid) { #region Create the DisplayRegionGrid if (DisplayRegionGridSave != null) { TextureGrid <FloatRectangle> displayRegionGrid = DisplayRegionGridSave.ToDisplayRegionGrid(GridSpacing); if (displayRegionGrid.BaseTexture == null) { displayRegionGrid.BaseTexture = new FloatRectangle( spriteGrid.Blueprint.TopTextureCoordinate, spriteGrid.Blueprint.BottomTextureCoordinate, spriteGrid.Blueprint.LeftTextureCoordinate, spriteGrid.Blueprint.RightTextureCoordinate); } spriteGrid.DisplayRegionGrid = displayRegionGrid; } #endregion }
public static void Regenerate(TextureGrid grid) { if (grid.MatcherType == MatcherType.Basic) { return; } // preserve any tiles a user has placed manually // should not happen via the UI, but if they added something via // the XML file, we try our best to keep it alive. var preservedTiles = grid.Tiles.Where(t => !t.AutoGenerated).ToList(); var newTiles = MatchTypeStrategyFactory.StrategyFor(grid.MatcherType) .Generate(grid); foreach (var t in newTiles.Where(t => !TileAlreadyExists(preservedTiles, t))) { preservedTiles.Add(t); } grid.Tiles.ReplaceAll(preservedTiles); }
public void SizeValidation_WhenCorner() { var g = new TextureGrid { Parent = new TileTextureCollection { Parent = new TextureSetFile { Width = 64, Height = 32, TileType = TileType.Isometric } }, MatcherType = MatcherType.Corner }; var size = g.EffectiveCellSize; var node = new TextureGridLayoutNode(prefs, g); node.Size.Should().Be(new IntDimension(8 * size.Width, 4 * size.Height)); }
public TextureGrid<FloatRectangle> ToDisplayRegionGrid(float gridSpacing) { TextureGrid<FloatRectangle> toReturn = new TextureGrid<FloatRectangle>(); toReturn.FirstPaintedX = FirstPaintedX; toReturn.LastPaintedX = new List<float>(); toReturn.FirstPaintedY = FirstPaintedY; toReturn.LastPaintedY = toReturn.FirstPaintedY + (ReferenceGrid.Length - 1) * gridSpacing; toReturn.GridSpacingX = gridSpacing; toReturn.GridSpacingY = gridSpacing; int yOn = 0; //toReturn.BaseTexture = new FloatRectangle(0,1,0,1); foreach (FloatRectangle[] frArray in ReferenceGrid) { List<FloatRectangle> newFloatRectangleList = new List<FloatRectangle>(); toReturn.Textures.Add(newFloatRectangleList); toReturn.LastPaintedX.Add(toReturn.FirstPaintedX[yOn] + gridSpacing * (frArray.Length - 1)); foreach (FloatRectangle rectangle in frArray) { newFloatRectangleList.Add(rectangle); } yOn++; } return toReturn; }
public static AnimationChainGridSave FromAnimationChainGrid( TextureGrid<FlatRedBall.Graphics.Animation.AnimationChain> animationChainGrid) { AnimationChainGridSave ags = new AnimationChainGridSave(); int numberOfTextures = animationChainGrid.Textures.Count; ags.ReferenceGrid = new ReferencedAnimationChain[numberOfTextures][]; ags.FirstPaintedX = animationChainGrid.FirstPaintedX; ags.FirstPaintedY = animationChainGrid.FirstPaintedY; for (int i = 0; i < animationChainGrid.Textures.Count; i++) { ags.ReferenceGrid[i] = new ReferencedAnimationChain[animationChainGrid[i].Count]; for (int j = 0; j < animationChainGrid.Textures[i].Count; j++) { if (animationChainGrid.Textures[i][j] != null) { ags.ReferenceGrid[i][j] = ReferencedAnimationChain.FromAnimationChain( animationChainGrid.Textures[i][j]); } } } return ags; }
public TextureGrid<FlatRedBall.Graphics.Animation.AnimationChain> ToAnimationChainGrid(string contentManagerName, float gridSpacing) { TextureGrid<FlatRedBall.Graphics.Animation.AnimationChain> toReturn = new TextureGrid<FlatRedBall.Graphics.Animation.AnimationChain>(); toReturn.FirstPaintedX = FirstPaintedX; toReturn.LastPaintedX = new List<float>(); toReturn.FirstPaintedY = FirstPaintedY; toReturn.LastPaintedY = toReturn.FirstPaintedY + (ReferenceGrid.Length - 1) * gridSpacing; toReturn.GridSpacingX = gridSpacing; toReturn.GridSpacingY = gridSpacing; int yOn = 0; toReturn.BaseTexture = null; Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChainList> animationChainListCache = new Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChainList>(); foreach (ReferencedAnimationChain[] racArray in ReferenceGrid) { List<FlatRedBall.Graphics.Animation.AnimationChain> newAnimationChainList = new List<FlatRedBall.Graphics.Animation.AnimationChain>(); toReturn.Textures.Add(newAnimationChainList); toReturn.LastPaintedX.Add(toReturn.FirstPaintedX[yOn] + gridSpacing * (racArray.Length - 1)); foreach (ReferencedAnimationChain rac in racArray) { FlatRedBall.Graphics.Animation.AnimationChainList acl = null; if (!string.IsNullOrEmpty(rac.AnimationChainListFileName) && animationChainListCache.ContainsKey(rac.AnimationChainListFileName) == false) { AnimationChainListSave acls = AnimationChainListSave.FromFile(rac.AnimationChainListFileName); animationChainListCache.Add(rac.AnimationChainListFileName, acls.ToAnimationChainList(contentManagerName)); } if (string.IsNullOrEmpty(rac.AnimationChainListFileName)) { acl = null; newAnimationChainList.Add(null); } else { acl = animationChainListCache[rac.AnimationChainListFileName]; newAnimationChainList.Add(acl[rac.AnimationChainName]); } } yOn++; } return toReturn; }