public void SetManualFaceToAuto_MatchesOriginalUVs( [ValueSource("AutoUVOffsetParameters")] Vector2 offset, [ValueSource("AutoUVRotationParameters")] float rotation, [ValueSource("AutoUVScaleParameters")] Vector2 scale) { var unwrap = face.uv; unwrap.offset = offset; unwrap.rotation = rotation; unwrap.scale = scale; face.uv = unwrap; // Verify that UV settings have actually been applied Assume.That(face.uv.offset, Is.EqualTo(offset)); Assume.That(face.uv.rotation, Is.EqualTo(rotation)); Assume.That(face.uv.scale, Is.EqualTo(scale)); Assume.That(face.manualUV, Is.EqualTo(false)); mesh.Refresh(RefreshMask.UV); // Verify that the UVs are in the correct place Assume.That(GetEdgeRotation(mesh, verticalEdge), Is.EqualTo(rotation).Within(.1f)); Assume.That(GetEdgeScale(mesh, verticalEdge), Is.EqualTo(scale.y).Within(.1f)); Assume.That(GetEdgeScale(mesh, horizontalEdge), Is.EqualTo(scale.x).Within(.1f)); // Offset is flipped in code for legacy reasons var center = Bounds2D.Center(mesh.texturesInternal, face.distinctIndexesInternal); Assume.That(center.x, Is.EqualTo(-offset.x).Within(.1f)); Assume.That(center.y, Is.EqualTo(-offset.y).Within(.1f)); face.uv = AutoUnwrapSettings.defaultAutoUnwrapSettings; face.manualUV = true; // Verify that UV settings have been reset Assume.That(face.uv.offset, Is.EqualTo(new Vector2(0f, 0f))); Assume.That(face.uv.rotation, Is.EqualTo(0f)); Assume.That(face.uv.scale, Is.EqualTo(new Vector2(1f, 1f))); Assume.That(face.manualUV, Is.EqualTo(true)); // This sets the manualFlag to false, sets the AutoUnwrap settings, and rebuilds UVs UVEditing.SetAutoAndAlignUnwrapParamsToUVs(mesh, new [] { face }); Assert.That(face.uv.offset.x, Is.EqualTo(offset.x).Within(.1f)); Assert.That(face.uv.offset.y, Is.EqualTo(offset.y).Within(.1f)); Assert.That(face.uv.rotation, Is.EqualTo(rotation).Within(.1f)); Assert.That(face.uv.scale.x, Is.EqualTo(scale.x).Within(.1f)); Assert.That(face.uv.scale.y, Is.EqualTo(scale.y).Within(.1f)); Assert.That(face.manualUV, Is.EqualTo(false)); }
protected override void OnToolDisengaged() { var isFaceMode = ProBuilderEditor.selectMode.ContainsFlag(SelectMode.TextureFace | SelectMode.Face); foreach (var mesh in elementSelection) { if (!(mesh is MeshAndTextures)) { continue; } var textures = ((MeshAndTextures)mesh).textures; mesh.mesh.SetUVs(k_TextureChannel, textures); if (isFaceMode) { UVEditing.SetAutoAndAlignUnwrapParamsToUVs(mesh.mesh, mesh.mesh.selectedFacesInternal.Where(x => !x.manualUV)); } else { var indices = new HashSet <int>(mesh.elementGroups.SelectMany(x => x.indices)); foreach (var face in mesh.mesh.facesInternal) { foreach (var index in face.distinctIndexesInternal) { if (indices.Contains(index)) { face.manualUV = true; break; } } } } } }