// Rotate the visualizer or whatever object is selected public static GameObject RotateObject() { GameObject gameObject = GetObjectToManipulate(MAST_Placement_Visualizer.GetGameObject()); if (gameObject != null) { // Make this an Undo point, just before rotating the existing object if (allowUndoRegistering) { Undo.RegisterCompleteObjectUndo(gameObject.transform, "Rotated GameObject"); allowUndoRegistering = false; } // TODO: Add code to see if local space rotation allows this rotation // This is different from world space // OnScene Change Target Axis Icon Button switch (rotateAxis) { case Axis.X: gameObject.transform.Rotate(MAST_Placement_Helper.GetRotationFactor().x, 0f, 0f, Space.World); break; case Axis.Y: gameObject.transform.Rotate(0f, MAST_Placement_Helper.GetRotationFactor().y, 0f, Space.World); break; case Axis.Z: gameObject.transform.Rotate(0f, 0f, MAST_Placement_Helper.GetRotationFactor().z, Space.World); break; } // Remember this rotation for future prefab placement currentRotation = gameObject.transform.rotation; } // Return rotated GameObject return(gameObject); }
// See if new selected Prefab will allow the saved rotation private static bool IsSavedRotationValidForVisualizer() { // If there is a saved rotation if (MAST_Placement_Manipulate.GetCurrentRotation() != null) { // If the current saved rotation is allowed by the prefab // (If allowed rotation divides evenly into current rotation) // or (Both allowed and current rotations are set to 0) if (((int)(MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.x % MAST_Placement_Helper.GetRotationFactor().x) == 0) || (int)MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.x == 0 && (int)MAST_Placement_Helper.GetRotationFactor().x == 0) { if (((int)(MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.y % MAST_Placement_Helper.GetRotationFactor().y) == 0) || (int)MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.y == 0 && (int)MAST_Placement_Helper.GetRotationFactor().y == 0) { if (((int)(MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.z % MAST_Placement_Helper.GetRotationFactor().z) == 0) || (int)MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.z == 0 && (int)MAST_Placement_Helper.GetRotationFactor().z == 0) { // Return true, since saved rotation is allowed return(true); } } } } // Return false, since saved rotation is not allowed return(false); }