Skip to content

Commit fdf1203

Browse files
author
Unity Technologies
committed
Unity 2018.2.0b3 C# reference source code
1 parent 8001cb7 commit fdf1203

41 files changed

Lines changed: 1046 additions & 768 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModule.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public override void OnModuleActivate()
3737
spriteEditor.enableMouseMoveEvent = true;
3838
}
3939

40+
public override void OnModuleDeactivate()
41+
{
42+
base.OnModuleDeactivate();
43+
m_AlphaPixelCache = null;
44+
}
45+
4046
public override bool CanBeActivated()
4147
{
4248
return SpriteUtility.GetSpriteImportMode(spriteEditor.GetDataProvider<ISpriteEditorDataProvider>()) != SpriteImportMode.Polygon;

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModuleBase.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ internal abstract partial class SpriteFrameModuleBase : SpriteEditorModuleBase
2828
protected ISpriteEditorDataProvider m_SpriteDataProvider;
2929
string m_ModuleName;
3030

31+
internal enum PivotUnitMode
32+
{
33+
Normalized,
34+
Pixels
35+
}
36+
37+
private PivotUnitMode m_PivotUnitMode = PivotUnitMode.Normalized;
38+
3139
protected SpriteFrameModuleBase(string name, ISpriteEditor sw, IEventSystem es, IUndoSystem us, IAssetDatabase ad)
3240
{
3341
spriteEditor = sw;
@@ -169,6 +177,16 @@ public Vector2 selectedSpritePivot
169177
get { return selected.pivot; }
170178
}
171179

180+
private Vector2 selectedSpritePivotInCurUnitMode
181+
{
182+
get
183+
{
184+
return m_PivotUnitMode == PivotUnitMode.Pixels
185+
? ConvertFromNormalizedToRectSpace(selectedSpritePivot, selectedSpriteRect)
186+
: selectedSpritePivot;
187+
}
188+
}
189+
172190
public int CurrentSelectedSpriteIndex()
173191
{
174192
if (m_RectsCache != null && selected != null)
@@ -261,7 +279,7 @@ public bool containsMultipleSprites
261279
get { return spriteImportMode == SpriteImportMode.Multiple; }
262280
}
263281

264-
protected void SnapPivot(Vector2 pivot, out Vector2 outPivot, out SpriteAlignment outAlignment)
282+
protected void SnapPivotToSnapPoints(Vector2 pivot, out Vector2 outPivot, out SpriteAlignment outAlignment)
265283
{
266284
Rect rect = selectedSpriteRect;
267285

@@ -287,6 +305,17 @@ protected void SnapPivot(Vector2 pivot, out Vector2 outPivot, out SpriteAlignmen
287305
outPivot = ConvertFromTextureToNormalizedSpace(snapPoints[(int)snappedAlignment], rect);
288306
}
289307

308+
protected void SnapPivotToPixels(Vector2 pivot, out Vector2 outPivot, out SpriteAlignment outAlignment)
309+
{
310+
outAlignment = SpriteAlignment.Custom;
311+
312+
Rect rect = selectedSpriteRect;
313+
float unitsPerPixelX = 1.0f / rect.width;
314+
float unitsPerPixelY = 1.0f / rect.height;
315+
outPivot.x = Mathf.Round(pivot.x / unitsPerPixelX) * unitsPerPixelX;
316+
outPivot.y = Mathf.Round(pivot.y / unitsPerPixelY) * unitsPerPixelY;
317+
}
318+
290319
private void UndoCallback()
291320
{
292321
UIUndoCallback();

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModuleBaseView.cs

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected static Styles styles
6363

6464
private const float kInspectorWidth = 330f;
6565
private const float kInspectorHeight = 170;
66+
private const float kPivotFieldPrecision = 0.0001f;
6667
private float m_Zoom = 1.0f;
6768
private GizmoMode m_GizmoMode;
6869

@@ -78,6 +79,7 @@ protected static Styles styles
7879
private PropertyControl<long> m_BorderFieldR;
7980
private PropertyControl<long> m_BorderFieldB;
8081
private EnumField m_PivotField;
82+
private EnumField m_PivotUnitModeField;
8183
private VisualElement m_CustomPivotElement;
8284
private PropertyControl<double> m_CustomPivotFieldX;
8385
private PropertyControl<double> m_CustomPivotFieldY;
@@ -221,8 +223,25 @@ private void AddMainUI(VisualElement mainView)
221223
SpriteAlignment alignment = (SpriteAlignment)evt.newValue;
222224
SetSpritePivotAndAlignment(selectedSpritePivot, alignment);
223225
m_CustomPivotElement.SetEnabled(selectedSpriteAlignment == SpriteAlignment.Custom);
224-
m_CustomPivotFieldX.value = selectedSpritePivot.x;
225-
m_CustomPivotFieldY.value = selectedSpritePivot.y;
226+
227+
Vector2 pivot = selectedSpritePivotInCurUnitMode;
228+
m_CustomPivotFieldX.value = pivot.x;
229+
m_CustomPivotFieldY.value = pivot.y;
230+
}
231+
});
232+
233+
234+
m_PivotUnitModeField = m_SelectedFrameInspector.Q<EnumField>("pivotUnitModeField");
235+
m_PivotUnitModeField.Init(PivotUnitMode.Normalized);
236+
m_PivotUnitModeField.OnValueChanged((evt) =>
237+
{
238+
if (hasSelected)
239+
{
240+
m_PivotUnitMode = (PivotUnitMode)evt.newValue;
241+
242+
Vector2 pivot = selectedSpritePivotInCurUnitMode;
243+
m_CustomPivotFieldX.value = pivot.x;
244+
m_CustomPivotFieldY.value = pivot.y;
226245
}
227246
});
228247

