public static void LoadDirectory(string dir) { if (dir == "") { return; } try { ConsoleScript.NewLine("Loading directory " + dir); string[] filePaths = Directory.GetFiles(dir); foreach (string file in filePaths) { new Assembly(file); } } catch (Exception e) { Debug.LogError("LoadDirectory failed: " + e.ToString()); } } // End of LoadDirectory
} // End of Start(). void Update() { // Smoothly interpolate camera position/rotation. transform.position = Vector3.SmoothDamp(transform.position, targetPos, ref smoothVelTranslate, translateSmoothTime); Quaternion tempRot = transform.rotation; tempRot = Quaternion.Slerp(tempRot, targetRot, 5 * Time.deltaTime); transform.rotation = tempRot; // Toggle camera lock/free movement with Spacebar. if (WesInput.GetKey("Camera Lock") && !spacePressed) { spacePressed = true; cameraLock = !cameraLock; } // Toggle freelook/camera lock. if (!WesInput.GetKey("Camera Lock")) { spacePressed = false; } // Camera defaults to unfocused, but if an element is selected this will become true. cameraFocused = false; // Determine what the user is looking at. Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit cameraLookHit; lookedAtNode = null; if (Physics.Raycast(mouseRay, out cameraLookHit)) { lookedAtObject = cameraLookHit.transform.gameObject; lookedAtNode = lookedAtObject.GetComponent <Node>(); } else { lookedAtObject = null; } // When not in free-look mode... if (cameraLock) { Screen.lockCursor = false; if (selectedAssembly != null) { cameraFocused = true; focusedPos = selectedAssembly.GetCenter(); } if (selectedNode != null) { cameraFocused = true; focusedPos = selectedNode.transform.position; } // Rotate orbit via directional input. if (Input.GetMouseButton(1)) { targetRot *= Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * cameraRotateSpeed, -Vector3.right); targetRot *= Quaternion.AngleAxis(Input.GetAxis("Mouse X") * cameraRotateSpeed, Vector3.up); } // If we are focusing on some object... if (cameraFocused) { // Zoom orbit with mousewheel. orbitDist -= (orbitDist * 0.3f) * Input.GetAxis("Mouse ScrollWheel") * orbitZoomSpeed; orbitDist = Mathf.Clamp(orbitDist, 3f, Mathf.Infinity); targetPos = focusedPos - (targetRot * (Vector3.forward * orbitDist)); } // If camera is locked but not focused... else { // Move in/out with mousewheel. targetPos += Camera.main.transform.forward * Input.GetAxis("Mouse ScrollWheel") * orbitZoomSpeed; } if (lookedAtObject) { if (lookedAtNode && Input.GetMouseButtonDown(0)) { mouseClickedNode = lookedAtNode; } else if (lookedAtNode && Input.GetMouseButtonUp(0)) { mouseReleasedNode = lookedAtNode; } // 'Selecting' a single node. if (mouseReleasedNode && (mouseClickedNode == mouseReleasedNode)) { Node clickAndReleaseNode = mouseReleasedNode; // Select the assembly attached to the node, if applicable... if ((clickAndReleaseNode.assembly != null) && (selectedAssembly != clickAndReleaseNode.assembly) && (!selectedNode || (selectedNode == clickAndReleaseNode) || (clickAndReleaseNode.assembly != selectedNode.assembly))) { selectedNode = null; FocusOnAssembly(clickAndReleaseNode.assembly); } // Otherwise just select the node. else { selectedNode = clickAndReleaseNode; selectedAssembly = null; targetRot = Quaternion.LookRotation(selectedNode.transform.position - transform.position, Camera.main.transform.up); } } } // Create a new bond. if (mouseClickedNode && mouseReleasedNode && !mouseClickedNode.BondedTo(mouseReleasedNode) && (mouseClickedNode != mouseReleasedNode) && (mouseClickedNode.BondCount() < 3) && (mouseReleasedNode.BondCount() < 3)) { new Bond(mouseClickedNode, mouseReleasedNode); ConsoleScript.NewLine("Manually created a bond."); } // Destroy an existing bond. else if (mouseClickedNode && mouseReleasedNode && mouseClickedNode.BondedTo(mouseReleasedNode)) { mouseClickedNode.GetBondTo(mouseReleasedNode).Destroy(); ConsoleScript.NewLine("Manually removed a bond."); } } // If we're in free-look mode... else { Screen.lockCursor = true; lookedAtObject = null; selectedNode = null; selectedAssembly = null; // Pitch/yaw camera via mouse movement. targetRot *= Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * cameraRotateSpeed, -Vector3.right); targetRot *= Quaternion.AngleAxis(Input.GetAxis("Mouse X") * cameraRotateSpeed, Vector3.up); } // Roll camera using Q and E targetRot *= Quaternion.AngleAxis(WesInput.rotationThrottle * -cameraRotateSpeed, Vector3.forward); if (!cameraFocused) { // Navigation // Translate position with keyboard input. targetPos += WesInput.forwardThrottle * transform.forward * cameraMoveSpeed * Time.deltaTime; targetPos += WesInput.horizontalThrottle * transform.right * cameraMoveSpeed * Time.deltaTime; targetPos += WesInput.verticalThrottle * transform.up * cameraMoveSpeed * Time.deltaTime; } // Auto-orbit targetRot = Quaternion.RotateTowards(targetRot, targetRot * autoOrbit, Time.deltaTime * 2.5f); if (Input.GetMouseButtonUp(0)) { mouseClickedNode = null; mouseReleasedNode = null; } dragLineRenderer.enabled = false; if (mouseClickedNode && lookedAtNode) { dragLineRenderer.SetPosition(0, mouseClickedNode.transform.position); dragLineRenderer.SetPosition(1, lookedAtNode.transform.position); if (mouseClickedNode.BondedTo(lookedAtNode)) { dragLineRenderer.SetColors(Color.yellow, Color.red); dragLineRenderer.enabled = true; } else if ((mouseClickedNode.BondCount() < 3) && (lookedAtNode.BondCount() < 3)) { dragLineRenderer.SetColors(Color.green, Color.white); dragLineRenderer.enabled = true; } } } // End of Update().