Skip to content

Commit 45349b6

Browse files
author
Karl Henkel
authored
Merge pull request #376 from Unity-Technologies/bugfixes-5x-release
Bugfixes 5x release
2 parents 7630976 + 5b83cfc commit 45349b6

19 files changed

Lines changed: 262 additions & 111 deletions

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [5.0.2] - 2021-03-11
9+
10+
### Bug Fixes
11+
12+
- Fixed `Draw Shape` tool showing incorrect UVs when setting shape bounding box.
13+
- Fixed `Draw Shape` tool not clearing selection when changing the active shape type.
14+
- Fixed `Cut Tool` error when pressing `Backspace` with no vertices placed.
15+
- Fixed `Cut Tool` error when finishing a cut segment with less than 3 vertices.
16+
- Fixed `Draw Shape` tool truncating shape property fields in the Scene View Overlay.
17+
18+
### Changes
19+
20+
- Moved contents of warning box in `Draw Shape` tool to tooltips.
21+
822
## [5.0.1] - 2021-03-09
923

1024
### Bug Fixes

Debug/Editor/Guides.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using UnityEditor;
2+
using UnityEditor.SettingsManagement;
3+
using UnityEngine;
4+
using UnityEngine.Rendering;
5+
6+
namespace ProBuilder.Debug.Editor
7+
{
8+
static class GuidesSettingsProvider
9+
{
10+
const string k_PreferencesPath = "Preferences/Scene Guides";
11+
static Settings s_Settings;
12+
public static Settings settings => s_Settings ?? (s_Settings = new Settings("com.unity.scene-guides"));
13+
14+
[SettingsProvider]
15+
static SettingsProvider CreateSettingsProvider()
16+
{
17+
var provider = new UserSettingsProvider(k_PreferencesPath,
18+
settings,
19+
new[] { typeof(GuidesSettingsProvider).Assembly });
20+
21+
settings.afterSettingsSaved += HandleUtility.Repaint;
22+
23+
return provider;
24+
}
25+
}
26+
27+
class Pref<T> : UserSetting<T>
28+
{
29+
public Pref(string key, T value, SettingsScope scope = SettingsScope.Project)
30+
: base(GuidesSettingsProvider.settings, key, value, scope) { }
31+
}
32+
33+
static class Guides
34+
{
35+
[UserSetting("World Space", "Origin Axes", "Shows 3 axis guides from the scene view origin.")]
36+
static Pref<bool> s_SceneOrigin = new Pref<bool>("Guides.s_SceneOrigin", false);
37+
38+
[UserSetting("Selection", "Transform Pivot", "Draw a gizmo at the origin of each selected transform.")]
39+
static Pref<bool> s_SelectionPivot = new Pref<bool>("Guides.s_SelectionPivot", false);
40+
41+
static Vector3 zero = Vector3.zero,
42+
up = new Vector3(0f, 1f, 0f),
43+
right = new Vector3(1f, 0f, 0f),
44+
forward = new Vector3(0f, 0f, 1f);
45+
46+
[InitializeOnLoadMethod]
47+
static void Init()
48+
{
49+
SceneView.duringSceneGui += view =>
50+
{
51+
var evt = Event.current;
52+
53+
if (evt.type != EventType.Repaint)
54+
return;
55+
56+
if (s_SceneOrigin)
57+
{
58+
var dist = view.camera.farClipPlane / 10f;
59+
60+
DrawLine(zero, right * dist, Handles.xAxisColor);
61+
DrawLine(zero, right * -dist, Handles.xAxisColor * .7f);
62+
63+
DrawLine(zero, up * dist, Handles.yAxisColor);
64+
DrawLine(zero, up * -dist, Handles.yAxisColor * .7f);
65+
66+
DrawLine(zero, forward * dist, Handles.zAxisColor);
67+
DrawLine(zero, forward * -dist, Handles.zAxisColor * .7f);
68+
}
69+
70+
if (s_SelectionPivot)
71+
{
72+
foreach (var transform in Selection.transforms)
73+
DrawPivot(transform);
74+
}
75+
};
76+
}
77+
78+
static void DrawPivot(Transform transform)
79+
{
80+
using (new Handles.DrawingScope(transform.localToWorldMatrix))
81+
{
82+
DrawLine(zero, right * .2f, Handles.xAxisColor, 1f, 3f);
83+
DrawLine(zero, up * .2f, Handles.yAxisColor, 1f, 3f);
84+
DrawLine(zero, forward * .2f, Handles.zAxisColor, 1f, 3f);
85+
}
86+
}
87+
88+
static void DrawLine(Vector3 from, Vector3 to, Color color, float occludedTint = .7f, float thickness = 0f)
89+
{
90+
Handles.color = color;
91+
Handles.zTest = CompareFunction.LessEqual;
92+
#if UNITY_2021_1_OR_NEWER
93+
Handles.DrawLine(from, to, thickness);
94+
#else
95+
Handles.DrawLine(from, to);
96+
#endif
97+
98+
Handles.color = color * occludedTint;
99+
Handles.zTest = CompareFunction.Greater;
100+
#if UNITY_2021_1_OR_NEWER
101+
Handles.DrawLine(from, to, thickness);
102+
#else
103+
Handles.DrawLine(from, to);
104+
#endif
105+
}
106+
}
107+
}