@@ -233,8 +252,13 @@ private void AddMainUI(VisualElement mainView)
233252
{
234253
if (hasSelected)
235254
{
255+
float newValue = (float)evt.newValue;
256+
float pivotX = m_PivotUnitMode == PivotUnitMode.Pixels
257+
? ConvertFromRectToNormalizedSpace(new Vector2(newValue, 0.0f), selectedSpriteRect).x
258+
: newValue;
259+
236260
var pivot = selectedSpritePivot;
237-
pivot.x = (float)evt.newValue;
261+
pivot.x = pivotX;
238262
SetSpritePivotAndAlignment(pivot, selectedSpriteAlignment);
239263
}
240264
});
@@ -244,8 +268,13 @@ private void AddMainUI(VisualElement mainView)
244268
{
245269
if (hasSelected)
246270
{
271+
float newValue = (float)evt.newValue;
272+
float pivotY = m_PivotUnitMode == PivotUnitMode.Pixels
273+
? ConvertFromRectToNormalizedSpace(new Vector2(0.0f, newValue), selectedSpriteRect).y
274+
: newValue;
275+
247276
var pivot = selectedSpritePivot;
248-
pivot.y = (float)evt.newValue;
277+
pivot.y = pivotY;
249278
SetSpritePivotAndAlignment(pivot, selectedSpriteAlignment);
250279
}
251280
});
@@ -294,8 +323,12 @@ protected void PopulateSpriteFrameInspectorField()
294323
m_BorderFieldR.value = Mathf.RoundToInt(spriteBorder.z);
295324
m_BorderFieldB.value = Mathf.RoundToInt(spriteBorder.w);
296325
m_PivotField.value = selectedSpriteAlignment;
297-
m_CustomPivotFieldX.value = (selectedSpritePivot.x);
298-
m_CustomPivotFieldY.value = (selectedSpritePivot.y);
326+
m_PivotUnitModeField.value = m_PivotUnitMode;
327+
328+
Vector2 pivot = selectedSpritePivotInCurUnitMode;
329+
m_CustomPivotFieldX.value = pivot.x;
330+
m_CustomPivotFieldY.value = pivot.y;
331+
299332
m_CustomPivotElement.SetEnabled(hasSelected && selectedSpriteAlignment == SpriteAlignment.Custom);
300333
}
301334

