Commit 0dbdd34f authored by Cethin's avatar Cethin

Added basic setup for adding borders.

Currently adds borders on all sides.
*Need to add check for adjacent grid blocks being the same to set border.
parent d17e7188
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Borders : MonoBehaviour
......@@ -17,12 +16,15 @@ public class Borders : MonoBehaviour
SpriteRenderer sr = GetComponent<SpriteRenderer>();
if(sr != null)
{
Texture2D tex = sr.sprite.texture;
Texture2D texOriginal = sr.sprite.texture;
Texture2D tex = (Texture2D)Instantiate(texOriginal);
Color32[] pixels = tex.GetPixels32();
tex.SetPixels32(setBorders(pixels, tex.width, tex.height, Direction.lbrt));
tex.Apply(false);
sr.sprite = Sprite.Create(tex, sr.sprite.rect, new Vector2(.5f, .5f), sr.sprite.pixelsPerUnit);
}
}
......@@ -32,21 +34,27 @@ public class Borders : MonoBehaviour
{
for(int i = left; i < width - right; i++)
{
for(int j = 0; j < top; j++)
for(int j = height - top*2; j < height - top; j++)
{
pixels[(j+top)*width + i] = pixels[j*width + i];
pixels[j*width + i] = pixels[(j+top)*width + i];
}
}
}
if((d & Direction.r) > 0) // right
{
for(int j = bottom; j < height-top; j++)
{
for(int i = left; i < left*2; i++)
{
pixels[j*width + i] = pixels[j*width + (i-left)];
}
}
}
if((d & Direction.b) > 0) // bottom
{
for(int i = left; i < width - right; i++)
{
for(int j = height - bottom; j < height; j++)
for(int j = bottom; j < bottom*2; j++)
{
pixels[j*width + i] = pixels[(j-bottom)*width + i];
}
......@@ -54,7 +62,13 @@ public class Borders : MonoBehaviour
}
if((d & Direction.l) > 0) // left
{
for(int j = bottom; j < height-top; j++)
{
for(int i = width - right*2; i < width-right; i++)
{
pixels[j*width + i] = pixels[j*width + (i+right)];
}
}
}
return pixels;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment