private static void averageCenterPoints(MapGraph graph) { foreach (var node in graph.nodes) { node.centerPoint = new Vector3(node.centerPoint.x, node.GetCorners().Average(x => x.y), node.centerPoint.z); } }
public static Texture2D GenerateTexture(MapGraph map, int meshSize, int textureSize, List <MapNodeTypeColor> colours, bool drawBoundries, bool drawTriangles, bool drawCenters) { CreateDrawingMaterial(); var texture = RenderGLToTexture(map, textureSize, meshSize, drawingMaterial, colours, drawBoundries, drawTriangles, drawCenters); return(texture); }
private static void SetBeaches(MapGraph graph) { // Set any nodes who have a neighbour of type SaltWater to type Beach. foreach (var node in graph.FilterNodes(MapGraph.NodeType.Grass)) { foreach (var neighbour in node.GetNeighbourNodes()) { if (neighbour.nodeType == MapGraph.NodeType.SaltWater) { node.nodeType = MapGraph.NodeType.Beach; break; } } } // Perform a second pass, converting any Grass nodes who have 4 or more // neighbours of type Beach to Beach. foreach (var node in graph.FilterNodes(MapGraph.NodeType.Grass)) { if (node.GetNeighbourNodes().Where(neighbour => neighbour.nodeType == MapGraph.NodeType.Beach).Count() >= 4) { node.nodeType = MapGraph.NodeType.Beach; } } }
// This method loads the information pertained originally in JSON form and creates a graph with it. public static MapGraph <Region> loadIntoGraph() { MapGraph <Region> graphRegions = new MapGraph <Region>(); List <Region> regionsToAdd = loadMapInfo(); foreach (Region region in regionsToAdd) { graphRegions.addVertex(region); } foreach (Region region in regionsToAdd) { foreach (Region secondRegion in regionsToAdd) { foreach (String border in region.Borders) { if (border.Equals(secondRegion.name)) { graphRegions.addEdge(region, secondRegion, region.size); } } } } return(graphRegions); }
void Start() { //params du menu xAmount = PlayerPrefs.GetInt("levelWidth"); zAmount = PlayerPrefs.GetInt("levelDepth"); tileAmount = xAmount * zAmount; playerAvatarsAmount = PlayerPrefs.GetInt("nbCharacters"); enemyAvatarsAmount = PlayerPrefs.GetInt("nbEnemies"); decorAmount = PlayerPrefs.GetInt("nbDecors"); //init levelParent = new GameObject().transform; levelParent.name = "LevelParent"; playerAvatarsParent = new GameObject().transform; playerAvatarsParent.name = "playerAvatarsParent"; enemiesParent = new GameObject().transform; enemiesParent.name = "enemiesParent"; outBoundaries = GameObject.Find("AABB"); outBoundaries.transform.localScale = (xAmount + 5) * tileSize * new Vector3(1, 1, 1); outBoundaries.transform.position = xAmount / 2 * tileSize * new Vector3(1, 0, 1); map = new MapGraph.Node <MapElement> [xAmount, zAmount]; graphStruct = new MapGraph(); indexX = 0; indexZ = 0; //generation du level StartCoroutine(GenerateLevel()); }
public KeyValPair(Vector3 key, Vector3 val, MapGraph graph) { keyX = key.x; keyY = key.y; keyZ = key.z; valX = val.x; valY = val.y; valZ = val.z; connections = new List <KeyValPair>(); foreach (Vector3 neighbor in graph.nodes[key].neighbors) { // go through each key value pair and store the key foreach (KeyValuePair <Vector3, GraphNode> pair in graph.nodes) { if (pair.Value.Equals(neighbor)) { KeyValPair pseudoConnect = new KeyValPair(pair.Key); connections.Add(pseudoConnect); break; } } } }
public static Texture2D generate(MapGraph map, Config conf) { CreateDrawingMaterial(); var texture = RenderGLToTexture(map, conf.textureSize, conf.meshSize, drawingMaterial); return(texture); }
private void GenerateEnemies(int nb, MapGraph map) { for (int i = 0; i < nb; i++) { Vector3 pos = map.GetRandomNode().center; pos.y = 1; GameObject enemy = Instantiate(p_enemy1, pos, new Quaternion(), transform); enemy.SetActive(false); Golem1Controller controller = enemy.GetComponent <Golem1Controller>(); if (controller != null) { int nbPatrol = 4; Vector3[] patrol = new Vector3[nbPatrol]; for (int p = 0; p < nbPatrol; p++) { patrol[p] = map.GetRandomNode().center; } controller.SetPatrol(patrol); controller.enabled = false; enemy.SetActive(true); } } }
private static Texture2D RenderGLToTexture(MapGraph map, int textureSize, int meshSize, Material material) { // get a temporary RenderTexture RenderTexture renderTexture = RenderTexture.GetTemporary(textureSize, textureSize); // set the RenderTexture as global target (that means GL too) RenderTexture.active = renderTexture; // clear GL GL.Clear(false, true, Color.white); GL.sRGBWrite = false; // render GL immediately to the active render texture RenderObjectTexture(map, material, textureSize, meshSize); // read the active RenderTexture into a new Texture2D Texture2D newTexture = new Texture2D(textureSize, textureSize); newTexture.ReadPixels(new Rect(0, 0, textureSize, textureSize), 0, 0); // apply pixels and compress bool applyMipsmaps = false; newTexture.Apply(applyMipsmaps); bool highQuality = true; newTexture.Compress(highQuality); // clean up after the party RenderTexture.active = null; RenderTexture.ReleaseTemporary(renderTexture); // return the goods return(newTexture); }
public const int MAX_WALL = 7; //can change this to create a geant map // Start is called before the first frame update void Start() { float begin = Time.realtimeSinceStartup; this.seed = Mathf.FloorToInt(Random.value * int.MaxValue); Random.InitState(seed); MapGeneration(); surface.BuildNavMesh(); surface.AddData(); //Add the surface to the singleton Nav Mesh NavMeshTriangulation navMeshTriangulation = NavMesh.CalculateTriangulation(); DebugDisplayTriangle(navMeshTriangulation); MapGraph mapGraph = GenerateGraph(navMeshTriangulation); mapGraph.DeugDrawGrahp(); Debug.Log("Generation took " + (Time.realtimeSinceStartup - begin) + " seconds"); GenerateLights(mapGraph); TemporaryPlayerGeneration(mapGraph); surface.RemoveData(); //Remove the surface to the singleton NavMesh surface_enemy.BuildNavMesh(); GenerateEnemies(5, mapGraph); gameObject.BroadcastMessage("StartTheGame"); }
private static void DrawToRenderTexture(MapGraph map, Material material, int textureSize, int meshSize, List <MapGraph.NodeTypeColour> colours, bool drawBoundries, bool drawTriangles) { material.SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(0, meshSize, 0, meshSize); GL.Viewport(new Rect(0, 0, textureSize, textureSize)); var coloursDictionary = new Dictionary <MapGraph.NodeType, Color>(); foreach (var colour in colours) { if (!coloursDictionary.ContainsKey(colour.type)) { coloursDictionary.Add(colour.type, colour.colour); } } DrawNodeTypes(map, coloursDictionary); if (drawBoundries) { DrawEdges(map, Color.black); } if (drawTriangles) { DrawDelaunayEdges(map, Color.red); } GL.PopMatrix(); }
private void GenerateLights(MapGraph mapGraph) { GameObject lights = new GameObject { name = "Lights" }; //should look if we can bake the light at the beginning foreach (MapGraph.Node node in mapGraph) { if (NavMesh.FindClosestEdge(node.center, out NavMeshHit hit, NavMesh.AllAreas)) { Collider[] res = Physics.OverlapSphere(hit.position, 10); bool adding = true; foreach (Collider c in res) { if (c.gameObject.GetComponent <Light>() != null || c.gameObject.GetComponentInChildren <Light>() != null) { adding = false; } } if (adding) { //adapt the position to the prefab Vector3 position = hit.position; position.y = (MIN_WALL + MAX_WALL) / 4f + Random.Range(-0.5f, 0.5f); Instantiate(p_lamp, position, Quaternion.AngleAxis(30, new Vector3(hit.normal.z, 0, hit.normal.x)), lights.transform); //TODO: Rotation is not okay } } } }
private static void RenderObjectTexture(MapGraph map, Material material, int textureSize, int meshSize) { material.SetPass(0); GL.PushMatrix(); GL.LoadPixelMatrix(0, meshSize, 0, meshSize); GL.Viewport(new Rect(0, 0, textureSize, textureSize)); GL.Begin(GL.TRIANGLES); foreach (var node in map.nodes) { var color = BiomeColors.colors.ContainsKey(node.nodeType) ? BiomeColors.colors[node.nodeType] : Color.red; GL.Color(color); foreach (var edge in node.GetEdges()) { var start = edge.previous.destination; var end = edge.destination; GL.Vertex3(node.centerPoint.x, node.centerPoint.z, 0); GL.Vertex3(start.x, start.z, 0); GL.Vertex3(end.x, end.z, 0); } } GL.End(); GL.PopMatrix(); }
public static void GenerateMap(MapGraph graph) { // Initially, set all nodes to Grass. foreach (var node in graph.nodesByCenterPosition.Values) { node.nodeType = MapGraph.NodeType.Grass; } SetLowNodesToWater(graph, 0.4f); FillOcean(graph); SetBeaches(graph); AddMountains(graph, 5f, 5f, 8f, 6.5f, 11.5f); AddTallGrass(graph, 2f, 2.5f); // Average the center points based on the average height of the corner // vertices. foreach (var node in graph.nodesByCenterPosition.Values) { node.centerPoint = new Vector3( node.centerPoint.x, node.GetCorners().Average(x => x.position.y), node.centerPoint.z ); } }
private static void SetLowNodesToWater(MapGraph graph, float cutoff) { foreach (var node in graph.nodesByCenterPosition.Values) { // Skip any nodes whose elevation exceed the `cutoff` value. if (node.centerPoint.y > cutoff) { continue; } // If any edge elevations exceed the cutoff, we will not set the // node to FreshWater. var allZero = true; foreach (var edge in node.GetEdges()) { if (edge.destination.position.y > cutoff) { allZero = false; break; } } if (allZero) { node.nodeType = MapGraph.NodeType.FreshWater; } } }
private static void AddMountains( MapGraph graph, float minRockyElevation, float minRockyHeightDifference, float minElevation, float minHeightDifference, float minSnowElevation ) { foreach (var node in graph.nodesByCenterPosition.Values) { if (node.elevation > minElevation || node.GetHeightDifference() > minHeightDifference) { node.nodeType = MapGraph.NodeType.Mountain; } else if (node.elevation > minRockyElevation || node.GetHeightDifference() > minRockyHeightDifference) { node.nodeType = MapGraph.NodeType.Rocky; } if (node.elevation > minSnowElevation) { node.nodeType = MapGraph.NodeType.Snow; } } }
void Awake() { gameManager = GameObject.FindGameObjectWithTag("Game manager"); graphStruct = gameManager.GetComponent <LevelGenerator>().getGraph(); graph = graphStruct.NodeSet; difficultyIsHard = System.Convert.ToBoolean(PlayerPrefs.GetInt("difficulty")); maxDistance = PlayerPrefs.GetInt("levelWidth"); }
// Update is called once per frame //void Update () { //} private MapGraph InitMapGraph() { MapGraph mapGraph = Instantiate(mapGraphPrefab) .GetComponent <MapGraph>(); mapGraph.SetDimensions(ROW_COUNT, COL_COUNT); return(mapGraph); }
private static Texture2D RenderGLToTexture(MapGraph map, int textureSize, int meshSize, Material material, List <MapGraph.NodeTypeColour> colours, bool drawBoundries, bool drawTriangles) { var renderTexture = CreateRenderTexture(textureSize, Color.white); DrawToRenderTexture(map, material, textureSize, meshSize, colours, drawBoundries, drawTriangles); return(CreateTextureFromRenderTexture(textureSize, renderTexture)); }
private void OnDestroy() { if (m_Map != null) { m_Map.searchPath.onStep -= MapPathfinding_OnStep; m_Map = null; } }
public static void Spawn(MapGraph mapGraph, Transform container, AnimalSettings settings, int seed) { AnimalSpawner.mapGraph = mapGraph; AnimalSpawner.prng = new System.Random(seed); var spawner = new PrefabSpawner(container); settings.speciesSettings.ForEach(s => SpawnSpecies(spawner, s)); }
private static Texture2D RenderGLToTexture(MapGraph map, int textureSize, int meshSize, Material material, List <MapNodeTypeColor> colours, bool drawBoundries, bool drawTriangles, bool drawCenters) { var renderTexture = CreateRenderTexture(textureSize, Color.white); // render GL immediately to the active render texture // DrawToRenderTexture(map, material, textureSize, meshSize, colours, drawBoundries, drawTriangles, drawCenters); return(CreateTextureFromRenderTexture(textureSize, renderTexture)); }
private static void FillOcean(MapGraph graph) { var startNode = graph.nodesByCenterPosition .FirstOrDefault(node => node.Value.IsEdge() && node.Value.nodeType == MapGraph.NodeType.FreshWater) .Value; FloodFill(startNode, MapGraph.NodeType.FreshWater, MapGraph.NodeType.SaltWater); }
public static void generate(MapGraph graph, Config conf) { setNodesWithElevationAndMoisture(graph, conf.moisture); setLowNodesToWater(graph, 0.2f); fillOcean(graph); setBeaches(graph); averageCenterPoints(graph); }
private static void SetNodesToGrass(MapGraph graph) { foreach (var node in graph.nodesByCenterPosition.Values) { if (node.nodeType != MapGraph.MapNodeType.Error) { node.nodeType = MapGraph.MapNodeType.Grass; } } }
private void TemporaryPlayerGeneration(MapGraph mapGraph) { Vector3 pos = mapGraph.GetNode(0).center; pos.y = 1; GameObject go = Instantiate(p_player, pos, new Quaternion()); go.tag = "Player"; }
private static void SetEdgesToWater(MapGraph graph) { foreach (var node in graph.nodesByCenterPosition.Values) { if (node.IsEdge()) { node.nodeType = MapGraph.MapNodeType.FreshWater; } } }
public static void Spawn(MapGraph mapGraph, Transform container, EnvironmentSettings settings, int seed) { EnvironmentSpawner.mapGraph = mapGraph; EnvironmentSpawner.prng = new System.Random(seed); EnvironmentSpawner.settings = settings; var spawner = new PrefabSpawner(container); SpawnTrees(spawner); SpawnRocks(spawner); }
private void Setup() { var map = Curio.GetMap(); if (Graph?.Map != map) { Graph = new MapGraph(map); Graph.Recalculate(); } Graph.RecalculateCurios(new[] { Curio }); }
public static Mesh generate(MapGraph mapGraph, int meshSize) { var vertices = new List <Vector3>(); var indices = new List <int>(); foreach (var node in mapGraph.nodes) { vertices.Add(node.centerPoint); var centerIndex = vertices.Count - 1; var edges = node.GetEdges().ToList(); int lastIndex = 0; int firstIndex = 0; for (var i = 0; i < edges.Count(); i++) { if (i == 0) { vertices.Add(edges[i].previous.destination); var i2 = vertices.Count - 1; vertices.Add(edges[i].destination); var i3 = vertices.Count - 1; addTriangle(indices, centerIndex, i2, i3); firstIndex = i2; lastIndex = i3; } else if (i < edges.Count() - 1) { vertices.Add(edges[i].destination); var currentIndex = vertices.Count - 1; addTriangle(indices, centerIndex, lastIndex, currentIndex); lastIndex = currentIndex; } else { addTriangle(indices, centerIndex, lastIndex, firstIndex); } } } Vector2[] uvs = new Vector2[vertices.Count]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(vertices[i].x / meshSize, vertices[i].z / meshSize); } var mesh = new Mesh { vertices = vertices.ToArray(), triangles = indices.ToArray(), uv = uvs }; return(mesh); }
public void createMapGraph(List<RoomArea> roomareas,float edgerelocationrate) { if (roomareas.Count == 0) { Debug.LogAssertion("Empty RoomAreas."); throw new ArgumentException(); } //Vector2 upperlimit = AverageRoomSize * 100f; List<Vertex> vertexs = new List<Vertex>(); foreach (RoomArea area in roomareas) { Vertex v = new Vertex(area.CenterToInt); vertexs.Add(v); } Debug.Log("v: "+vertexs.Count); List<Node> nodes = new List<Node>(); List<Edge> edges = new List<Edge>(); DelaunayTriangles dt = new DelaunayTriangles(new Rect(Vector2.zero, MaxMapSize), vertexs); if (vertexs.Count >= 3) { dt.DelaunayTrianglation(); nodes = Node.createNodes(new List<Triangle>(dt.TriangleSet.Keys).ToArray()); edges = Edge.createEdges(new List<Triangle>(dt.TriangleSet.Keys).ToArray()); //Debug.Log(string.Format("N:{0},E:{1}", nodes.Count, edges.Count)); } else{ Debug.Log("Vertex amount lower than 3!!!"); foreach (Vertex v in vertexs) { nodes.Add(new Node(v.Position)); } Node n1 = nodes[0]; Node n2 = nodes[nodes.Count - 1]; float cost = (n1.Position - n2.Position).sqrMagnitude; edges.Add(new Edge(n1,n2,cost)); } SpanningTree spt = new SpanningTree(nodes.ToArray(), edges.ToArray()); Debug.LogFormat("N:{0},E:{1}",nodes.Count,edges.Count); //Debug.Log("Create Tree"); spt.createTree(0); //Debug.Log("Create Tree End"); ////Debug.Log("After: " + RoomAreas.Count); var es = new List<Edge>(spt.NewEdgeList); edges.RemoveAll(e => spt.NewEdgeList.Contains(e)); ////Debug.Log("Edgecount: " + edges.Count); int limit = (int)(edges.Count * edgerelocationrate); ////Debug.Log("Limit: "+limit+","+edgerelocationrate); for (int i = 0; i < limit; i++) { //////Debug.Log("Edgecount: "+edges.Count); Edge adding = edges[GameController.Rnd.Next(edges.Count)]; es.Add(adding); edges.Remove(adding); if (edges.Count == 0) break; } //es.Distinct(); Mapgraph = new MapGraph(spt.NewNodeList, es,dt,spt,roomareas); }
void reset() { RoomAreas = new List<RoomArea>(); PathWays = new List<Pathway>(); Mapgraph = new MapGraph(); }
void createMapGraph(List<RoomArea> roomareas, float edgerelocationrate) { Debug.logger.logEnabled = false; //Vector2 upperlimit = AverageRoomSize * 100f; List<Vertex> vertexs = new List<Vertex>(); foreach (RoomArea area in roomareas) { Vertex v = new Vertex(area.CenterToInt); vertexs.Add(v); } Debug.logger.LogFormat(LogType.Log,"v:{0} A:{1}",vertexs.Count,roomareas.Count); List<Node> nodes = new List<Node>(); List<Edge> edges = new List<Edge>(); DelaunayTriangles dt = new DelaunayTriangles(new Rect(Vector2.zero, DgParam.MaxMapSize), vertexs); if (vertexs.Count > 3) { dt.DelaunayTrianglation(); nodes = Node.createNodes(new List<Triangle>(dt.TriangleSet.Keys).ToArray()); edges = Edge.createEdges(new List<Triangle>(dt.TriangleSet.Keys).ToArray()); //Debug.Log(string.Format("N:{0},E:{1}", nodes.Count, edges.Count)); } else { Debug.Log("Vertex amount lower than 3!!!"); List<Node> ns = new List<Node>(); List<Node> select = new List<Node>(); List<Edge> eds = new List<Edge>(); vertexs.ForEach(v => ns.Add(new Node(v.Position))); int maxcount = Mathf.Max(0,ns.Count - 1); for (int i = 0; i < maxcount; i++) { var rest = ns.FindAll(n=> !select.Contains(n)); var sel = rest[Rnd.Next(rest.Count)]; select.Add(sel); } var rest2 = ns.FindAll(n => !select.Contains(n)); rest2.ForEach(s2 => { select.ForEach(s1 => { eds.Add(new Edge(s2,s1,(s1.Position-s2.Position).sqrMagnitude )); }); }); nodes = ns; edges = eds; } var restv = vertexs.FindAll( v => nodes.Find(n => n.Position.Equals(v.Position))==null); Debug.logger.LogFormat(LogType.Warning,"Rest Vertex:{0}", restv.Count()); if (restv.Count != 0) { restv.ForEach(v => { var n1 = new Node(v.Position); var n2 = nodes[Rnd.Next(nodes.Count)]; nodes.Add(n1); edges.Add(new Edge(n1,n2,(n1.Position - n2.Position).sqrMagnitude)); }); } SpanningTree spt = new SpanningTree(nodes.ToArray(), edges.ToArray()); Debug.logger.LogFormat(LogType.Log,"N:{0},E:{1}", nodes.Count, edges.Count); //Debug.Log("Create Tree"); spt.createTree(0); //Debug.Log("Create Tree End"); ////Debug.Log("After: " + RoomAreas.Count); var es = new List<Edge>(spt.NewEdgeList); edges.RemoveAll(e => spt.NewEdgeList.Contains(e)); ////Debug.Log("Edgecount: " + edges.Count); int limit = (int)(edges.Count * edgerelocationrate); ////Debug.Log("Limit: "+limit+","+edgerelocationrate); for (int i = 0; i < limit; i++) { //////Debug.Log("Edgecount: "+edges.Count); Edge adding = edges[Rnd.Next(edges.Count)]; es.Add(adding); edges.Remove(adding); if (edges.Count == 0) break; } //es.Distinct(); Mapgraph = new MapGraph(spt.NewNodeList, es, dt, spt, roomareas); Debug.logger.logEnabled = true; }
public void generatePathways2(MapGraph graph,RndGenerator rnd) { Pathways = new List<Pathway>(); foreach (Edge e in graph.EdgeList) { RoomArea r1 = Rooms.Find(room => room.Area.CenterToInt.Equals(e.Start.Position)).Area; RoomArea r2 = Rooms.Find(room => room.Area.CenterToInt.Equals(e.End.Position)).Area; //Rect a1 = Array.Find<Rect>(this.SplitFloorRect, rect => rect.Contains(r1.Center)); //Rect a2 = Array.Find<Rect>(this.SplitFloorRect, rect => rect.Contains(r2.Center)); float deg = MathUtil.SignedAngle(r1.Center, r2.Center); MathUtil.Quadrant q = MathUtil.getQuadrant(deg); var sides = RoomArea.getRoomAreaSide(q, deg); var sside = sides[rnd.Next(sides.Length)]; sides = RoomArea.getRoomAreaSide(MathUtil.getReveseQuadrant(q), -deg); var eside = sides[rnd.Next(sides.Length)]; var pws = createPathWays(r1, r2, sside, eside,rnd); Pathways.AddRange(pws); } }
public void generatePathway(MapGraph graph) { List<Pathway> ret = new List<Pathway>(); //Debug.Log("Edge: "+graph.EdgeList.Count); foreach (Edge edge in graph.EdgeList) { //Debug.Log("E:"+edge.ToString()); Node start = edge.Start; Node end = edge.End; /* foreach (Room r in Rooms) { Debug.Log(start.Position +"=="+r.CenterToInt+" = "+r.CenterToInt.Equals(start.Position)); Debug.Log(r.Position+","+r.Size); } */ Room room1 = Rooms.Find(r => r.Area.CenterToInt.Equals(start.Position)); Room room2 = Rooms.Find(r => r.Area.CenterToInt.Equals(end.Position)); // startがendより右及び上に位置するとdistの各成分はマイナスになる Vector2 dist = (end.Position - start.Position); Vector2 midpos = start.Position + dist / 2; float angle = Mathf.Atan2(dist.x, dist.y) * Mathf.Rad2Deg; Vector2 norm = dist.normalized; Vector2 posdelta = new Vector2(Mathf.CeilToInt(norm.x), Mathf.CeilToInt(norm.y)); //Debug.Log("S: " + start.Position + ", E:" + end.Position); //Debug.Log("A: " + angle + ", " + norm); // 2つの部屋がx,yそれぞれの軸で近接しているか判定する /* 近接とみなす条件 ・ノードの中間点が境界内に含まれている場合 境界の位置 ・start部屋の大きさ+α */ bool xproximity = (midpos.x <= room1.RoomRect.xMax + areaboderrate && midpos.x >= room1.CenterToInt.x) || (midpos.x >= room1.RoomRect.xMin - areaboderrate && midpos.x <= room1.CenterToInt.x); bool yproximity = (midpos.y <= room1.RoomRect.yMax + areaboderrate && midpos.y >= room1.CenterToInt.y) || (midpos.y >= room1.RoomRect.yMin - areaboderrate && midpos.y <= room1.CenterToInt.y); //Debug.Log("MidPos: " + midpos+", Xprox: " +xproximity+", Yprox: "+yproximity); Vector2[] pos = new Vector2[2]; if (xproximity && !yproximity) { pos = getStartAndEndPosition(room1, room2, false); } else if (yproximity && !xproximity) { pos = getStartAndEndPosition(room1, room2, true); } else { if (Mathf.Abs(dist.x) < Mathf.Abs(dist.y)) { pos = getStartAndEndPosition(room1,room2,false); } else { pos = getStartAndEndPosition(room1, room2, true); } } Pathway pw = new Pathway(pos[0],pos[1]); //Debug.Log("Pw: " + pw.ToString()); if (!room2.join(pw)) { Vector2 dir = pw.Direction; //Debug.Log("Dir: "+dir); Vector2 sv = pw.EndPosition+dir; float ex = 0, ey = 0; if (dir.y == 0) { ex = sv.x; ey = room2.CenterToInt.y;//norm.y < 0 ? room2.RoomRect.yMax : room2.RoomRect.yMin; } else if (dir.x == 0) { ey = sv.y; ex = room2.CenterToInt.x; //norm.x < 0 ? room2.RoomRect.xMin : room2.RoomRect.xMax; } //sx = Mathf.Max(0, sx); sx = Mathf.Min(this.Size.x, sx); ex = Mathf.Max(0, ex); ex = Mathf.Min(this.Size.x, ex); //sy = Mathf.Max(0, sy); sy = Mathf.Min(this.Size.y, sy); ey = Mathf.Max(0, ey); ey = Mathf.Min(this.Size.y, ey); Pathway pw2 = new Pathway(sv, new Vector2(ex, ey)); //Debug.Log("Pw2: "+pw2); ret.Add(pw2); } if(pw.Length != 0) ret.Add(pw); } Pathways.AddRange(ret); }