public void AddWall(RoomWall wall) { for (var i = 0; i < corners.Count; i++) { if (corners[i] == wall.start) { corners.Add(wall.end); corners.Add(wall.end); SortCorners(); return; } if (corners[i] == wall.end) { corners.Add(wall.start); corners.Add(wall.start); SortCorners(); return; } } corners.Add(wall.start); corners.Add(wall.start); corners.Add(wall.end); corners.Add(wall.end); SortCorners(); }
public static RoomWall operator -(RoomWall a, GridVector b) { var result = new RoomWall(a); result.start -= b; result.end -= b; return(result); }
public void TriggerEvent(RoomWall designator, Vector3 velocity) { RoomUnityEvent evt = null; if (m_eventDatabase.TryGetValue(designator, out evt)) { evt.Invoke(designator, velocity); } }
public static int CompareByLength(RoomWall a, RoomWall b) { if (a.length > b.length) { return(1); } if (a.length == b.length) { return(0); } return(-1); }
//TODO need to optimise //use of list and "index of" killing it public static RoomWall[] CalculatePoints(Room room, IVolume volume, bool debug = false) { Dictionary <int, List <Vector2Int> > facadeWallAnchors = volume.facadeWallAnchors; // List<Vector2Int> volumeWallAnchors = volume.wallAnchors; int pointCount = room.numberOfPoints; RoomWall[] output = new RoomWall[pointCount]; for (int p = 0; p < pointCount; p++) { Vector2Int startPoint = room[p].position; int pb = (p + 1) % pointCount; Vector2Int endPoint = room[pb].position; RoomWall newWall = CalculateNewWall(volume, startPoint, endPoint); // int numberOfFacades = facadeWallAnchors.Count; int size = newWall.offsetPoints.Length; newWall.offsetPointWallSection = new int[size]; newWall.anchorPointIndicies = new int[size]; int currentFacade = newWall.facadeIndex; // int facadePointCount = facadeWallAnchors[currentFacade].Count; // int wallSectionIndex = facadePointCount - facadeWallAnchors[currentFacade].IndexOf(newWall.offsetPointsInt[0]); for (int s = 0; s < size; s++) { //minus one as we're on the other side of the wall - the wall point index will be the wrong point - need to use the other section point newWall.offsetPointWallSection[s] = facadeWallAnchors[currentFacade].IndexOf(newWall.offsetPointsInt[s]); // Debug.Log(currentFacade+" "+s+" "+ newWall.offsetPointsInt[s]); // newWall.anchorPointIndicies[s] = volumeWallAnchors.IndexOf(newWall.offsetPointsInt[s]); // if (facadeWallAnchors[currentFacade].IndexOf(newWall.offsetPointsInt[s]) == facadeWallAnchors[currentFacade].Count - 1) // currentFacade = (currentFacade + 1) % numberOfFacades; // int it = numberOfFacades; // while (!facadeWallAnchors[currentFacade].Contains(newWall.offsetPointsInt[s]))//find the facade that this anchor point is part of // { // currentFacade = (currentFacade + 1) % numberOfFacades; // it--; // if (it < 0) break; // } // newWall.offsetPointWallSection[s] = facadeWallAnchors[currentFacade].IndexOf(newWall.offsetPointsInt[s]); // newWall.offsetPointWallSection[s] = wallSectionIndex - s; // while(newWall.offsetPointWallSection[s] < 0) newWall.offsetPointWallSection[s] += facadePointCount; } output[p] = newWall; } return(output); }
public void UnSubscribeEvent(RoomWall eventDesignator) { if (!m_instance) { return; } RoomUnityEvent evt = null; if (m_eventDatabase.TryGetValue(eventDesignator, out evt)) { evt.RemoveListener(RoomRotationTrigger); } }
private void RoomRotationTrigger(RoomWall hitWall, Vector3 triggerVelocity) { if (hitWall.ID != m_currentWall.ID && m_rotationRefresh.isDone && !m_rotating) { if (triggerVelocity.sqrMagnitude > m_collisionMagnitude) // trigger the rotation if we hit hard enough { m_rotating = true; var rotDir = GetRotation(m_currentWall.ID, hitWall.ID); StartCoroutine(RotateRoom(rotDir)); // no need to cache as it gets auto collected m_currentWall.ToggleCamera(); m_currentWall = hitWall; m_currentWall.ToggleCamera(); } } }
void Awake() { if (!Application.isPlaying && !initialized) { leftWall = new RoomWall("Left Wall", this); rightWall = new RoomWall("Right Wall", this); frontWall = new RoomWall("Front Wall", this); rearWall = new RoomWall("Rear Wall", this); floor = new RoomWall("Floor", this); roof = new RoomWall("Roof", this); material = leftWall.Material; initialized = true; UpdateDimensions(); } }
public void Subscribe(RoomWall eventDesignator) { RoomUnityEvent evt = null; if (m_eventDatabase.TryGetValue(eventDesignator, out evt)) { Debug.Log("Can't add multiple events to one object"); return; } else { evt = new RoomUnityEvent(); evt.AddListener(RoomRotationTrigger); m_eventDatabase.Add(eventDesignator, evt); } }
private bool AddSpider(List <Spider> spiders, RoomBounds room1, RoomWall room1Wall, RoomBounds room2, RoomWall room2Wall, Pathfinder pathfinder) { var start = GetIndex(room1, room1Wall); var end = GetIndex(room2, room2Wall); var spider = new Spider(); spider.Path = pathfinder.Calculate(start, end); if (spider.Path != null) { dungeon[start].Type = CellType.Door; dungeon[end].Type = CellType.Door; spiders.Add(spider); } return(spider.Path != null); }
public static Vector2[] RoomArchorPoints(RoomWall[] walls) { int wallCount = walls.Length; // List<Vector2Int> intList = new List<Vector2Int>(); List <Vector2> output = new List <Vector2>(); for (int w = 0; w < wallCount; w++) { RoomWall wall = walls[w]; int pointCount = wall.offsetPointsInt.Length - 1;//skip last point to avoid repetition for (int p = 0; p < pointCount; p++) { // if(!intList.Contains(wall.offsetPointsInt[p])) // { output.Add(wall.offsetPoints[p]); // intList.Add(wall.offsetPointsInt[p]); // } } } return(output.ToArray()); }
private Index GetIndex(RoomBounds room, RoomWall wall) { Index index = null; switch (wall) { case RoomWall.Top: case RoomWall.Bottom: { index = new Index((wall == RoomWall.Top) ? room.Top : room.Bottom, random.Next(room.Left + 1, room.Right)); break; } case RoomWall.Left: case RoomWall.Right: { index = new Index(random.Next(room.Top + 1, room.Bottom), (wall == RoomWall.Left) ? room.Left : room.Right); break; } } return(index); }
public void GrowWall(RoomWall wall) { for (var i = 0; i < corners.Count; i++) { if (i < corners.Count - 1) { if (corners[i] == wall.start && corners[i + 1] == wall.end) { corners[i] += wall.outwards.minimized; corners[i + 1] += wall.outwards.minimized; return; } if (corners[i] == wall.end && corners[i + 1] == wall.start) { corners[i] -= wall.outwards.minimized; corners[i + 1] -= wall.outwards.minimized; return; } } else { if (corners[i] == wall.start && corners[0] == wall.end) { corners[i] += wall.outwards.minimized; corners[0] += wall.outwards.minimized; return; } if (corners[i] == wall.end && corners[0] == wall.start) { corners[i] -= wall.outwards.minimized; corners[0] -= wall.outwards.minimized; return; } } } }
bool CheckRect(RoomWall wall, Color freeColor, Color roomColor) { return(CheckRect(wall.start, wall.end, freeColor, roomColor)); }
public static RoomWall CalculateNewWall(IVolume volume, Vector2Int startPoint, Vector2Int endPoint) { RoomWall output = new RoomWall(); output.baseA = startPoint; output.baseB = endPoint; output.offsetPoints = new Vector2[0]; output.offsetPointsInt = new Vector2Int[0]; if (startPoint == endPoint) { return(output);//not a wall mate } Dictionary <int, List <Vector2Int> > facadeWallAnchors = volume.facadeWallAnchors; List <Vector2Int> volumeWallAnchors = volume.wallAnchors; int start = volumeWallAnchors.IndexOf(startPoint); int end = volumeWallAnchors.IndexOf(endPoint); output.startVolumePointIndex = start; output.endVolumePointIndex = end; if (start == -1 || end == -1)//fully internal wall. two points need to represent { output.isExternal = false; output.offsetPointsInt = new Vector2Int[2]; output.offsetPointsInt[0] = startPoint; output.offsetPointsInt[1] = endPoint; output.offsetPoints = new Vector2[2]; output.offsetPoints[0] = startPoint.vector2; output.offsetPoints[1] = endPoint.vector2; } else { int index = start; int size = volumeWallAnchors.Count; int its = 0; int facadeCount = facadeWallAnchors.Count; int facadeIndex = -1; for (int f = 0; f < facadeCount; f++) { if (facadeWallAnchors[f].Contains(startPoint) && facadeWallAnchors[f].Contains(endPoint)) { facadeIndex = f; break;//the exist on a single facade } } if (facadeIndex == -1)//internal wall as points do not exist on same facade { output.isExternal = false; output.offsetPointsInt = new Vector2Int[2]; output.offsetPointsInt[0] = startPoint; output.offsetPointsInt[1] = endPoint; output.offsetPoints = new Vector2[2]; output.offsetPoints[0] = startPoint.vector2; output.offsetPoints[1] = endPoint.vector2; } else { output.isExternal = true; output.facadeIndex = facadeIndex; int direction = start < end ? 1 : -1; int wallAnchorDiff = Mathf.Abs(start - end); if (wallAnchorDiff > size / 2) { direction = -direction; } List <Vector2Int> wallPointsInt = new List <Vector2Int>(); List <Vector2> wallPoints = new List <Vector2>(); while (true)//count around the volume anchors to get the complete list of anchor points { if (wallPointsInt.Count > 0 && volumeWallAnchors[index] == wallPointsInt[wallPointsInt.Count - 1]) { //skip it - this wall point has already been registered on this wall } else { wallPointsInt.Add(volumeWallAnchors[index]); wallPoints.Add(volumeWallAnchors[index].vector2); } // Debug.Log(index); index += direction; if (index >= size) { index = 0; } if (index < 0) { index = size - 1; } if (index == end) { wallPointsInt.Add(volumeWallAnchors[index]); //last anchor point wallPoints.Add(volumeWallAnchors[index].vector2); //last anchor point break; } its++; if (its > size) { break; //only go around once... } } output.offsetPointsInt = wallPointsInt.ToArray(); output.offsetPoints = wallPoints.ToArray(); } } return(output); }
public RoomWall(RoomWall wall) { start = wall.start; end = wall.end; }
public int GenerateRoom(int floorIndex, int roomIndex, Material wallMaterial, Material floorMaterial, Transform parentContainer) { string newName = string.Format("room{0}-{1}", floorIndex, roomIndex); assignedFurniture.Clear(); PopulateSideAssignmentOrder(); Dimensions = new Vector3( UnityEngine.Random.Range(MinDimensions.x, MaxDimensions.x), UnityEngine.Random.Range(MinDimensions.y, MaxDimensions.y), UnityEngine.Random.Range(MinDimensions.z, MaxDimensions.z)); var _light = GameObject.Instantiate(LightPrefab, Vector3.zero, Quaternion.identity) as Light; var _blacklight = GameObject.Instantiate(LightPrefab, Vector3.zero, Quaternion.identity) as Light; wallLeft = GameObject.Instantiate(WallPartPrefab, Vector3.zero, Quaternion.identity) as RoomWall; wallRight = GameObject.Instantiate(WallPartPrefab, Vector3.zero, Quaternion.identity) as RoomWall; wallBack = GameObject.Instantiate(WallPartPrefab, Vector3.zero, Quaternion.identity) as RoomWall; floor = GameObject.Instantiate(WallPartPrefab, Vector3.zero, Quaternion.identity) as RoomWall; ceiling = GameObject.Instantiate(WallPartPrefab, Vector3.zero, Quaternion.identity) as RoomWall; GameObject room = new GameObject(newName, typeof(BuildingRoom)); room.transform.SetToParentZero(parentContainer); room.transform.position = Vector3.left * 100; var roomComponent = room.GetComponent<BuildingRoom>(); roomComponent.Room = roomIndex; roomComponent.Floor = floorIndex; roomComponent.Dimensions = Dimensions; BuiltRooms.Add(room); wallLeft.transform.SetParent(room.transform); wallRight.transform.SetParent(room.transform); wallBack.transform.SetParent(room.transform); floor.transform.SetParent(room.transform); ceiling.transform.SetParent(room.transform); _light.transform.SetParent(room.transform); _blacklight.transform.SetParent(room.transform); floor.transform.localScale = new Vector3(Dimensions.x, 0.1f, Dimensions.z); ceiling.transform.localScale = new Vector3(Dimensions.x, 0.1f, Dimensions.z); wallRight.SetSize(Dimensions.z, Dimensions.y); wallLeft.SetSize(Dimensions.z, Dimensions.y); wallBack.SetSize(Dimensions.x, Dimensions.y); _light.transform.localPosition = Vector3.zero; _blacklight.transform.localPosition = Vector3.zero; floor.transform.localPosition = Vector3.zero; ceiling.transform.localPosition = Vector3.zero; _light.transform.localPosition += Vector3.up * Dimensions.y; _blacklight.transform.localPosition += Vector3.up * Dimensions.y; wallLeft.transform.localPosition = new Vector3(Dimensions.x * 0.5f, 0, 0); wallRight.transform.localPosition = new Vector3(-(Dimensions.x * 0.5f), 0, 0); wallBack.transform.localPosition = new Vector3(0, 0, (Dimensions.z * 0.5f)); ceiling.transform.localPosition += Vector3.up * Dimensions.y; wallLeft.transform.localRotation = Quaternion.Euler(Vector3.up * 90); wallRight.transform.localRotation = Quaternion.Euler(Vector3.up * -90); _light.range = (Dimensions.x + Dimensions.z) * 2; _blacklight.range = 5; // (Dimensions.x + Dimensions.z) * 2; BedSide = (RoomSide)UnityEngine.Random.Range(0, 2); SideAssignmentOrder.Remove(BedSide); SideAssignmentOrder.Insert(0, BedSide); FillWalls(); roomComponent.AssignIndexesToItems(); SetWallMaterial(wallMaterial); SetFloorMaterial(floorMaterial); _blacklight.color = Color.Lerp(Color.red, Color.blue, .5f); _blacklight.intensity = 4; _blacklight.gameObject.SetActive(false); roomComponent.Blacklight = _blacklight; roomComponent.RoomLight = _light; return BuiltRooms.Count - 1; }
override public void OnInspectorGUI() { RoomWall wall = target as RoomWall; if (AssetDatabase.Contains(wall.gameObject)) { DrawDefaultInspector(); } else { Object[] objects = Selection.objects; Object[] selection = new Object[objects.Length]; Object[] prefabs = Resources.LoadAll("Wall"); RoomWall prefab; string[] strList = new string[prefabs.Length]; string selectionName = null; int selectionIndex = 0; int j; int i; for (i = 0; i < prefabs.Length; i++) { prefab = (prefabs[i] as GameObject).GetComponent <RoomWall>(); strList[i] = prefab.referenceName; for (j = 0; j < objects.Length; j++) { wall = (objects[j] as GameObject).GetComponent <RoomWall>(); if (wall.referenceName == prefab.referenceName) { if (selectionName == null) { selectionName = wall.referenceName; selectionIndex = i; } else if (selectionName != wall.referenceName) { selectionIndex = -1; } } } } int selected = EditorGUILayout.Popup("Wall:", selectionIndex, strList); if (selectionIndex != selected) { GameObject newWall; GameObject obj; for (i = 0; i < objects.Length; i++) { newWall = PrefabUtility.InstantiatePrefab(prefabs[selected] as GameObject) as GameObject; obj = objects[i] as GameObject; Undo.RegisterCreatedObjectUndo(newWall, "Created replacement tile"); newWall.transform.position = obj.transform.position; newWall.transform.rotation = obj.transform.rotation; newWall.transform.localScale = obj.transform.localScale; newWall.transform.parent = obj.transform.parent; newWall.transform.SetSiblingIndex(obj.transform.GetSiblingIndex()); obj.transform.parent.transform.parent.GetComponent <RoomUnit>().ReplaceWall(newWall.GetComponent <RoomWall>(), obj.GetComponent <RoomWall>().index); Undo.DestroyObjectImmediate(obj); selection[i] = newWall; } Selection.objects = selection; } } }
private void Awake() { instance = this; UpdateWallTexture(); }
void connect(RoomWall rw) { roomLeaves[rw.wall.top - 1].connect(roomLeaves[rw.wall.bottom - 1]); }
bool isConnect(RoomWall rw) { //Debug.Log("top: " + roomLeaves[rw.wall.top - 1].num + "bottom: " + roomLeaves[rw.wall.bottom - 1].num + "connect: " + roomLeaves[rw.wall.top - 1].isConnectTo(roomLeaves[rw.wall.bottom - 1])); return(roomLeaves[rw.wall.top - 1].isConnectTo(roomLeaves[rw.wall.bottom - 1])); }
void BresenhamLine(RoomWall wall, Color color, Texture2D tex = null) { BresenhamLine(wall.start, wall.end, color, tex); }
List <RoomWall> FindSegments(RoomWall wall, Color freeColor, Color roomColor) { var moved = wall + wall.outwards.minimized; var x0 = moved.start.x; var y0 = moved.start.y; var x1 = moved.end.x; var y1 = moved.end.y; var segments = new List <RoomWall>(); GridVector start = null; GridVector end = null; bool steep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0); if (steep) { Swap(ref x0, ref y0); Swap(ref x1, ref y1); } if (x0 > x1) { Swap(ref x0, ref x1); Swap(ref y0, ref y1); } for (int x = x0; x <= x1; x++) { for (int y = y0; y <= y1; y++) { int coordX = steep ? y : x; int coordY = steep ? x : y; Color color = texture.GetPixel(coordX, coordY); if (color != freeColor && color != roomColor) { if (end != null && start != null) { var segment = new RoomWall(start, end); segment -= wall.outwards.minimized; segments.Add(segment); start = null; end = null; } scanTexture.SetPixel(coordX, coordY, Color.red); } else { if (start == null) { start = new GridVector(coordX, coordY); } end = new GridVector(coordX, coordY); scanTexture.SetPixel(coordX, coordY, Color.green); } } } if (end != null && start != null) { var segment = new RoomWall(start, end); segment -= wall.outwards.minimized; segments.Add(segment); } return(segments); }