public override void OnInspectorGUI() { //DrawDefaultInspector(); serializedObject.Update(); //EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Initialization File", EditorStyles.boldLabel); EditorStyles.label.wordWrap = true; EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.Space(); EditorGUILayout.LabelField("Leave empty if you do not want to initialize with an initial calibration file."); myScript.defaultCalibrationFile = EditorGUILayout.TextField("Startup Calibration File", myScript.defaultCalibrationFile); myScript.configFileName = EditorGUILayout.TextField("Config File Name", myScript.configFileName); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("File IO", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Load Calibration")) { string[] filters = { "JSON Calibration File", "json" }; string path = EditorUtility.OpenFilePanelWithFilters("Load Calibration", "", filters); myScript.LoadCalibration(path); } if (GUILayout.Button("Save Calibration")) { string path = EditorUtility.SaveFilePanelInProject( "Save Calibration", "projector_calibration.json", "json", "Enter a filename for the calibration file"); myScript.SaveCalibration(path); AssetDatabase.Refresh(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout); foldoutStyle.fontStyle = FontStyle.Bold; EditorGUILayout.LabelField("Visibility", EditorStyles.boldLabel); myScript.showMouseCursor = EditorGUILayout.Toggle("Mouse Cursor", myScript.showMouseCursor); myScript.showProjectionWarpGUI = EditorGUILayout.Toggle("Projection Warp GUI", myScript.showProjectionWarpGUI); myScript.showIconLabels = EditorGUILayout.Toggle("Icon Labels", myScript.showIconLabels); EditorGUILayout.Space(); EditorGUILayout.LabelField("Projection Settings", EditorStyles.boldLabel); ProjectionWarpSystem.CameraArragement cameraArrangement = (ProjectionWarpSystem.CameraArragement)EditorGUILayout.EnumPopup("Arrangement", myScript.arrangement); myScript.arrangement = cameraArrangement; float orthographicSizeScale = 1f; switch (cameraArrangement) { case ProjectionWarpSystem.CameraArragement.HORIZONTAL_PERSPECTIVE: case ProjectionWarpSystem.CameraArragement.VERTICAL_PERSPECTIVE: break; case ProjectionWarpSystem.CameraArragement.HORIZONTAL_ORTHOGRAPHIC: case ProjectionWarpSystem.CameraArragement.VERTICAL_ORTHOGRAPHIC: default: orthographicSizeScale = EditorGUILayout.FloatField("Orthographic Size Scale", myScript.orthographicSizeScale); if (orthographicSizeScale <= 0f) { orthographicSizeScale = 0.001f; } myScript.orthographicSizeScale = orthographicSizeScale; break; } Vector2 projectorResolution = EditorGUILayout.Vector2Field("Projector Resolution", myScript.renderTextureSize); if (projectorResolution.x < 1f) { projectorResolution.x = 1f; } else if (projectorResolution.x > 16384f) { projectorResolution.x = 16384f; } if (projectorResolution.y < 1f) { projectorResolution.y = 1f; } else if (projectorResolution.y > 16384f) { projectorResolution.y = 16384f; } myScript.renderTextureSize = projectorResolution; myScript.viewportSize = projectorResolution.y / 200f; int xDivisions = EditorGUILayout.IntField("X Divisions", myScript.xDivisions); xDivisions = Mathf.Clamp(xDivisions, 1, 100); myScript.xDivisions = xDivisions; int yDivisions = EditorGUILayout.IntField("Y Divisions", myScript.yDivisions); yDivisions = Mathf.Clamp(yDivisions, 1, 100); myScript.yDivisions = yDivisions; int firstProjector = EditorGUILayout.IntSlider("First Projector", myScript.firstProjector, 1, 8); firstProjector = Mathf.Clamp(firstProjector, 1, 8); myScript.firstProjector = firstProjector; int projectorCount = EditorGUILayout.IntSlider("Projector Count", myScript.projectorCount, 1, 8 - firstProjector + 1); projectorCount = Mathf.Clamp(projectorCount, 1, 8 - firstProjector + 1); myScript.projectorCount = projectorCount; bool regenerateCamera = EditorGUILayout.Toggle("Regenerate Cameras", myScript.regenerateCamera); myScript.regenerateCamera = regenerateCamera; EditorGUILayout.Space(); EditorGUILayout.LabelField("Distances", EditorStyles.boldLabel); float near = EditorGUILayout.FloatField("Near", myScript.near); if (near <= 0f) { near = 0.001f; } myScript.near = near; float far = EditorGUILayout.FloatField("Far", myScript.far); if (far <= near) { far = near + 0.001f; } myScript.far = far; float overlap = 0f; float projectionCameraSpace = 0f; if (myScript.projectorCount > 1) { switch (cameraArrangement) { case ProjectionWarpSystem.CameraArragement.HORIZONTAL_ORTHOGRAPHIC: overlap = EditorGUILayout.FloatField("Overlap", myScript.overlap.x); overlap = Mathf.Clamp(overlap, 0f, projectorResolution.x / 100f); myScript.overlap = new Vector2(overlap, 0f); break; case ProjectionWarpSystem.CameraArragement.VERTICAL_ORTHOGRAPHIC: overlap = EditorGUILayout.FloatField("Overlap", myScript.overlap.y); overlap = Mathf.Clamp(overlap, 0f, projectorResolution.y / 100f); myScript.overlap = new Vector2(0f, overlap); break; case ProjectionWarpSystem.CameraArragement.HORIZONTAL_PERSPECTIVE: overlap = EditorGUILayout.FloatField("Overlap", myScript.overlap.x); overlap = Mathf.Clamp(overlap, 0f, myScript.fieldOfView - (myScript.fieldOfView / myScript.sourceCameras.Count)); myScript.overlap = new Vector2(overlap, 0f); break; case ProjectionWarpSystem.CameraArragement.VERTICAL_PERSPECTIVE: overlap = EditorGUILayout.FloatField("Overlap", myScript.overlap.y); overlap = Mathf.Clamp(overlap, 0f, myScript.fieldOfView - (myScript.fieldOfView / myScript.sourceCameras.Count)); myScript.overlap = new Vector2(0f, overlap); break; default: break; } projectionCameraSpace = EditorGUILayout.FloatField("Projection Camera Space", myScript.projectionCameraSpace); if (projectionCameraSpace < 0) { projectionCameraSpace = 0f; } myScript.projectionCameraSpace = projectionCameraSpace; } else { myScript.overlap = Vector2.zero; } float fieldOfView = 0f; switch (cameraArrangement) { case ProjectionWarpSystem.CameraArragement.HORIZONTAL_PERSPECTIVE: case ProjectionWarpSystem.CameraArragement.VERTICAL_PERSPECTIVE: fieldOfView = EditorGUILayout.FloatField("Field Of View", myScript.fieldOfView); myScript.fieldOfView = fieldOfView; break; default: break; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Edit Mode (Single Mesh)", EditorStyles.boldLabel); int selectedMesh = EditorGUILayout.IntSlider("Selected Mesh", myScript.selectedMesh, -1, projectorCount - 1); selectedMesh = Mathf.Clamp(selectedMesh, -1, projectorCount - 1); myScript.selectedMesh = selectedMesh; if (selectedMesh >= 0) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.Space(); EditorGUILayout.LabelField("Visibility", EditorStyles.boldLabel); bool showGrid = EditorGUILayout.Toggle("Show Grid", myScript.projectionCameras[myScript.selectedMesh].showGrid); if (showGrid) { myScript.projectionCameras[myScript.selectedMesh].ShowBaseGrid(); } else { myScript.projectionCameras[myScript.selectedMesh].HideBaseGrid(); } bool showSelectedGrid = EditorGUILayout.Toggle("Show Selected Grid", myScript.projectionCameras[myScript.selectedMesh].showSelectedGrid); if (showSelectedGrid) { myScript.projectionCameras[myScript.selectedMesh].ShowSelectedGrid(); } else { myScript.projectionCameras[myScript.selectedMesh].HideSelectedGrid(); } bool showControlPoints = EditorGUILayout.Toggle("Show Control Points", myScript.projectionCameras[myScript.selectedMesh].showControlPoints); if (showControlPoints) { myScript.projectionCameras[myScript.selectedMesh].ShowControlPoints(); } else { myScript.projectionCameras[myScript.selectedMesh].HideControlPoints(); } bool showSelectedControlPoints = EditorGUILayout.Toggle("Show Selected Control Points", myScript.projectionCameras[myScript.selectedMesh].showSelectedControlPoints); if (showSelectedControlPoints) { myScript.projectionCameras[myScript.selectedMesh].ShowSelectedControlPoints(); } else { myScript.projectionCameras[myScript.selectedMesh].HideSelectedControlPoints(); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Fade Controls", EditorStyles.boldLabel); float topFadeRange = EditorGUILayout.FloatField("Top Fade Range", myScript.projectionCameras[myScript.selectedMesh].topFadeRange); topFadeRange = Mathf.Clamp(topFadeRange, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].topFadeRange = topFadeRange; float topFadeChoke = EditorGUILayout.FloatField("Top Fade Choke", myScript.projectionCameras[myScript.selectedMesh].topFadeChoke); topFadeChoke = Mathf.Clamp(topFadeChoke, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].topFadeChoke = topFadeChoke; float bottomFadeRange = EditorGUILayout.FloatField("Bottom Fade Range", myScript.projectionCameras[myScript.selectedMesh].bottomFadeRange); bottomFadeRange = Mathf.Clamp(bottomFadeRange, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].bottomFadeRange = bottomFadeRange; float bottomFadeChoke = EditorGUILayout.FloatField("Bottom Fade Choke", myScript.projectionCameras[myScript.selectedMesh].bottomFadeChoke); bottomFadeChoke = Mathf.Clamp(bottomFadeChoke, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].bottomFadeChoke = bottomFadeChoke; float leftFadeRange = EditorGUILayout.FloatField("Left Fade Range", myScript.projectionCameras[myScript.selectedMesh].leftFadeRange); leftFadeRange = Mathf.Clamp(leftFadeRange, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].leftFadeRange = leftFadeRange; float leftFadeChoke = EditorGUILayout.FloatField("Left Fade Choke", myScript.projectionCameras[myScript.selectedMesh].leftFadeChoke); leftFadeChoke = Mathf.Clamp(leftFadeChoke, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].leftFadeChoke = leftFadeChoke; float rightFadeRange = EditorGUILayout.FloatField("Right Fade Range", myScript.projectionCameras[myScript.selectedMesh].rightFadeRange); rightFadeRange = Mathf.Clamp(rightFadeRange, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].rightFadeRange = rightFadeRange; float rightFadeChoke = EditorGUILayout.FloatField("Right Fade Choke", myScript.projectionCameras[myScript.selectedMesh].rightFadeChoke); rightFadeChoke = Mathf.Clamp(rightFadeChoke, 0f, 1f); myScript.projectionCameras[myScript.selectedMesh].rightFadeChoke = rightFadeChoke; EditorGUILayout.Space(); EditorGUILayout.LabelField("White Balance", EditorStyles.boldLabel); myScript.projectionCameras[myScript.selectedMesh].tint = EditorGUILayout.ColorField("Tint", myScript.projectionCameras[myScript.selectedMesh].tint);; myScript.projectionCameras[myScript.selectedMesh].UpdateBlend(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Grid Controls", EditorStyles.boldLabel); int selectedVertex = EditorGUILayout.IntSlider("Selected Vertex", myScript.projectionCameras[selectedMesh].selectedVertex, -1, myScript.projectionCameras[selectedMesh].vertices.Length - 1); selectedVertex = Mathf.Clamp(selectedVertex, -1, myScript.projectionCameras[selectedMesh].vertices.Length - 1); myScript.projectionCameras[selectedMesh].selectedVertex = selectedVertex; EditorGUILayout.BeginVertical(EditorStyles.helpBox); myScript.projectionCameras[selectedMesh].editMode = (ProjectionMesh.MeshEditMode)EditorGUILayout.EnumPopup("Mesh Edit Mode", myScript.projectionCameras[selectedMesh].editMode); switch (myScript.projectionCameras[selectedMesh].editMode) { case ProjectionMesh.MeshEditMode.CORNERS: EditorGUILayout.LabelField("Corner Offsets", EditorStyles.boldLabel); for (int i = 0; i < 4; i++) { myScript.projectionCameras[myScript.selectedMesh].cornerOffset[i] = EditorGUILayout.Vector2Field("Corner Vertex " + i, myScript.projectionCameras[myScript.selectedMesh].cornerOffset[i]); } break; case ProjectionMesh.MeshEditMode.ROWS: /* * EditorGUILayout.LabelField("Row Offsets", EditorStyles.boldLabel); * for (int i = 0; i < myScript.yDivisions + 1; i++) * { * myScript.projectionCameras[myScript.selectedMesh].rowOffset[i] = EditorGUILayout.Vector2Field("Row " + i, myScript.projectionCameras[myScript.selectedMesh].rowOffset[i]); * } */ EditorGUILayout.LabelField("Point Offsets", EditorStyles.boldLabel); for (int i = 0; i < myScript.yDivisions + 1; i++) { for (int j = 0; j < myScript.xDivisions + 1; j++) { int index = (i * (myScript.xDivisions + 1)) + j; myScript.projectionCameras[myScript.selectedMesh].pointOffset[index] = EditorGUILayout.Vector2Field("Point (" + i + "," + j + ")", myScript.projectionCameras[myScript.selectedMesh].pointOffset[index]); } } break; case ProjectionMesh.MeshEditMode.COLUMNS: /* * EditorGUILayout.LabelField("Column Offsets", EditorStyles.boldLabel); * for (int i = 0; i < myScript.xDivisions + 1; i++) * { * myScript.projectionCameras[myScript.selectedMesh].columnOffset[i] = EditorGUILayout.Vector2Field("Column " + i, myScript.projectionCameras[myScript.selectedMesh].columnOffset[i]); * } */ EditorGUILayout.LabelField("Point Offsets", EditorStyles.boldLabel); for (int i = 0; i < myScript.yDivisions + 1; i++) { for (int j = 0; j < myScript.xDivisions + 1; j++) { int index = (i * (myScript.xDivisions + 1)) + j; myScript.projectionCameras[myScript.selectedMesh].pointOffset[index] = EditorGUILayout.Vector2Field("Point (" + i + "," + j + ")", myScript.projectionCameras[myScript.selectedMesh].pointOffset[index]); } } break; case ProjectionMesh.MeshEditMode.POINTS: EditorGUILayout.LabelField("Point Offsets", EditorStyles.boldLabel); for (int i = 0; i < myScript.yDivisions + 1; i++) { for (int j = 0; j < myScript.xDivisions + 1; j++) { int index = (i * (myScript.xDivisions + 1)) + j; myScript.projectionCameras[myScript.selectedMesh].pointOffset[index] = EditorGUILayout.Vector2Field("Point (" + i + "," + j + ")", myScript.projectionCameras[myScript.selectedMesh].pointOffset[index]); } } break; default: break; } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); } EditorGUILayout.Space(); showReferenceGameObjects = EditorGUILayout.Foldout(showReferenceGameObjects, "Reference Game Objects", foldoutStyle); if (showReferenceGameObjects) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.Space(); EditorGUILayout.LabelField("Do not unlink these references. If you accidentally unlink them, please revert the prefab or refer to the manual on how to relink them."); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); myScript.sourceCamerasContainer = (Transform)EditorGUILayout.ObjectField("Pano Cameras Controller", myScript.sourceCamerasContainer, typeof(Transform), true); myScript.projectionCamerasContainer = (Transform)EditorGUILayout.ObjectField("Projection Cameras Controller", myScript.projectionCamerasContainer, typeof(Transform), true); myScript.calibrationManager = (CalibrationManager)EditorGUILayout.ObjectField("Calibration Manager", myScript.calibrationManager, typeof(CalibrationManager), true); myScript.notificationMessage = (NotificationMessage)EditorGUILayout.ObjectField("Notification Message", myScript.notificationMessage, typeof(NotificationMessage), true); EditorGUILayout.Space(); } /* * EditorGUILayout.Space(); * showStats = EditorGUILayout.Foldout(showStats, "Stats"); * if(showStats){ * string stats = ""; * stats+="Vertex Total: "+"\n"; * stats+="Triangle Total: "+"\n"; * EditorGUILayout.TextArea(stats); * } */ /* * if (EditorGUI.EndChangeCheck()) * { * Undo.RecordObject(myScript, "Changed Camera Count"); * //Refresh(); * * } */ if (GUI.changed) { if (myScript.showIconLabels) { myScript.calibrationManager.ShowIconLabels(); } else { myScript.calibrationManager.HideIconLabels(); } string[] res = UnityStats.screenRes.Split('x'); //check to see if resolution matches, if not show warning message if (int.Parse(res[0]) != (int)projectorResolution.x || int.Parse(res[1]) != (int)projectorResolution.y) { Debug.LogWarning("One of your Game windows set at " + int.Parse(res[0]) + "x" + int.Parse(res[1]) + " does not match the specified projector resolution " + (int)projectorResolution.x + "x" + (int)projectorResolution.y + ". Please update your Game window resolution or adjust your desired projector resolution to match."); } myScript.projectorCount = Mathf.Clamp(myScript.projectorCount, 1, MAX_CAMERAS); #region REBUILD CAMERA CONDITIONS //determine if critical things are changed bool rebuildCameras = false; //projection camera space changed if (prevOrthographicSizeScale != orthographicSizeScale) { rebuildCameras = true; } //projection camera space changed if (prevProjectorResolution != projectorResolution) { rebuildCameras = true; } //X/Y divisions changed if (prevXDivisions != xDivisions || prevYDivisions != yDivisions) { rebuildCameras = true; } //Camera count changed if (prevCameraCount != projectorCount) { rebuildCameras = true; } #endregion if (rebuildCameras) { myScript.regenerateCamera = true; myScript.DestroyCameras(); myScript.InitCameras(); } //update selection and mesh vertex for (int i = 0; i < myScript.projectionCameras.Count; i++) { myScript.projectionCameras[i].UpdateMeshVertices(); myScript.projectionCameras[i].UpdateSelectedLines(); myScript.projectionCameras[i].HighlightSelection(); myScript.targetDisplays[i] = i + myScript.firstProjector - 1; myScript.sourceCameras[i].GetComponent <Camera>().targetDisplay = myScript.targetDisplays[i]; myScript.projectionCameras[i].transform.parent.GetComponent <Camera>().targetDisplay = myScript.targetDisplays[i]; } myScript.UpdateCursor(); myScript.UpdateProjectionWarpGUI(); myScript.UpdateSourceCameras(); myScript.UpdateProjectionCameras(); //EditorUtility.SetDirty(myScript); //EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } prevProjectorResolution = projectorResolution; prevXDivisions = xDivisions; prevYDivisions = yDivisions; prevCameraCount = projectorCount; prevOrthographicSizeScale = orthographicSizeScale; serializedObject.ApplyModifiedProperties(); }
void Update() { //don't allow keyboard inputs when input field is focused CalibrationManager calibrationManager = system.calibrationManager; if (calibrationManager.topRangeInputField.isFocused || calibrationManager.topChokeInputField.isFocused || calibrationManager.bottomRangeInputField.isFocused || calibrationManager.bottomChokeInputField.isFocused || calibrationManager.leftRangeInputField.isFocused || calibrationManager.leftChokeInputField.isFocused || calibrationManager.rightRangeInputField.isFocused || calibrationManager.rightChokeInputField.isFocused || calibrationManager.redInputField.isFocused || calibrationManager.greenInputField.isFocused || calibrationManager.blueInputField.isFocused || calibrationManager.filename.isFocused) { return; } ProjectionMesh mesh = system.GetCurrentProjectionCamera(); #region Visibility Toggles if (Input.GetKeyDown(uiToggleKey)) { system.showProjectionWarpGUI = !system.showProjectionWarpGUI; system.UpdateProjectionWarpGUI(); } if (Input.GetKeyDown(mouseToggleKey)) { system.showMouseCursor = !system.showMouseCursor; system.UpdateCursor(); } if (Input.GetKeyDown(gridToggleKey)) { if (mesh != null) { mesh.ToggleBaseGrid(); } } if (Input.GetKeyDown(selectedGridToggleKey)) { if (mesh != null) { mesh.ToggleSelectedGrid(); } } if (Input.GetKeyDown(controlPointsToggleKey)) { if (mesh != null) { mesh.ToggleControlPoints(); } } if (Input.GetKeyDown(selectedControlPointsToggleKey)) { if (mesh != null) { mesh.ToggleSelectedControlPoints(); } } #endregion #region UI Toggles if (Input.GetKeyDown(helpKey)) { system.calibrationManager.OnToggleHelp(); } if (Input.GetKeyDown(noModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.NONE); } else if (Input.GetKeyDown(cornerModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.CORNERS); } else if (Input.GetKeyDown(rowModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.ROWS); } else if (Input.GetKeyDown(columnModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.COLUMNS); } else if (Input.GetKeyDown(pointModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.POINTS); } if (Input.GetKeyDown(blendingModeKey)) { system.calibrationManager.OnToggleBlend(); } else if (Input.GetKeyDown(whiteBalanceModeKey)) { system.calibrationManager.OnToggleWhiteBalance(); } #endregion #region Projector Selection if (Input.GetKeyDown(projectorAKey) || Input.GetKeyDown(projectorAAltKey)) { system.SelectProjector(0, true); } else if (Input.GetKeyDown(projectorBKey) || Input.GetKeyDown(projectorBAltKey)) { system.SelectProjector(1, true); } else if (Input.GetKeyDown(projectorCKey) || Input.GetKeyDown(projectorCAltKey)) { system.SelectProjector(2, true); } else if (Input.GetKeyDown(projectorDKey) || Input.GetKeyDown(projectorDAltKey)) { system.SelectProjector(3, true); } else if (Input.GetKeyDown(projectorEKey) || Input.GetKeyDown(projectorEAltKey)) { system.SelectProjector(4, true); } else if (Input.GetKeyDown(projectorFKey) || Input.GetKeyDown(projectorFAltKey)) { system.SelectProjector(5, true); } else if (Input.GetKeyDown(projectorGKey) || Input.GetKeyDown(projectorGAltKey)) { system.SelectProjector(6, true); } else if (Input.GetKeyDown(projectorHKey) || Input.GetKeyDown(projectorHAltKey)) { system.SelectProjector(7, true); } #endregion #region Selection Activation if (mesh != null) { if (mesh.editMode != ProjectionMesh.MeshEditMode.NONE) { if (Input.GetKeyDown(activateKey)) { if (mesh.selectionActive) { mesh.DeactivateSelection(); } else { mesh.ActivateSelection(); } } } } #endregion #region Point Selection and Adjustment //corner indexes are at - 0, xDivisions, (xDivisions+1) * yDivisions, (xDivisions+1) * (yDivisions+1)-1 float adjustmentScale = 0.1f; if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { adjustmentScale = 0.001f; } if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { adjustmentScale = 0.01f; } else if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { adjustmentScale = 0.1f; } if (mesh != null) { switch (mesh.editMode) { case ProjectionMesh.MeshEditMode.CORNERS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } //navigate control point corners if (!mesh.selectionActive) { if (Input.GetKeyDown(upKey)) { if (mesh.selectedVertex > system.xDivisions) { mesh.selectedVertex -= ((system.xDivisions + 1) * system.yDivisions); } } if (Input.GetKeyDown(downKey)) { if (mesh.selectedVertex < system.xDivisions + 1) { mesh.selectedVertex += ((system.xDivisions + 1) * system.yDivisions); } } if (Input.GetKeyDown(leftKey)) { if (mesh.selectedVertex == system.xDivisions || mesh.selectedVertex == ((system.xDivisions + 1) * (system.yDivisions + 1) - 1)) { mesh.selectedVertex -= system.xDivisions; } } if (Input.GetKeyDown(rightKey)) { if (mesh.selectedVertex == 0 || mesh.selectedVertex == ((system.xDivisions + 1) * system.yDivisions)) { mesh.selectedVertex += system.xDivisions; } } } //move control points else { int cornerIndex = -1; if (mesh.selectedVertex == 0) { cornerIndex = 0; } else if (mesh.selectedVertex == mesh.xDivisions) { cornerIndex = 1; } else if (mesh.selectedVertex == ((mesh.xDivisions + 1) * mesh.yDivisions)) { cornerIndex = 2; } else if (mesh.selectedVertex == ((mesh.xDivisions + 1) * (mesh.yDivisions + 1) - 1)) { cornerIndex = 3; } Vector2 point = mesh.cornerOffset[cornerIndex]; if (Input.GetKeyDown(upKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { mesh.cornerOffset[cornerIndex] = Vector2.zero; } } break; case ProjectionMesh.MeshEditMode.ROWS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } //up and down selects row if (!mesh.selectionActive) { if (Input.GetKeyDown(upKey)) { if (mesh.selectedVertex > system.xDivisions) { mesh.selectedVertex -= (system.xDivisions + 1); } } if (Input.GetKeyDown(downKey)) { if (mesh.selectedVertex < ((system.xDivisions + 1) * system.yDivisions)) { mesh.selectedVertex += (system.xDivisions + 1); } } } //move row around else { //figured out which row is being moved int rowIndex = -1; rowIndex = (int)Mathf.Floor(mesh.selectedVertex / (mesh.xDivisions + 1)); Vector2 point; int index; //Vector2 point = mesh.rowOffset[rowIndex]; if (Input.GetKeyDown(upKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } //mesh.rowOffset[rowIndex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } //mesh.rowOffset[rowIndex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } //mesh.rowOffset[rowIndex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } //mesh.rowOffset[rowIndex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; mesh.pointOffset[index] = Vector2.zero; } } } break; case ProjectionMesh.MeshEditMode.COLUMNS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } //left and right selects column if (!mesh.selectionActive) { if (Input.GetKeyDown(leftKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != 0) { mesh.selectedVertex -= 1; } } if (Input.GetKeyDown(rightKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != system.xDivisions) { mesh.selectedVertex += 1; } } } //move column around else { //figured out which column is being moved int columnIndex = -1; columnIndex = mesh.selectedVertex % (mesh.xDivisions + 1); Vector2 point; int index; if (Input.GetKeyDown(upKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } //mesh.columnOffset[columnIndex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } //mesh.columnOffset[columnIndex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } //mesh.columnOffset[columnIndex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } //mesh.columnOffset[columnIndex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; mesh.pointOffset[index] = Vector2.zero; } } } break; case ProjectionMesh.MeshEditMode.POINTS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } if (!mesh.selectionActive) { if (Input.GetKeyDown(upKey)) { if (mesh.selectedVertex > system.xDivisions) { mesh.selectedVertex -= (system.xDivisions + 1); } } if (Input.GetKeyDown(downKey)) { if (mesh.selectedVertex < ((system.xDivisions + 1) * system.yDivisions)) { mesh.selectedVertex += (system.xDivisions + 1); } } if (Input.GetKeyDown(leftKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != 0) { mesh.selectedVertex -= 1; } } if (Input.GetKeyDown(rightKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != system.xDivisions) { mesh.selectedVertex += 1; } } } else { //figured out which row is being moved Vector2 point = mesh.pointOffset[mesh.selectedVertex]; if (Input.GetKeyDown(upKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { mesh.pointOffset[mesh.selectedVertex] = Vector2.zero; } } break; default: case ProjectionMesh.MeshEditMode.NONE: break; } } #endregion if (Input.anyKeyDown) { //only rebuild when keys have been pressed if (mesh != null) { mesh.UpdateMeshVertices(); mesh.CreateBaseGridLines(); mesh.HighlightSelection(); mesh.UpdateSelectedLines(); } } }