Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Tilemaps;
- namespace BaseProject
- {
- public class TemplateMaster : TemplateBase
- {
- //Related templates
- public Vector2Int templateLayout;
- public Template[] templates;
- public override Vector2Int GetBaseSize()
- {
- return templates[0].size;
- }
- public override Vector2Int GetFullSize()
- {
- return templates[0].size * templateLayout;
- }
- public override TileBase[] FlattenTiles()
- {
- TileBase[] tiles = new TileBase[templates[0].terrain.Length * templates.Length];
- int totalWidth = templates[0].size.x * templateLayout.x;
- int partWidth = templates[0].size.x;
- int yJump = templates[0].size.x * templates[0].size.y * templateLayout.x;
- //Background
- for (int i = 0; i < templates.Length; i++)
- {
- //Calculate where in the grid we are
- int xTemplate = i % templateLayout.x * templates[0].size.x;
- int yTemplate = i / templateLayout.y * totalWidth;
- //Grab the tile out of the correct template
- for (int y = 0; y < templates[0].size.y; y++)
- {
- for (int x = 0; x < templates[0].size.x; x++)
- {
- TileBase tile = templates[i].background[y * templates[i].size.x + x];
- int index = x + xTemplate + y * yTemplate;
- if (tile != null)
- tiles[index] = tile;
- }
- }
- }
- //Terrain
- for (int i = 0; i < templates.Length; i++)
- {
- //Calculate where in the grid we are
- int xTemplate = i % templateLayout.x * templates[0].size.x;
- int yTemplate = i / templateLayout.y * totalWidth;
- //Grab the tile out of the correct template
- for (int y = 0; y < templates[0].size.y; y++)
- {
- for (int x = 0; x < templates[0].size.x; x++)
- {
- TileBase tile = templates[i].terrain[y * templates[i].size.x + x];
- int index = x + xTemplate + y * yTemplate;
- if (tile != null)
- tiles[index] = tile;
- }
- }
- }
- //Foreground
- for (int i = 0; i < templates.Length; i++)
- {
- //Calculate where in the grid we are
- int xTemplate = i % templateLayout.x * templates[0].size.x;
- int yTemplate = i / templateLayout.y * totalWidth;
- //Grab the tile out of the correct template
- for (int y = 0; y < templates[0].size.y; y++)
- {
- for (int x = 0; x < templates[0].size.x; x++)
- {
- TileBase tile = templates[i].foreground[y * templates[i].size.x + x];
- int index = x + xTemplate + y * yTemplate;
- if (tile != null)
- tiles[index] = tile;
- }
- }
- }
- return tiles;
- }
- public override Matrix4x4[] FlattenRotation()
- {
- Matrix4x4[] rotations = new Matrix4x4[templates[0].terrain.Length * templates.Length];
- int totalWidth = templates[0].size.x * templateLayout.x;
- int partWidth = templates[0].size.x;
- int yJump = templates[0].size.x * templates[0].size.y * templateLayout.x;
- //Background
- for (int i = 0; i < templates.Length; i++)
- {
- //Calculate where in the grid we are
- int xTemplate = i % templateLayout.x * templates[0].size.x;
- int yTemplate = i / templateLayout.y * totalWidth;
- //Grab the tile out of the correct template
- for (int y = 0; y < templates[0].size.y; y++)
- {
- for (int x = 0; x < templates[0].size.x; x++)
- {
- TileBase tile = templates[i].background[y * templates[i].size.x + x];
- int index = x + xTemplate + y * yTemplate;
- if (tile != null)
- rotations[index] = templates[i].backgroundRotation[y * templates[i].size.x + x];
- }
- }
- }
- //Terrain
- for (int i = 0; i < templates.Length; i++)
- {
- //Calculate where in the grid we are
- int xTemplate = i % templateLayout.x * templates[0].size.x;
- int yTemplate = i / templateLayout.y * totalWidth;
- //Grab the tile out of the correct template
- for (int y = 0; y < templates[0].size.y; y++)
- {
- for (int x = 0; x < templates[0].size.x; x++)
- {
- TileBase tile = templates[i].terrain[y * templates[i].size.x + x];
- int index = x + xTemplate + y * yTemplate;
- if (tile != null)
- rotations[index] = templates[i].terrainRotation[y * templates[i].size.x + x];
- }
- }
- }
- //Foreground
- for (int i = 0; i < templates.Length; i++)
- {
- //Calculate where in the grid we are
- int xTemplate = i % templateLayout.x * templates[0].size.x;
- int yTemplate = i / templateLayout.y * totalWidth;
- //Grab the tile out of the correct template
- for (int y = 0; y < templates[0].size.y; y++)
- {
- for (int x = 0; x < templates[0].size.x; x++)
- {
- TileBase tile = templates[i].foreground[y * templates[i].size.x + x];
- int index = x + xTemplate + y * yTemplate;
- if (tile != null)
- rotations[index] = templates[i].foregroundRotation[y * templates[i].size.x + x];
- }
- }
- }
- return rotations;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement