Commit 3d850791 authored by Cethin's avatar Cethin
Browse files

Optimized editor. Correctly checks for same existing prefab at position and...

Optimized editor. Correctly checks for same existing prefab at position and dosn't create new instance if the same thing already exists there.
parent abe40ee9
...@@ -92,18 +92,24 @@ public class MapEditor : MonoBehaviour ...@@ -92,18 +92,24 @@ public class MapEditor : MonoBehaviour
if(Tile != null) if(Tile != null)
{ {
GameObject go = (GameObject)GameObject.Instantiate(Tile, new Vector3(pos.x, pos.y, Layer), Quaternion.identity); if(!World.posIsThis(pos, Tile))
go = PrefabUtility.ConnectGameObjectToPrefab(go, Tile);
go.transform.position = new Vector3(pos.x, pos.y, Layer);
SpriteRenderer sr = go.GetComponent<SpriteRenderer>();
if(sr != null)
{ {
sr.sortingOrder = layer * -World.SORTING_ORDER_MULT; Debug.Log("new");
GameObject go = (GameObject)GameObject.Instantiate(Tile, new Vector3(pos.x, pos.y, Layer), Quaternion.identity);
go = PrefabUtility.ConnectGameObjectToPrefab(go, Tile);
go.transform.position = new Vector3(pos.x, pos.y, Layer);
SpriteRenderer sr = go.GetComponent<SpriteRenderer>();
if(sr != null)
{
sr.sortingOrder = layer * -World.SORTING_ORDER_MULT;
}
go.transform.parent = Tiles;
World.set(pos, layer, go);
} }
go.transform.parent = Tiles; else
World.set(pos, layer, go); Debug.Log("new");
} }
else else
{ {
......
...@@ -61,7 +61,8 @@ public static class World ...@@ -61,7 +61,8 @@ public static class World
{ {
if(!posInBounds(x, y, z)) if(!posInBounds(x, y, z))
return false; return false;
destroyPos(x,y,z);
destroyPos(x, y, z);
map[x][y][z] = go; map[x][y][z] = go;
return true; return true;
...@@ -99,7 +100,8 @@ public static class World ...@@ -99,7 +100,8 @@ public static class World
{ {
if(!posInBounds(x, y, z)) if(!posInBounds(x, y, z))
return false; return false;
return PrefabUtility.GetPrefabObject(map[x][y][z]) == PrefabUtility.GetPrefabObject(go);
return PrefabUtility.GetPrefabParent(map[x][y][z]) == go;
} }
......
m_EditorVersion: 5.5.0xf3Linux m_EditorVersion: 5.3.5f1
m_StandardAssetsVersion: 0
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