private void FollowMousePosition() { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePosition = SimulationGrid.FitToGrid(mousePosition); transform.position = mousePosition; }
void LateUpdate() { if (running) { dummyWire.points[1] = SimulationGrid.FitToGrid(EditorInput.instance.mousePosition); } }
void RepositionInstantiatedObjects() { Vector2 mousePosition = SimulationGrid.FitToGrid(EditorInput.instance.mousePosition); Vector3 componentCenter = Vector3.zero; foreach (var component in idToComponent) { componentCenter += component.Value.transform.position; } componentCenter /= idToComponent.Count; Vector2 offset = componentCenter; if (centerComponentsAroundMouse) { offset = mousePosition - offset; } else { offset = (Vector2)Camera.main.transform.position - offset; } foreach (var component in idToComponent) { component.Value.transform.position = component.Value.transform.position + (Vector3)offset; } }
void MoveSelectedComponentsWithMouse() { Vector2 offset = EditorInput.instance.mousePosition - EditorInput.instance.startingDragPoint; for (int i = 0; i < selectedComponents.Count; ++i) { selectedComponents[i].transform.position = SimulationGrid.FitToGrid(initialPositions[i] + offset); } }
/// <summary> /// Creates a 3x3 physicsinfo around the point on the simulation grid /// </summary> /// <param name="start"></param> public RectLRTB(ref SimulationPoint start) { var gp = SimulationGrid.GetGridPoint(start.Location.X, start.Location.Y); top = gp.Y - 1; bottom = gp.Y + 1; left = gp.X - 1; right = gp.X + 1; }
/// <summary> /// Instantiates the referenced floating component and adds it to the /// floating selection /// </summary> public void SetFloatingComponent() { var newFloatingComponent = Instantiate(floatingComponent); newFloatingComponent.transform.position = SimulationGrid.FitToGrid(Camera.main.ScreenToWorldPoint(Input.mousePosition)); FloatingSelection.instance.AddComponent(newFloatingComponent); ComponentListBar.instance.CloseComponentList(); }
/// <summary> /// Backs up all the grid cells on a line for the recompute engine. /// </summary> public void SaveCells(Vector2d start, Vector2d end) { var positions = SimulationGrid.GetGridPositions(start, end, _track.Grid.GridVersion); using (changesync.AcquireWrite()) { foreach (var cellpos in positions) { _savedcells.AddOverlay(cellpos.Point, _track.Grid.GetCell(cellpos.X, cellpos.Y)); _changedcells.Add(cellpos.Point); } } }