A game about forced loneliness, made by TACStudios
at master 148 lines 5.0 kB view raw
1namespace UnityEngine.Rendering 2{ 3 /// <summary>Utility for tiles layout</summary> 4 public static class TileLayoutUtils 5 { 6 /// <summary>Try decompose the givent rect into tiles given the parameter</summary> 7 /// <param name="src">The rect to split</param> 8 /// <param name="tileSize">The size of the tiles</param> 9 /// <param name="main">Computed main area</param> 10 /// <param name="topRow">Computed top row area</param> 11 /// <param name="rightCol">Computed right column area</param> 12 /// <param name="topRight">Computed top right corner area</param> 13 /// <returns>If true, the tiles decomposition is a success</returns> 14 public static bool TryLayoutByTiles( 15 RectInt src, 16 uint tileSize, 17 out RectInt main, 18 out RectInt topRow, 19 out RectInt rightCol, 20 out RectInt topRight) 21 { 22 if (src.width < tileSize || src.height < tileSize) 23 { 24 main = new RectInt(0, 0, 0, 0); 25 topRow = new RectInt(0, 0, 0, 0); 26 rightCol = new RectInt(0, 0, 0, 0); 27 topRight = new RectInt(0, 0, 0, 0); 28 return false; 29 } 30 31 int mainRows = src.height / (int)tileSize; 32 int mainCols = src.width / (int)tileSize; 33 int mainWidth = mainCols * (int)tileSize; 34 int mainHeight = mainRows * (int)tileSize; 35 36 main = new RectInt 37 { 38 x = src.x, 39 y = src.y, 40 width = mainWidth, 41 height = mainHeight, 42 }; 43 topRow = new RectInt 44 { 45 x = src.x, 46 y = src.y + mainHeight, 47 width = mainWidth, 48 height = src.height - mainHeight 49 }; 50 rightCol = new RectInt 51 { 52 x = src.x + mainWidth, 53 y = src.y, 54 width = src.width - mainWidth, 55 height = mainHeight 56 }; 57 topRight = new RectInt 58 { 59 x = src.x + mainWidth, 60 y = src.y + mainHeight, 61 width = src.width - mainWidth, 62 height = src.height - mainHeight 63 }; 64 65 return true; 66 } 67 68 /// <summary>Try decompose the givent rect into rows given the parameter</summary> 69 /// <param name="src">The rect to split</param> 70 /// <param name="tileSize">The size of the tiles</param> 71 /// <param name="main">Computed main area</param> 72 /// <param name="other">Computed other area</param> 73 /// <returns>If true, the tiles decomposition is a success</returns> 74 public static bool TryLayoutByRow( 75 RectInt src, 76 uint tileSize, 77 out RectInt main, 78 out RectInt other) 79 { 80 if (src.height < tileSize) 81 { 82 main = new RectInt(0, 0, 0, 0); 83 other = new RectInt(0, 0, 0, 0); 84 return false; 85 } 86 87 int mainRows = src.height / (int)tileSize; 88 int mainHeight = mainRows * (int)tileSize; 89 90 main = new RectInt 91 { 92 x = src.x, 93 y = src.y, 94 width = src.width, 95 height = mainHeight, 96 }; 97 other = new RectInt 98 { 99 x = src.x, 100 y = src.y + mainHeight, 101 width = src.width, 102 height = src.height - mainHeight 103 }; 104 105 return true; 106 } 107 108 /// <summary>Try decompose the givent rect into columns given the parameter</summary> 109 /// <param name="src">The rect to split</param> 110 /// <param name="tileSize">The size of the tiles</param> 111 /// <param name="main">Computed main area</param> 112 /// <param name="other">Computed other area</param> 113 /// <returns>If true, the tiles decomposition is a success</returns> 114 public static bool TryLayoutByCol( 115 RectInt src, 116 uint tileSize, 117 out RectInt main, 118 out RectInt other) 119 { 120 if (src.width < tileSize) 121 { 122 main = new RectInt(0, 0, 0, 0); 123 other = new RectInt(0, 0, 0, 0); 124 return false; 125 } 126 127 int mainCols = src.width / (int)tileSize; 128 int mainWidth = mainCols * (int)tileSize; 129 130 main = new RectInt 131 { 132 x = src.x, 133 y = src.y, 134 width = mainWidth, 135 height = src.height, 136 }; 137 other = new RectInt 138 { 139 x = src.x + mainWidth, 140 y = src.y, 141 width = src.width - mainWidth, 142 height = src.height 143 }; 144 145 return true; 146 } 147 } 148}