Debug/Editor/Guides.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "Unity.ProBuilder.Debug.Editor",
3+
"rootNamespace": "",
34
"references": [
45
"Unity.ProBuilder",
56
"Unity.ProBuilder.Editor",
6-
"Unity.ProBuilder.AssetIdRemapUtility"
7+
"Unity.ProBuilder.AssetIdRemapUtility",
8+
"Unity.Settings.Editor"
79
],
8-
"optionalUnityReferences": [],
910
"includePlatforms": [
1011
"Editor"
1112
],
@@ -14,5 +15,7 @@
1415
"overrideReferences": false,
1516
"precompiledReferences": [],
1617
"autoReferenced": false,
17-
"defineConstraints": []
18+
"defineConstraints": [],
19+
"versionDefines": [],
20+
"noEngineReferences": false
1821
}

Editor/EditorCore/CutTool.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ public bool isALoop
133133
{
134134
if (m_CutPath.Count < 3)
135135
return false;
136-
else
137-
return Math.Approx3(m_CutPath[0].position,
138-
m_CutPath[m_CutPath.Count - 1].position);
136+
137+
return Math.Approx3(m_CutPath[0].position, m_CutPath[m_CutPath.Count - 1].position);
139138
}
140139
}
141140

@@ -409,9 +408,13 @@ void HandleKeyEvent(Event evt)
409408
{
410409
case KeyCode.Backspace:
411410
{
412-
UndoUtility.RecordObject(m_Mesh, "Delete Selected Points");
413-
m_CutPath.RemoveAt(m_CutPath.Count-1);
414-
m_Dirty = true;
411+
if (m_CutPath.Count > 0)
412+
{
413+
UndoUtility.RecordObject(m_Mesh, "Delete Selected Points");
414+
m_CutPath.RemoveAt(m_CutPath.Count - 1);
415+
m_Dirty = true;
416+
}
417+
415418
evt.Use();
416419
break;
417420
}
@@ -513,9 +516,7 @@ void DoPointPlacement()
513516
&& evtType == EventType.MouseDown
514517
&& HandleUtility.nearestControl == m_ControlId)
515518
{
516-
int polyCount = m_CutPath.Count;
517-
if (!m_CurrentPosition.Equals(Vector3.positiveInfinity)
518-
&& (polyCount == 0 || m_SelectedIndex != polyCount - 1))
519+
if(CanAppendCurrentPointToPath())
519520
{
520521
AddCurrentPositionToPath();
521522
evt.Use();
@@ -532,6 +533,26 @@ void DoPointPlacement()
532533
}
533534
}
534535

536+
bool CanAppendCurrentPointToPath()
537+
{
538+
int polyCount = m_CutPath.Count;
539+
540+
if (!Math.IsNumber(m_CurrentPosition))
541+
return false;
542+
543+
if (!(polyCount == 0 || m_SelectedIndex != polyCount - 1))
544+
return false;
545+
546+
// duplicate points are not permitted, except the special case where placing a final point on the starting
547+
// point finishes the cut operation.
548+
for(int i = 1; i < polyCount; i++)
549+
if (Math.Approx3(m_CutPath[i].position, m_CurrentPosition))
550+
return false;
551+
552+
// when the existing vertex count is less than 3, don't allow the special duplicate first vertex position
553+
return polyCount < 2 || !(polyCount < 3 && Math.Approx3(m_CutPath[0].position, m_CurrentPosition));
554+
}
555+
535556
internal void AddCurrentPositionToPath(bool optimize = true)
536557
{
537558
UndoUtility.RecordObject(this, "Add Vertex On Path");

Editor/EditorCore/DrawShapeTool.cs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using UnityEngine.ProBuilder;
66
using UnityEngine.ProBuilder.Shapes;
7+
using Math = UnityEngine.ProBuilder.Math;
78
using UObject = UnityEngine.Object;
89
#if UNITY_2020_2_OR_NEWER
910
using ToolManager = UnityEditor.EditorTools.ToolManager;
@@ -238,22 +239,32 @@ internal void SetBounds(Vector3 size)
238239
m_BB_HeightCorner = m_BB_Origin + size;
239240
}
240241