@@ -315,6 +348,22 @@ private static Vector2 ConvertFromTextureToNormalizedSpace(Vector2 texturePos, R
315348
return new Vector2((texturePos.x - rect.xMin) / rect.width, (texturePos.y - rect.yMin) / rect.height);
316349
}
317350

351+
private static Vector2 ConvertFromNormalizedToRectSpace(Vector2 normalizedPos, Rect rect)
352+
{
353+
Vector2 rectPos = new Vector2(rect.width * normalizedPos.x, rect.height * normalizedPos.y);
354+
355+
// This is to combat the lack of precision formating on the UI controls.
356+
rectPos.x = Mathf.Round(rectPos.x / kPivotFieldPrecision) * kPivotFieldPrecision;
357+
rectPos.y = Mathf.Round(rectPos.y / kPivotFieldPrecision) * kPivotFieldPrecision;
358+
359+
return rectPos;
360+
}
361+
362+
private static Vector2 ConvertFromRectToNormalizedSpace(Vector2 rectPos, Rect rect)
363+
{
364+
return new Vector2(rectPos.x / rect.width, rectPos.y / rect.height);
365+
}
366+
318367
private static Vector2[] GetSnapPointsArray(Rect rect)
319368
{
320369
Vector2[] snapPoints = new Vector2[9];
@@ -375,7 +424,9 @@ protected void HandlePivotHandle()
375424
{
376425
// Pivot snapping only happen when ctrl is press. Same as scene view snapping move
377426
if (eventSystem.current.control)
378-
SnapPivot(pivotHandlePosition, out pivot, out alignment);
427+
SnapPivotToSnapPoints(pivotHandlePosition, out pivot, out alignment);
428+
else if (m_PivotUnitMode == PivotUnitMode.Pixels)
429+
SnapPivotToPixels(pivotHandlePosition, out pivot, out alignment);
379430
else
380431
{
381432
pivot = pivotHandlePosition;

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpritePolygonModeModule.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ private void DeterminePolygonSides()
5656
else
5757
// If for reasons we cannot determine the sides of the polygon, fall back to 0 (Square)
5858
polygonSides = 0;
59+
ViewUpdateSideCountField();
5960
}
6061

6162
public int GetPolygonSideCount()
@@ -92,5 +93,24 @@ public void GeneratePolygonOutline()
9293
}
9394
Repaint();
9495
}
96+
97+
public override bool ApplyRevert(bool apply)
98+
{
99+
var outlineProvider = spriteEditor.GetDataProvider<ISpriteOutlineDataProvider>();
100+
if (apply)
101+
{
102+
for (int i = 0; i < m_RectsCache.spriteRects.Count && i < m_Outline.Count; ++i)
103+
outlineProvider.SetOutlines(m_RectsCache.spriteRects[i].spriteID, m_Outline[i]);
104+
}
105+
else
106+
{
107+
m_Outline.Clear();
108+
for (int i = 0; i < m_RectsCache.spriteRects.Count; ++i)
109+
m_Outline.Add(outlineProvider.GetOutlines(m_RectsCache.spriteRects[i].spriteID));
110+
DeterminePolygonSides();
111+
ViewUpdateSideCountField();
112+
}
113+
return base.ApplyRevert(apply);
114+
}
95115
}
96116
}

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpritePolygonModeModuleView.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ private void DrawGizmos()
8787
DrawSpriteRectGizmos();
8888
}
8989

