void startMoving() { ConnectedSet.pieceForAlign = (connectedSet == null) ? null : this; MovingTarget = (connectedSet != null) ? connectedSet : this as IPuzzleLayer; MovingTarget.BeforeMoving(); // 記下位置 oldLocalPos = MovingTarget.GetTransform().localPosition; beginDragPos = Input.mousePosition; onMoving = true; }
void movingPiece() { //https://docs.unity3d.com/ScriptReference/Input-mousePosition.html //這裡是Sreen的delta var delta = (Input.mousePosition - beginDragPos); delta = screenVectorToWorld(delta); var localDelta = GetParentTransform().InverseTransformVector(delta); MovingTarget.GetTransform().localPosition = oldLocalPos + localDelta; var pocket = PuzzlePiecePocket.Instance; var nowX = transform.position.x; if (nowX < pocket.GetBorder()) // group區 { if (inPocket) { pocket.removeFromPocket(this); } } else // Pocket區 { // 已經拼好的,就不能放回口袋 if (connectedSet != null) { return; } //轉換回Pocket的local space var pos = transform.position; pos = PuzzlePiecePocket.Instance.transform.InverseTransformPoint(pos); var localZ = pos.z; var nowIndex = pocket.getInsertIndex(localZ, inPocket); if (!inPocket) // 不在口袋裡,就加進去 { pocket.addToPocket(nowIndex, this, false); } else { if (nowIndexInPocket != nowIndex) { pocket.swapInPocket(nowIndexInPocket, nowIndex);//交換 } } } }