241-
internal void DuplicatePreview(Vector3 position)
242+
internal void DoDuplicateShapePreviewHandle(Vector3 position)
242243
{
243-
if(position.Equals(Vector3.positiveInfinity) || !Event.current.isMouse)
244+
var evt = Event.current;
245+
246+
if(evt.type != EventType.Repaint)
247+
return;
248+
249+
bool previewShortcutActive = evt.shift && !(evt.control || evt.command);
250+
251+
if (HandleUtility.nearestControl != m_ControlID || !previewShortcutActive)
252+
{
253+
DestroyImmediate(m_DuplicateGO);
244254
return;
255+
}
245256

246257
var pivotLocation = (PivotLocation)s_LastPivotLocation.value;
247258
var size = currentShapeInOverlay.size;
248259

249260
m_Bounds.size = size;
250-
251261
Vector3 cornerPosition;
252-
switch(pivotLocation)
262+
263+
switch (pivotLocation)
253264
{
254265
case PivotLocation.FirstCorner:
255266
cornerPosition = GetPoint(position);
256-
m_PlaneRotation = Quaternion.LookRotation(m_PlaneForward,m_Plane.normal);
267+
m_PlaneRotation = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);
257268
m_Bounds.center = cornerPosition + m_PlaneRotation * size / 2f;
258269

259270
m_BB_Origin = cornerPosition;
@@ -266,32 +277,37 @@ internal void DuplicatePreview(Vector3 position)
266277
position = GetPoint(position);
267278
cornerPosition = position - size / 2f;
268279
cornerPosition.y = position.y;
269-
m_Bounds.center = cornerPosition + new Vector3(size.x/2f,0, size.z/2f) + (size.y / 2f) * m_Plane.normal;
270-
m_PlaneRotation = Quaternion.LookRotation(m_PlaneForward,m_Plane.normal);
280+
m_Bounds.center = cornerPosition + new Vector3(size.x / 2f, 0, size.z / 2f) + (size.y / 2f) * m_Plane.normal;
281+
m_PlaneRotation = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);
271282

272283
m_BB_Origin = m_Bounds.center - m_PlaneRotation * (size / 2f);
273284
m_BB_HeightCorner = m_Bounds.center + m_PlaneRotation * (size / 2f);
274285
m_BB_OppositeCorner = m_BB_HeightCorner - m_PlaneRotation * new Vector3(0, size.y, 0);
275286
break;
276287
}
277288

278-
ProBuilderShape proBuilderShape;
279-
280-
if(m_DuplicateGO == null)
289+
if (m_DuplicateGO == null)
281290
{
282291
var instantiated = ShapeFactory.Instantiate(activeShapeType, ((PivotLocation)s_LastPivotLocation.value));
283-
proBuilderShape = instantiated.GetComponent<ProBuilderShape>();
284-
m_DuplicateGO = proBuilderShape.gameObject;
292+
var shape = instantiated.GetComponent<ProBuilderShape>();
293+
m_DuplicateGO = shape.gameObject;
285294
m_DuplicateGO.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy;
286-
ApplyPrefsSettings(proBuilderShape);
287-
proBuilderShape.GetComponent<MeshRenderer>().sharedMaterial = m_ShapePreviewMaterial;
295+
ApplyPrefsSettings(shape);
296+
shape.GetComponent<MeshRenderer>().sharedMaterial = m_ShapePreviewMaterial;
297+
298+
EditorShapeUtility.CopyLastParams(shape.shape, shape.shape.GetType());
299+
shape.Rebuild(m_Bounds, m_PlaneRotation, m_BB_Origin);
300+
ProBuilderEditor.Refresh(false);
288301
}
289-
else
290-
proBuilderShape = m_DuplicateGO.GetComponent<ProBuilderShape>();
291302

292-
EditorShapeUtility.CopyLastParams(proBuilderShape.shape, proBuilderShape.shape.GetType());
293-
proBuilderShape.Rebuild(m_Bounds, m_PlaneRotation);
294-
ProBuilderEditor.Refresh(false);
303+
var pivot = GetPoint(position);
304+
if (pivotLocation == PivotLocation.Center)
305+
pivot += m_Plane.normal * size.y * .5f;
306+
307+
m_DuplicateGO.transform.position = pivot;
308+
m_DuplicateGO.transform.rotation = Quaternion.LookRotation(m_PlaneForward, m_Plane.normal);
309+
310+
DrawBoundingBox(false);
295311
}
296312

297313
void RecalculateBounds()
@@ -343,7 +359,7 @@ internal void RebuildShape()
343359
m_IsShapeInit = true;
344360
}
345361

346-
m_ProBuilderShape.Rebuild(m_Bounds, m_PlaneRotation);
362+
m_ProBuilderShape.Rebuild(m_Bounds, m_PlaneRotation, m_BB_Origin);
347363
ProBuilderEditor.Refresh(false);
348364

