Guest User

Template

a guest
May 11th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.24 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Tilemaps;
  6.  
  7. namespace BaseProject
  8. {
  9.     public class Template : TemplateBase
  10.     {
  11.         //public int level;
  12.  
  13.         //Connections
  14.         public bool up;
  15.         public bool right;
  16.         public bool down;
  17.         public bool left;
  18.  
  19.         //Template size
  20.         public Vector2Int size = new Vector2Int(40, 24);
  21.  
  22.         //Tiles
  23.         public TileBase[] foreground;
  24.         public TileBase[] terrain;
  25.         public TileBase[] background;
  26.  
  27.         //Rotations
  28.  
  29.         public Matrix4x4[] foregroundRotation;
  30.         public Matrix4x4[] terrainRotation;
  31.         public Matrix4x4[] backgroundRotation;
  32.  
  33.         //Extra data
  34.         public TemplateMaster master;
  35.         public TemplateColliderData[] colliders;
  36.         public TemplatePrefabData[] prefabs;
  37.  
  38.         public override Vector2Int GetBaseSize()
  39.         {
  40.             return size;
  41.         }
  42.  
  43.         public override Template Copy()
  44.         {
  45.             Template newTemplate = new Template();
  46.             CopyMetadata(newTemplate);
  47.             CopyTiles(newTemplate);
  48.             return newTemplate;
  49.         }
  50.  
  51.         public override Template CopyFlattened()
  52.         {
  53.             Template newTemplate = new Template();
  54.             CopyMetadata(newTemplate);
  55.             newTemplate.background = new TileBase[background.Length];
  56.             newTemplate.terrain = FlattenTiles();
  57.             newTemplate.foreground = new TileBase[foreground.Length];
  58.             return newTemplate;
  59.         }
  60.  
  61.         public override void CopyMetadata(Template template)
  62.         {
  63.             //template.level = this.level;
  64.             template.up = this.up;
  65.             template.right = this.right;
  66.             template.down = this.down;
  67.             template.left = this.left;
  68.         }
  69.  
  70.         public override void CopyTiles(Template template)
  71.         {
  72.             int i = 0;
  73.             for (i = 0; i < background.Length; i++)
  74.             {
  75.                 template.background[i] = background[i];
  76.             }
  77.             for (i = 0; i < terrain.Length; i++)
  78.             {
  79.                 template.terrain[i] = terrain[i];
  80.             }
  81.             for (i = 0; i < foreground.Length; i++)
  82.             {
  83.                 template.foreground[i] = foreground[i];
  84.             }
  85.         }
  86.  
  87.         public override TileBase[] FlattenTiles()
  88.         {
  89.             TileBase[] tiles = new TileBase[terrain.Length];
  90.             int i = 0;
  91.             for (i = 0; i < background.Length; i++)
  92.             {
  93.                 if (background[i] != null)
  94.                     tiles[i] = background[i];
  95.             }
  96.             for (i = 0; i < terrain.Length; i++)
  97.             {
  98.                 if (terrain[i] != null)
  99.                     tiles[i] = terrain[i];
  100.             }
  101.             for (i = 0; i < foreground.Length; i++)
  102.             {
  103.                 if (foreground[i] != null)
  104.                     tiles[i] = foreground[i];
  105.             }
  106.             return tiles;
  107.         }
  108.  
  109.         public override Matrix4x4[] FlattenRotation()
  110.         {
  111.             Matrix4x4[] tiles = new Matrix4x4[terrain.Length];
  112.             int i = 0;
  113.             for (i = 0; i < background.Length; i++)
  114.             {
  115.                 if (background[i] != null)
  116.                     tiles[i] = backgroundRotation[i];
  117.             }
  118.             for (i = 0; i < terrain.Length; i++)
  119.             {
  120.                 if (terrain[i] != null)
  121.                     tiles[i] = terrainRotation[i];
  122.             }
  123.             for (i = 0; i < foreground.Length; i++)
  124.             {
  125.                 if (foreground[i] != null)
  126.                     tiles[i] = foregroundRotation[i];
  127.             }
  128.             return tiles;
  129.         }
  130.     }
  131.  
  132.     [System.Serializable]
  133.     public class TemplateColliderData
  134.     {
  135.         public UnityEngine.Vector2Int location;
  136.         public Vector2 size;
  137.         public Vector2 offset;
  138.         public GameObject prefab; //Defaults to box if null
  139.     }
  140.  
  141.     [System.Serializable]
  142.     public class TemplatePrefabData
  143.     {
  144.         public GameObject prefab;
  145.         public Vector3 position;
  146.         public Quaternion rotation;
  147.         public Vector3 scale;
  148.     }
  149. }
  150.  
Advertisement
Add Comment
Please, Sign In to add comment