/// <summary> /// Updates the transform and state of this object every frame, depending on /// manipulations and docking state. /// </summary> public void Update() { if (isDragging && overlappingPositions.Count > 0) { var closestPosition = GetClosestPosition(); if (closestPosition.IsOccupied) { closestPosition.GetComponentInParent <Dock>().TryMoveToFreeSpace(closestPosition); } } if (dockingState == DockingState.Docked || dockingState == DockingState.Docking) { Assert.IsNotNull(dockedPosition, "When a dockable is docked, its dockedPosition must be valid."); Assert.AreEqual(dockedPosition.DockedObject, this, "When a dockable is docked, its dockedPosition reference the dockable."); var lerpTime = dockingState == DockingState.Docked ? moveLerpTimeWhenDocked : moveLerpTime; if (!isDragging) { // Don't override dragging transform.position = Solver.SmoothTo(transform.position, dockedPosition.transform.position, Time.deltaTime, lerpTime); transform.rotation = Solver.SmoothTo(transform.rotation, dockedPosition.transform.rotation, Time.deltaTime, lerpTime); } transform.localScale = Solver.SmoothTo(transform.localScale, dockedPositionScale, Time.deltaTime, lerpTime); if (VectorExtensions.CloseEnough(dockedPosition.transform.position, transform.position, distanceTolerance) && QuaternionExtensions.AlignedEnough(dockedPosition.transform.rotation, transform.rotation, angleTolerance) && AboutTheSameSize(dockedPositionScale.x, transform.localScale.x)) { // Finished docking dockingState = DockingState.Docked; // Snap to position transform.position = dockedPosition.transform.position; transform.rotation = dockedPosition.transform.rotation; transform.localScale = dockedPositionScale; } } else if (dockedPosition == null && dockingState == DockingState.Undocking) { transform.localScale = Solver.SmoothTo(transform.localScale, originalScale, Time.deltaTime, moveLerpTime); if (AboutTheSameSize(originalScale.x, transform.localScale.x)) { // Finished undocking dockingState = DockingState.Undocked; // Snap to size transform.localScale = originalScale; } } }
public void Update() { if (from_ != null && to_ != null && to_.hasChanged) { if (!VectorExtensions.CloseEnough(to_.position, from_.position, 0.05f) || !QuaternionExtensions.AlignedEnough(to_.rotation, from_.rotation, 3.0f)) { TweenTransformData.Begin(from_.gameObject, 0.1f, new TransformData(to_.position, to_.rotation, from_.lossyScale)); } to_.hasChanged = false; } }