349365
SceneView.RepaintAll();
@@ -390,8 +406,6 @@ internal void DrawBoundingBox(bool drawCorners = true)
390406

391407
void OnOverlayGUI(UObject overlayTarget, SceneView view)
392408
{
393-
EditorGUILayout.HelpBox(L10n.Tr("Click and drag to place and scale the shape, or SHIFT+click once to duplicate last size settings."), MessageType.Info);
394-
395409
DrawShapeGUI();
396410

397411
#if !UNITY_2021_1_OR_NEWER
@@ -463,6 +477,7 @@ void DrawShapeGUI()
463477
m_LastShapeCreated = null;
464478

465479
UndoUtility.RegisterCompleteObjectUndo(currentShapeInOverlay, "Change Shape");
480+
Selection.activeObject = null;
466481
currentShapeInOverlay.SetShape(EditorShapeUtility.CreateShape(type), currentShapeInOverlay.pivotLocation);
467482
SetBounds(currentShapeInOverlay.size);
468483

Editor/EditorCore/EditorShapeUtility.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ static class EditorShapeUtility
1212
{
1313
[UserSetting]
1414
public static Pref<bool> s_ResetUserPrefs = new Pref<bool>("ShapeComponent.ResetSettings", true);
15-
1615
static Dictionary<string, Shape> s_Prefs = new Dictionary<string, Shape>();
16+
static readonly string k_Tooltip = L10n.Tr("Click and drag to place and scale the shape, or SHIFT+click once to duplicate last size settings.");
1717

1818
static Dictionary<string, Shape> prefs
1919
{
@@ -76,7 +76,7 @@ public static List<GUIContent[]> shapeTypesGUI
7676
if(s_ShapeTypesGUILists == null)
7777
{
7878
s_ShapeTypesGUILists = new List<GUIContent[]>();
79-
string[] shapeTypeNames = availableShapeTypes.Select(x => ((ShapeAttribute)System.Attribute.GetCustomAttribute(x, typeof(ShapeAttribute))).name).ToArray();
79+
string[] shapeTypeNames = availableShapeTypes.Select(x => ((ShapeAttribute) Attribute.GetCustomAttribute(x, typeof(ShapeAttribute))).name).ToArray();
8080
GUIContent[] shapeTypesGUI = null;
8181

8282
int i;
@@ -91,9 +91,9 @@ public static List<GUIContent[]> shapeTypesGUI
9191
var name = shapeTypeNames[i];
9292
var texture = IconUtility.GetIcon("Tools/ShapeTool/" + name);
9393
if(texture != null)
94-
shapeTypesGUI[i % s_MaxContentPerGroup] = new GUIContent(texture, name);
94+
shapeTypesGUI[i % s_MaxContentPerGroup] = new GUIContent(texture, k_Tooltip);
9595
else
96-
shapeTypesGUI[i % s_MaxContentPerGroup] = new GUIContent(name, name);
96+
shapeTypesGUI[i % s_MaxContentPerGroup] = new GUIContent(name, k_Tooltip);
9797
}
9898

9999
if(shapeTypesGUI != null) s_ShapeTypesGUILists.Add(shapeTypesGUI);

Editor/EditorCore/EditorUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static class EditorUtility
4242
static Pref<bool> s_MeshColliderIsConvex = new Pref<bool>("mesh.meshColliderIsConvex", false);
4343

4444
[UserSetting("Mesh Settings", "Pivot Location", "Determines the placement of new shape's pivot.")]
45-
static Pref<PivotLocation> s_NewShapesPivotAtCenter = new Pref<PivotLocation>("mesh.newShapePivotLocation", PivotLocation.Center);
45+
static Pref<PivotLocation> s_NewShapesPivotAtCenter = new Pref<PivotLocation>("mesh.newShapePivotLocation", PivotLocation.FirstCorner);
4646

4747
[UserSetting("Mesh Settings", "Snap New Shape To Grid", "When enabled, new shapes will snap to the closest point on grid.")]
4848
static Pref<bool> s_SnapNewShapesToGrid = new Pref<bool>("mesh.newShapesSnapToGrid", true);

Editor/EditorCore/Experimental.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static void ExperimentalFeaturesSettings(string searchContext)
3131

3232
EditorGUI.BeginChangeCheck();
3333

34+
EditorGUILayout.HelpBox("Enabling Experimental Features will cause Unity to recompile scripts.", MessageType.Warning);
3435
enabled = SettingsGUILayout.SearchableToggle("Experimental Features Enabled", enabled, searchContext);
3536

3637
if (EditorGUI.EndChangeCheck())

0 commit comments

Comments
 (0)