/// <summary> /// Set the world state values of the current Transform /// </summary> /// <param name="transform">The transform that is to be modified</param> /// <param name="state">The Transform State values that are to be applied locally</param> /// <param name="modifyParent">Flags if the parent should also be modified by this operation</param> public static void SetWorldTransformState(this Transform transform, TransformState state, bool modifyParent = false) { //Stash the previous transform parent object if (!modifyParent) { state.parent = transform.parent; } //Remove the current parent reference transform.SetParent(null, true); //Set the scale value transform.localScale = state.scale; //Reset the transform parent transform.SetParent(state.parent); //Reset the sibling index if (modifyParent) { transform.SetSiblingIndex(state.siblingIndex); } //Set the remaining values transform.position = state.position; transform.rotation = state.rotation; }
/// <summary> /// Set the local state values of the current Transform /// </summary> /// <param name="transform">The transform that is to be modified</param> /// <param name="state">The Transform State values that are to be applied locally</param> /// <param name="modifyParent">Flags if the parent should also be modified by this operation</param> public static void SetLocalTransformState(this Transform transform, TransformState state, bool modifyParent = false) { //Reset the parent value if (modifyParent) { transform.parent = state.parent; transform.SetSiblingIndex(state.siblingIndex); } //Set the default values transform.localPosition = state.position; transform.localRotation = state.rotation; transform.localScale = state.scale; }