90+
private void ViewUpdateSideCountField()
91+
{
92+
var sidesField = m_PolygonShapeView.Q<PropertyControl<long>>("labelIntegerField");
93+
sidesField.value = polygonSides;
94+
}
95+
9096
private void SetupPolygonChangeShapeWindowElements(VisualElement moduleView)
9197
{
9298
var sidesField = moduleView.Q<PropertyControl<long>>("labelIntegerField");

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
[assembly: InternalsVisibleTo("UnityEditor.AR")]
5656
[assembly: InternalsVisibleTo("UnityEditor.SpatialTracking")]
5757
[assembly: InternalsVisibleTo("UnityEditor.HoloLens")]
58+
[assembly: InternalsVisibleTo("Unity.WindowsMRAutomation")]
5859
[assembly: InternalsVisibleTo("Unity.InternalAPIEditorBridge.001")]
5960
[assembly: InternalsVisibleTo("Unity.InternalAPIEditorBridge.002")]
6061
[assembly: InternalsVisibleTo("Unity.InternalAPIEditorBridge.003")]

Editor/Mono/AssetPipeline/TextureImporter.bindings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ public void SetPlatformTextureSettings(string platform, int maxTextureSize, Text
209209
public extern int mipmapFadeDistanceStart { get; set; }
210210
// Mip level where texture is faded out completely.
211211
public extern int mipmapFadeDistanceEnd { get; set; }
212-
public extern bool pushPullDilation { get; set; }
213212

214213
// Should mip maps be generated with gamma correction?
215214
[Obsolete("generateMipsInLinearSpace Property deprecated. Mipmaps are always generated in linear space.")]

Editor/Mono/AssetPipeline/TextureImporterTypes.bindings.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ public sealed partial class TextureImporterSettings
106106
[SerializeField]
107107
int m_SingleChannelComponent;
108108

109-
[SerializeField]
110-
int m_PushPullDilation;
111-
112109
// memory layout of these is in TextureSettings.h
113110
[SerializeField]
114111
[NativeName("m_TextureSettings.m_FilterMode")]
@@ -259,12 +256,6 @@ public TextureImporterSingleChannelComponent singleChannelComponent
259256
set { m_SingleChannelComponent = (int)value; }
260257
}
261258

262-
public bool pushPullDilation
263-
{
264-
get { return m_PushPullDilation != 0; }
265-
set { m_PushPullDilation = value ? 1 : 0; }
266-
}
267-
268259
public bool readable
269260
{
270261
get {return m_IsReadable != 0; }

Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ internal static bool UseIl2CppCodegenWithMonoBackend(BuildTargetGroup targetGrou
124124

125125
internal static bool EnableIL2CPPDebugger(BuildTargetGroup targetGroup)
126126
{
127-
if (!EditorUserBuildSettings.allowDebugging)
127+
if (!EditorUserBuildSettings.allowDebugging || !EditorUserBuildSettings.development)
128128
return false;
129129

130130
switch (PlayerSettings.GetApiCompatibilityLevel(targetGroup))

Editor/Mono/BuildPlayerSceneTreeView.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ public void UpdateName()
3636
}
3737
}
3838

39-
public BuildPlayerSceneTreeViewItem(int id, int depth, string path, bool state) : base(id, depth)
39+
public BuildPlayerSceneTreeViewItem(int id, int depth, GUID g, bool state) : base(id, depth)
4040
{
4141
active = state;
4242
counter = kInvalidCounter;
43-
guid = new GUID(AssetDatabase.AssetPathToGUID(path));
43+
guid = g;
4444
fullName = "";
45-
displayName = path;
4645
UpdateName();
4746
}
4847
}
@@ -72,7 +71,7 @@ protected override TreeViewItem BuildRoot()
7271
List<EditorBuildSettingsScene> scenes = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes);
7372
foreach (var sc in scenes)
7473
{
75-
var item = new BuildPlayerSceneTreeViewItem(sc.guid.GetHashCode(), 0, sc.path, sc.enabled);
74+
var item = new BuildPlayerSceneTreeViewItem(sc.guid.GetHashCode(), 0, sc.guid, sc.enabled);
7675
root.AddChild(item);
7776
}
7877
return root;

0 commit comments

Comments
 (0)