Commit 9d269d1e authored by Cethin's avatar Cethin

Borders now detect adjacency.

To use:
  Attach the borders script and setup the public ints to be the correct size for the borders.   Also, set the sprite to not include the borders in the original import.
parent 0dbdd34f
......@@ -37,6 +37,11 @@ public static class World
setupWithGOs();
}
public static void setup()
{
setup(50, 50 , 3);
}
private static void instantiateMap()
{
map = new GameObject[width][][];
......@@ -113,7 +118,7 @@ public static class World
{
if(x < 0 || y < 0 || z < 0 || x >= width || y >= height || z >= depth)
{
Debug.LogWarning("Pos out of bounds!");
//Debug.LogWarning("Pos out of bounds!");
return false;
}
return true;
......
using UnityEngine;
using System.Collections;
using UnityEditor;
public class Borders : MonoBehaviour
{
......@@ -21,13 +21,42 @@ public class Borders : MonoBehaviour
Color32[] pixels = tex.GetPixels32();
tex.SetPixels32(setBorders(pixels, tex.width, tex.height, Direction.lbrt));
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);
}
}
Direction checkAdjacency()
{
Direction d = Direction.none;
Vector3 pos = transform.position;
if(!World.Ready())
{
World.setup();
}
if(!World.posInBounds(pos + Vector3.up) || World.posIsThis(pos + Vector3.up, (GameObject)PrefabUtility.GetPrefabObject(this)))
{
d |= Direction.t;
}
if(!World.posInBounds(pos + Vector3.left) ||World.posIsThis(pos + Vector3.left, (GameObject)PrefabUtility.GetPrefabObject(this)))
{
d |= Direction.r;
}
if(!World.posInBounds(pos + Vector3.down) ||World.posIsThis(pos + Vector3.down, (GameObject)PrefabUtility.GetPrefabObject(this)))
{
d |= Direction.b;
}
if(!World.posInBounds(pos + Vector3.right) ||World.posIsThis(pos + Vector3.right, (GameObject)PrefabUtility.GetPrefabObject(this)))
{
d |= Direction.l;
}
return d;
}
Color32[] setBorders(Color32[] pixels, int width, int height, Direction d)
{
if((d & Direction.t) > 0) // top
......
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