public void ClearAllParts() { while (parts.Count > 0) { builder.DispatchPart(parts[0], ShipBuilder.TransferMode.Return); } UpdateHandler(); builder.UpdateChain(); }
void Update() { UpdateCompact(); if (clickedOnce) { if (timer > 0.2F) { clickedOnce = false; } else { timer += Time.deltaTime; } } int baseMoveSize = cursorMode == BuilderMode.Yard ? 4 : 5; builder.UpdateChain(); if (Input.GetKeyDown(KeyCode.C) && (!searchField.isFocused && !jsonField.isFocused && !WCWorldIO.active)) { if (builder as ShipBuilder == null || (builder as ShipBuilder).Equals(null) || !(builder as ShipBuilder).editorMode) { ClearAllParts(); } } foreach (var part in parts) { part.boundImage.enabled = Input.GetKey(KeyCode.LeftShift); } System.Func <Vector3, int, int, Vector3> roundToRatios = (x, y, z) => new Vector3(y * ((int)x.x / (int)y), z * ((int)x.y / (int)z), 0); var newOffset = roundToRatios(grid.position, baseMoveSize, baseMoveSize) - grid.position; transform.position = roundToRatios(Input.mousePosition, baseMoveSize, baseMoveSize) - newOffset; var oldPos = GetComponent <RectTransform>().anchoredPosition; GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Round(oldPos.x / 10) * 10, Mathf.Round(oldPos.y / 10) * 10); // round to nearest 0.1 // TODO: Make this stuff less messy. Regardless, consistency achieved! if (rotateMode) { RotateLastPart(); return; } if (flipped) { grid2mousePos = Input.mousePosition; flipped = false; return; } if (currentPart) { currentPart.SetMaskable(false); currentPart.info.location = (GetComponent <RectTransform>().anchoredPosition + offset) / 100; if (Input.GetMouseButtonUp(0)) { PlaceCurrentPart(); } } else if (Input.GetMouseButtonDown(0)) { grid2lastPos = grid.anchoredPosition; grid2mousePos = Input.mousePosition; lastPart = null; for (int i = parts.Count - 1; i >= 0; i--) { Bounds bound = ShipBuilder.GetRect(parts[i].rectTransform); bound.extents /= 1.5F; var origPos = transform.position; transform.position = Input.mousePosition; if (bound.Contains(GetComponent <RectTransform>().anchoredPosition)) { transform.position = origPos; GrabPart(parts[i]); break; } transform.position = origPos; } if (clickedOnce && !rotateMode && !flipped && !currentPart) { grid2lastPos = grid.anchoredPosition = Vector2.zero; } else { timer = 0; clickedOnce = true; } } // drag grid Vector2 bounds = grid.sizeDelta / 2 - grid2mask.sizeDelta / 2; if (grid.GetComponent <DragDetector>().dragging && Input.GetMouseButton(0) && !rotateMode && !flipped && !currentPart) { grid.anchoredPosition = grid2lastPos + ((Vector2)Input.mousePosition - grid2mousePos) * 2; grid.anchoredPosition = new Vector2(Mathf.Max(-bounds.x, Mathf.Min(bounds.x, grid.anchoredPosition.x)), Mathf.Max(-bounds.y, Mathf.Min(bounds.y, grid.anchoredPosition.y)) ); } }