Commit 1a6a7e32 authored by Luke A Smith's avatar Luke A Smith

Merge branch 'borders' into 'master'

Moved setup from Start() to MapEditor button.

See merge request !18
parents 8c23579b cb83e93d
......@@ -146,5 +146,9 @@ public class MapEditorEditor : Editor
// Toggle on field
MapEditor.On = GUILayout.Toggle(MapEditor.On, "ON");
// Initialize Borders
if(GUILayout.Button("Initialize Borders"))
Borders.initializeAll();
}
}
......@@ -4,28 +4,37 @@ using UnityEditor;
public class Borders : MonoBehaviour
{
public int top = 0, right = 0, bottom = 0, left = 0; // Border sizes by pixel
public bool setup = false;
private enum Direction{none, t, r, rt, b, bt, br, brt, l, lt, lr, lrt, lb, lbt, lbr, lbrt}
// Binary representation:
// lbrt
// 0000
// Use this for initialization
void Start ()
/*void Start()
{
SpriteRenderer sr = GetComponent<SpriteRenderer>();
if(sr != null)
if(!setup)
{
Texture2D texOriginal = sr.sprite.texture;
Texture2D tex = (Texture2D)Instantiate(texOriginal);
initializeAll();
}
}*/
Color32[] pixels = tex.GetPixels32();
void init ()
{
SpriteRenderer sr = GetComponent<SpriteRenderer>();
if (sr != null)
{
Texture2D texOriginal = sr.sprite.texture;
Texture2D tex = (Texture2D)Instantiate(texOriginal);
tex.SetPixels32(setBorders(pixels, tex.width, tex.height, checkAdjacency()));
tex.Apply(false);
Color32[] pixels = tex.GetPixels32();
sr.sprite = Sprite.Create(tex, sr.sprite.rect, new Vector2(.5f, .5f), sr.sprite.pixelsPerUnit);
}
tex.SetPixels32(setBorders(pixels, tex.width, tex.height, checkAdjacency()));
tex.Apply(false);
sr.sprite = Sprite.Create(tex, sr.sprite.rect, new Vector2(.5f, .5f), sr.sprite.pixelsPerUnit);
setup = true;
}
}
Direction checkAdjacency()
......@@ -61,7 +70,6 @@ public class Borders : MonoBehaviour
{
if((d & Direction.t) > 0) // top
{
Debug.Log("set top");
for(int i = left; i < width - right; i++)
{
for(int j = height - top*2; j < height - top; j++)
......@@ -103,4 +111,14 @@ public class Borders : MonoBehaviour
return pixels;
}
public static void initializeAll()
{
Borders[] bs = GameObject.FindObjectsOfType<Borders>();
foreach(Borders b in bs)
{
b.init();
}
}
}
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