public HallwayAStar(DoorDefinition start, DoorDefinition end, AStarGrid grid) { this.openList = new List <Square> (); this.closedList = new List <Square> (); this.finalPath = new List <Square> (); this.startDoor = start; Square.Grid = grid; this.endDoor = end; this.grid = grid; }
private void RoundValues(DoorDefinition door) { if (door.Direction == Vector3.right || door.Direction == Vector3.left) { door.Position.z = ChunkBoundsHelper.RoundTo(door.Position.z, DoorDefinition.GlobalSize); } else { door.Position.x = ChunkBoundsHelper.RoundTo(door.Position.x, DoorDefinition.GlobalSize); } }
private void UpdateDoor(DoorDefinition door) { door.Position = AbstractBounds.Corners [door.CornerIndex] + door.Offset; ClampPosition(door); RoundValues(door); door.RelPosition = door.Position - transform.position; if (door != draggingDoor) { AdjustWorkingPosition(door); } //The doorsize should never be larger thant the actual room //doorSize = Mathf.Clamp (doorSize, 1f, AbstractBounds.minSize.y); }
//Hinders the door to be placed outside of the room public void ClampPosition(DoorDefinition door) { int[] cornerIndices = AbstractBounds.CornerIndicesByDirection(door.Direction); if (cornerIndices.Length > 0) { //Min and Max Points of the wall the door is facing //As to the order of the corners in AbstractBounds, these are not always the actual min and max values //The exceptions are handles by the clamp function below, which calculates min and max if they are unknown Vector3 roomBottomLeft = AbstractBounds.Corners [cornerIndices [0]]; Vector3 roomTopRight = AbstractBounds.Corners [cornerIndices [cornerIndices.Length - 1]]; //Either (1,1,0) or (0,1,1). Y Axis is always the same since we always want to clamp on the Y-Axis Vector3 clampFilter = VectorAbs(Vector3.Cross(door.Direction, Vector3.up) + Vector3.up); //Clamp on all axis. Depending on the direction the door is facing, one axis' value is going to be discarded using the clampFilter Vector3 clampedPos; clampedPos.x = Clamp(door.Position.x, roomBottomLeft.x, roomTopRight.x, DoorDefinition.GlobalSize); clampedPos.y = Clamp(door.Position.y, roomBottomLeft.y, roomTopRight.y - 0.1f, DoorDefinition.GlobalSize / 2f); clampedPos.z = Clamp(door.Position.z, roomBottomLeft.z, roomTopRight.z, DoorDefinition.GlobalSize); door.Position = Vector3.Scale(clampedPos, clampFilter) + Vector3.Scale(door.Position, VectorAbs(door.Direction)); } }
public HallwayMeta(DoorDefinition startDoor, DoorDefinition endDoor) { this.startDoor = startDoor; this.endDoor = endDoor; }
public void AdjustWorkingPosition(DoorDefinition doorDefinition) { //UpdateDoor (doorDefinition); doorDefinition.WorkingPosition = doorDefinition.Position; }
public override void OnInspectorGUI() { buttonStyle = new GUIStyle("button"); buttonStyle.fontSize = 13; buttonStyle.fixedHeight = 18; if (SceneUpdater.IsActive) { serDoorDefinitions = new SerializedObject(doorDefinitions); serDoorList = serDoorDefinitions.FindProperty("doors"); int selectedIndex = doorDefinitions.doors.IndexOf(selectedDoor); SerializedProperty serPreviewDoors = serDoorDefinitions.FindProperty("previewDoors"); //PREVIEW DOOR toggle EditorGUILayout.Space(); string onOff = serPreviewDoors.boolValue ? ": On" : ": Off"; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Mesh preview" + onOff, buttonStyle)) { bool prevPreviewVal = serPreviewDoors.boolValue; serPreviewDoors.boolValue = !serPreviewDoors.boolValue; } if (!SceneUpdater.HideGizmos) { EditorGUILayout.Space(); if (GUILayout.Button("-> Enter edit mode", buttonStyle)) { SceneUpdater.HideGizmos = true; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (SceneUpdater.HideGizmos) { EditorGUILayout.Space(); //SerializedProperty serDoorDefSize = serDoorDefinitions.FindProperty ("doorSize"); //float prevSize = serDoorDefSize.floatValue; //serDoorDefSize.floatValue = (float)EditorGUILayout.IntField ("Door size", (int)serDoorDefSize.floatValue); //doorDefinitions.AreDoorsDirty |= prevSize != serDoorDefSize.floatValue; //The doorsize should never be larger thant the actual room //serDoorDefSize.floatValue = Mathf.Clamp (serDoorDefSize.floatValue, 1f, doorDefinitions.AbstractBounds.minSize.y); //serDoorDefSize.floatValue = 2f; EditorGUILayout.Space(); SerializedProperty serMinCount = serDoorDefinitions.FindProperty("minCount"); SerializedProperty serMaxCount = serDoorDefinitions.FindProperty("maxCount"); serMinCount.intValue = EditorGUILayout.IntField("Min Quantity", serMinCount.intValue); serMinCount.intValue = Mathf.Max(serMinCount.intValue, 1); serMinCount.intValue = Mathf.Min(serMinCount.intValue, serMaxCount.intValue); serMaxCount.intValue = EditorGUILayout.IntField("Max Quantity", serMaxCount.intValue); serMaxCount.intValue = Mathf.Min(serMaxCount.intValue, serDoorList.arraySize); serMaxCount.intValue = Mathf.Max(serMaxCount.intValue, serMinCount.intValue); EditorGUILayout.Space(); for (int i = 0; i < serDoorList.arraySize; i++) { SerializedProperty serDoor = serDoorList.GetArrayElementAtIndex(i); SerializedProperty serDoorPos = serDoor.FindPropertyRelative("Position"); //SerializedProperty serDoorSize = serDoor.FindPropertyRelative ("Size"); SerializedProperty serDoorName = serDoor.FindPropertyRelative("Name"); //serDoorSize.vector3Value = DoorDefinition.GlobalSize * Vector3.one; EditorGUILayout.BeginHorizontal(); GUIStyle labelStyle = EditorStyles.label; labelStyle.normal.textColor = (selectedIndex == i) ? Color.blue : Color.black; labelStyle.stretchWidth = true; string labelPrefix = serDoorPos.vector3Value.ToString(); if (doorDefinitions.doors.IndexOf(selectedDoor) == i) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(labelPrefix, labelStyle); serDoorName.stringValue = EditorGUILayout.TextField(serDoorName.stringValue); EditorGUILayout.EndHorizontal(); } else { if (GUILayout.Button(labelPrefix, labelStyle)) { selectedDoor = doorDefinitions.doors [i]; } EditorGUILayout.LabelField(serDoorName.stringValue); } labelStyle.normal.textColor = Color.black; if (GUILayout.Button("x", GUILayout.Width(20))) { serDoorList.DeleteArrayElementAtIndex(i); //In case the selected door has been deleted if (doorDefinitions.doors.IndexOf(selectedDoor) == i) { selectedDoor = null; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+ Add Door", buttonStyle)) { serDoorList.InsertArrayElementAtIndex(serDoorList.arraySize); InitializeNewDoor(serDoorList.GetArrayElementAtIndex(serDoorList.arraySize - 1)); } if (selectedDoor != null && GUILayout.Button("Clear Selection", buttonStyle)) { selectedDoor = null; } if (GUILayout.Button("<- Leave edit mode", buttonStyle)) { SceneUpdater.HideGizmos = false; } EditorGUILayout.EndHorizontal(); } serDoorDefinitions.ApplyModifiedProperties(); SceneUpdater.UpdateScene(); } }
public void OnSceneGUI() { if (SceneUpdater.IsActive) { //Repaint Inspector in order to update movement changes of the doors Repaint(); //Check if the selected object has been deleted if (doorDefinitions.doors.Count == 0) { selectedDoor = null; } //Autoselect new door //This will also result in initial clamping, see below if (newDoorCreated) { selectedDoor = doorDefinitions.doors [doorDefinitions.doors.Count - 1]; newDoorCreated = false; } //Display doors as rectangle, color them red if selected //It seems like Handles have the limitation of having only floats as size input //Therefore I only support doors with same height / width, sadly foreach (DoorDefinition door in doorDefinitions.doors) { Handles.color = (door == selectedDoor) ? Color.red : Color.blue; if (Handles.Button(door.WorkingPosition, Quaternion.LookRotation(door.Direction), door.Extends.x, door.Extends.x, Handles.RectangleHandleCap)) { selectedDoor = door; } if (SceneUpdater.HideGizmos) { Handles.Label(door.Position, door.Name); } } //Handle logic for selected door if (selectedDoor == null) { doorDefinitions.DraggingDoor = null; } else { //Chewing gum effect. The handles are using the working position of the doors //Since also the offset is changed (below) the actual position of the door is bein calculated regardless //When releasing the mouse, set the working position to the current, calculated position //They may differ, since the working position is NOT aligned to the grid if (Event.current.type == EventType.MouseDown) { doorDefinitions.DraggingDoor = selectedDoor; } if (Event.current.type == EventType.MouseUp) { doorDefinitions.DraggingDoor = null; doorDefinitions.AdjustWorkingPosition(selectedDoor); } Vector3 horHandleDir = Vector3.Cross(Vector3.up, selectedDoor.Direction); if (horHandleDir.magnitude == 0f) { selectedDoor = null; return; } float sliderSize = HandleUtility.GetHandleSize(selectedDoor.WorkingPosition) * 1.5f; //Draw Move Arrows, use Normal in order to point it at the right direction Handles.color = horHandleDir.normalized == Vector3.right || horHandleDir.normalized == Vector3.left ? Color.red : Color.blue; selectedDoor.WorkingPosition = Handles.Slider(selectedDoor.WorkingPosition, horHandleDir, selectedDoor.Extends.x * sliderSize, Handles.ArrowHandleCap, 1f); Handles.color = Color.green; selectedDoor.WorkingPosition = Handles.Slider(selectedDoor.WorkingPosition, Vector3.up, selectedDoor.Extends.y * sliderSize, Handles.ArrowHandleCap, 1f); //Eventhough the position is already being clamped in the preview function of doorsPositions, //This clamp is important since several frames may pass before the next call of preview doorDefinitions.ClampPosition(selectedDoor); //Calculate Offset to the selected corner. Essential for docking //DoorDefinitions later calculates the position from the corner pos and offset selectedDoor.Offset = selectedDoor.WorkingPosition - doorDefinitions.AbstractBounds.Corners[selectedDoor.CornerIndex]; doorDefinitions.UpdateYOffset(selectedDoor.Offset.y); //Uniform handle size factor float directionHandleSize = HandleUtility.GetHandleSize(selectedDoor.WorkingPosition) * 0.8f; //Get one of four directions. The direction represent the wall the door is locked to. Vector3 newDirection = EditorGUIExtension.DirectionHandleVec(selectedDoor.WorkingPosition, directionHandleSize, selectedDoor.Direction, new Vector3(1f, 0f, 1f)); if (newDirection != selectedDoor.Direction) { selectedDoor.Direction = newDirection; //Default docking corner is at index one, bottom middle. See AbstractBounds for corner indices. selectedDoor.CornerIndex = doorDefinitions.AbstractBounds.CornerIndicesByDirection(newDirection) [1]; selectedDoor.Position = doorDefinitions.AbstractBounds.Corners [selectedDoor.CornerIndex]; doorDefinitions.ClampPosition(selectedDoor); doorDefinitions.AdjustWorkingPosition(selectedDoor); } //Retrieve all corner positions belonging to a certain wall defined by a direction vector int[] indices = doorDefinitions.AbstractBounds.CornerIndicesByDirection(selectedDoor.Direction); //Draw docking buttons foreach (int i in indices) { float dockHandleSize = HandleUtility.GetHandleSize(doorDefinitions.AbstractBounds.Corners[i]) * 0.1f; if (Handles.Button(doorDefinitions.AbstractBounds.Corners [i], Quaternion.identity, dockHandleSize, dockHandleSize, Handles.DotHandleCap)) { selectedDoor.Position = doorDefinitions.AbstractBounds.Corners [i]; selectedDoor.Offset = Vector2.up * doorDefinitions.GlobalYOffset; selectedDoor.CornerIndex = i; ApplyCornerHeight(i); doorDefinitions.AdjustWorkingPosition(selectedDoor); } } } } }