Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Tilemaps;
- namespace BaseProject
- {
- public class Template : TemplateBase
- {
- //public int level;
- //Connections
- public bool up;
- public bool right;
- public bool down;
- public bool left;
- //Template size
- public Vector2Int size = new Vector2Int(40, 24);
- //Tiles
- public TileBase[] foreground;
- public TileBase[] terrain;
- public TileBase[] background;
- //Rotations
- public Matrix4x4[] foregroundRotation;
- public Matrix4x4[] terrainRotation;
- public Matrix4x4[] backgroundRotation;
- //Extra data
- public TemplateMaster master;
- public TemplateColliderData[] colliders;
- public TemplatePrefabData[] prefabs;
- public override Vector2Int GetBaseSize()
- {
- return size;
- }
- public override Template Copy()
- {
- Template newTemplate = new Template();
- CopyMetadata(newTemplate);
- CopyTiles(newTemplate);
- return newTemplate;
- }
- public override Template CopyFlattened()
- {
- Template newTemplate = new Template();
- CopyMetadata(newTemplate);
- newTemplate.background = new TileBase[background.Length];
- newTemplate.terrain = FlattenTiles();
- newTemplate.foreground = new TileBase[foreground.Length];
- return newTemplate;
- }
- public override void CopyMetadata(Template template)
- {
- //template.level = this.level;
- template.up = this.up;
- template.right = this.right;
- template.down = this.down;
- template.left = this.left;
- }
- public override void CopyTiles(Template template)
- {
- int i = 0;
- for (i = 0; i < background.Length; i++)
- {
- template.background[i] = background[i];
- }
- for (i = 0; i < terrain.Length; i++)
- {
- template.terrain[i] = terrain[i];
- }
- for (i = 0; i < foreground.Length; i++)
- {
- template.foreground[i] = foreground[i];
- }
- }
- public override TileBase[] FlattenTiles()
- {
- TileBase[] tiles = new TileBase[terrain.Length];
- int i = 0;
- for (i = 0; i < background.Length; i++)
- {
- if (background[i] != null)
- tiles[i] = background[i];
- }
- for (i = 0; i < terrain.Length; i++)
- {
- if (terrain[i] != null)
- tiles[i] = terrain[i];
- }
- for (i = 0; i < foreground.Length; i++)
- {
- if (foreground[i] != null)
- tiles[i] = foreground[i];
- }
- return tiles;
- }
- public override Matrix4x4[] FlattenRotation()
- {
- Matrix4x4[] tiles = new Matrix4x4[terrain.Length];
- int i = 0;
- for (i = 0; i < background.Length; i++)
- {
- if (background[i] != null)
- tiles[i] = backgroundRotation[i];
- }
- for (i = 0; i < terrain.Length; i++)
- {
- if (terrain[i] != null)
- tiles[i] = terrainRotation[i];
- }
- for (i = 0; i < foreground.Length; i++)
- {
- if (foreground[i] != null)
- tiles[i] = foregroundRotation[i];
- }
- return tiles;
- }
- }
- [System.Serializable]
- public class TemplateColliderData
- {
- public UnityEngine.Vector2Int location;
- public Vector2 size;
- public Vector2 offset;
- public GameObject prefab; //Defaults to box if null
- }
- [System.Serializable]
- public class TemplatePrefabData
- {
- public GameObject prefab;
- public Vector3 position;
- public Quaternion rotation;
- public Vector3 scale;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment