public void UpdateConnections(Cell cell) { AssignPosition(cell); AdjacentObject[] adjObjects = FindObjectsOfType <AdjacentObject>(); foreach (AdjacentObject obj in adjObjects) { if (obj.position.x + 1 == this.position.x && obj.position.y == this.position.y) { leftObj = obj; leftObj.rightObj = this; list.Add(leftObj); } else if (obj.position.x - 1 == this.position.x && obj.position.y == this.position.y) { rightObj = obj; rightObj.leftObj = this; list.Add(rightObj); } else if (obj.position.y + 1 == this.position.y && obj.position.x == this.position.x) { lowerObj = obj; lowerObj.upperObj = this; list.Add(lowerObj); } else if (obj.position.y - 1 == this.position.y && obj.position.x == this.position.x) { upperObj = obj; upperObj.lowerObj = this; list.Add(upperObj); } } }
public void DestroyConnection(AdjacentObject adj) { if (list.Contains(adj)) { list.Remove(adj); } if (rightObj == adj) { rightObj = null; } if (leftObj == adj) { leftObj = null; } if (upperObj == adj) { upperObj = null; } if (lowerObj == adj) { lowerObj = null; } }
public virtual void MergeAdjacentRooms(SceneObject type) //split in 2 methods. Try merge and merge, add resourcepertime from adjacent object; { Debug.Log("Merging"); List <AdjacentObject> adjacents = new List <AdjacentObject>(); if (adjacent.leftObj != null) { adjacents.Add(adjacent.leftObj); } if (adjacent.rightObj != null) { adjacents.Add(adjacent.rightObj); } if (adjacent.upperObj != null) { adjacents.Add(adjacent.upperObj); } if (adjacent.lowerObj != null) { adjacents.Add(adjacent.lowerObj); } foreach (AdjacentObject nearObj in adjacents) { if (!nearObj.GetComponent <SceneObject>().hasJointedObject&& objectToMerge == null && type.GetType() == nearObj.GetComponent <SceneObject>().GetType() && nearObj.GetComponent <SceneObject>().lvl == lvl && lvl == 2) { if (nearObj.GetComponent <SceneObject>().lvl > 2 || nearObj.GetComponent <SceneObject>().id != id) { continue; } if (nearObj == adjacent.leftObj) { direction = new Vector2(-1, 0); } if (nearObj == adjacent.rightObj) { direction = new Vector2(1, 0); } if (nearObj == adjacent.upperObj) { direction = new Vector2(0, 1); } if (nearObj == adjacent.lowerObj) { direction = new Vector2(0, -1); } hasJointedObject = true; nearObj.GetComponent <SceneObject>().hasJointedObject = true; objectToMerge = nearObj; Debug.Log("ID: " + id + " " + "MERGED ID: " + objectToMerge.GetComponent <SceneObject>().id); if (!isMerged) { Debug.Log("why here?"); id = GetUniqueID(); objectToMerge.GetComponent <SceneObject>().id = id; ResizeObject(1.042f); TurnObject(); // dont do it after loading. Dont forget to turn finished production image RecenterObject(0.5f); isMerged = true; objectToMerge.GetComponent <SceneObject>().isMerged = true; } else { Debug.Log("right here"); if (direction.y != 0) { RotateViewObjects(); } ResizeCollider(); } return; } } }