/// <summary> /// Moves toMove, retaining the local position, scale, rotation. /// /// This is in contrast to simply modifying Transform.parent, which modifies /// the local transformation state to retain the same world-space result. /// </summary> /// <param name="toMove">The Transform to reparent.</param> /// <param name="newParent">The new parent Transform.</param> public static void MoveToParent(Transform toMove, Transform newParent) { var state = new TransformState(toMove); toMove.parent = newParent; state.Revert(); }
/// <summary> /// Updates references to Transform objects that we're interested in. /// </summary> private void UpdateTransformReferences() { Transform newParent; if (relativeTrn == null) { if (FlightGlobals.ActiveVessel == null) { newParent = null; } else { newParent = FlightGlobals.ActiveVessel.transform; } } else { newParent = relativeTrn; } TransformState.MoveToParent(destructionProxy.transform, newParent); TransformState.ResetTransformToIdentity(destructionProxy.transform); TransformState.ResetTransformToIdentity(transform); // For FlightCamera, the second transform is that for the FlightCamera itself. secondTrn = new TransformState(FlightCamera.fetch.transform); // ... and the transform parent is the "main camera pivot". firstTrn = new TransformState(secondTrn.Transform.parent); }
private void ReplaceProxy() { if (destructionProxy != null) { destructionProxy.onDestroy -= this.OnProxyDestroyed; } GameObject obj = new GameObject("KerbCam.CameraController DestructionProxy"); destructionProxy = obj.AddComponent <DestructionProxy>(); destructionProxy.onDestroy += OnProxyDestroyed; TransformState.MoveToParent(transform, destructionProxy.transform); }
private void ReacquireFlightCamera() { if (!isControlling) { return; } FlightCamera.fetch.DeactivateUpdate(); UpdateTransformReferences(); // Store the first and second transform states, for when we release the camera. firstTrn.Store(); secondTrn.Store(); // The CameraController becomes the parent transform for the camera transforms. TransformState.MoveToParent(firstTrn.Transform, transform); }