Skip to content

Commit 8666305

Browse files
author
Unity Technologies
committed
Unity 2018.1.0b2 C# reference source code
1 parent d0c56c7 commit 8666305

69 files changed

Lines changed: 2650 additions & 3534 deletions

File tree

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/SpriteEditorData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal class SpriteDataExt : SpriteRect
1616
{
1717
public List<SpriteBone> spriteBone;
1818
public float tessellationDetail = 0;
19+
20+
// The following lists are to be left un-initialized.
21+
// If they never loaded or assign explicitly, we avoid writing empty list to metadata.
1922
public List<Vector2[]> spriteOutline;
2023
public List<Vertex2DMetaData> vertices;
2124
public List<int> indices;
@@ -36,9 +39,6 @@ internal SpriteDataExt(SpriteRect sr)
3639
spriteID = sr.spriteID;
3740
alignment = sr.alignment;
3841
pivot = sr.pivot;
39-
spriteOutline = new List<Vector2[]>();
40-
spritePhysicsOutline = new List<Vector2[]>();
41-
spriteBone = new List<SpriteBone>();
4242
}
4343

4444
public void Apply(SerializedObject so)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public override void OnModuleActivate()
5050
textureActualHeight = height;
5151
m_RectsCache = ScriptableObject.CreateInstance<SpriteRectModel>();
5252
m_RectsCache.spriteRects = m_SpriteDataProvider.GetSpriteRects().ToList();
53+
spriteEditor.spriteRects = m_RectsCache.spriteRects;
5354
if (spriteEditor.selectedSpriteRect != null)
5455
spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID);
5556
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SpriteRect[] ISpriteEditorDataProvider.GetSpriteRects()
3232

3333
void ISpriteEditorDataProvider.SetSpriteRects(SpriteRect[] spriteRects)
3434
{
35-
if (spriteImportMode == SpriteImportMode.Single && spriteRects.Length == 1)
35+
if (spriteImportMode != SpriteImportMode.Multiple && spriteImportMode != SpriteImportMode.None && spriteRects.Length == 1)
3636
{
3737
m_SpriteSingle.CopyFromSpriteRect(spriteRects[0]);
3838
}

Editor/Mono/Commands/GOCreationCommands.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal static void Place(GameObject go, GameObject parent)
2121
if (parent != null)
2222
{
2323
var transform = go.transform;
24-
transform.SetParent(parent.transform, false);
24+
Undo.SetTransformParent(transform, parent.transform, "Reparenting");
2525
transform.localPosition = Vector3.zero;
2626
transform.localRotation = Quaternion.identity;
2727
transform.localScale = Vector3.one;
@@ -30,7 +30,10 @@ internal static void Place(GameObject go, GameObject parent)
3030
if (parent.GetComponent<RectTransform>())
3131
ObjectFactory.AddComponent<RectTransform>(go);
3232
}
33-
SceneView.PlaceGameObjectInFrontOfSceneView(go);
33+
else
34+
{
35+
SceneView.PlaceGameObjectInFrontOfSceneView(go);
36+
}
3437
EditorWindow.FocusWindowIfItsOpen<SceneHierarchyWindow>();
3538
Selection.activeGameObject = go;
3639
}

Editor/Mono/EditorGUI.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,12 @@ internal static string TextFieldInternal(Rect position, GUIContent label, string
14311431
return text;
14321432
}
14331433

1434+
internal static string ToolbarSearchField(Rect position, string text, bool showWithPopupArrow)
1435+
{
1436+
int id = GUIUtility.GetControlID(s_SearchFieldHash, FocusType.Keyboard, position);
1437+
return ToolbarSearchField(id, position, text, showWithPopupArrow);
1438+
}
1439+
14341440
internal static string ToolbarSearchField(int id, Rect position, string text, bool showWithPopupArrow)
14351441
{
14361442
bool dummy;
@@ -4195,6 +4201,8 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
41954201
{
41964202
Color c = EyeDropper.GetPickedColor();
41974203
c.a = value.a;
4204+
if (hdr)
4205+
c = c.linear;
41984206
EditorGUIUtility.DrawColorSwatch(position2, c, showAlpha, hdr);
41994207
}
42004208
else
@@ -4246,7 +4254,7 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
42464254
Color c = EyeDropper.GetLastPickedColor();
42474255
c.a = value.a;
42484256
s_ColorPickID = 0;
4249-
return c;
4257+
return hdr ? c.linear : c;
42504258
case EventCommandNames.EyeDropperCancelled:
42514259
HandleUtility.Repaint();
42524260
s_ColorPickID = 0;

Editor/Mono/GUI/ColorMutator.cs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@ internal class ColorMutator
2020
// this is the value used by Photoshop
2121
private const byte k_MaxByteForOverexposedColor = 191;
2222

23+
internal static void DecomposeHdrColor(Color linearColorHdr, out Color32 baseLinearColor, out float exposure)
24+
{
25+
baseLinearColor = linearColorHdr;
26+
var maxColorComponent = linearColorHdr.maxColorComponent;
27+
// replicate Photoshops's decomposition behaviour
28+
if (maxColorComponent == 0f || maxColorComponent <= 1f && maxColorComponent > 1 / 255f)
29+
{
30+
exposure = 0f;
31+
32+
baseLinearColor.r = (byte)Mathf.RoundToInt(linearColorHdr.r * 255f);
33+
baseLinearColor.g = (byte)Mathf.RoundToInt(linearColorHdr.g * 255f);
34+
baseLinearColor.b = (byte)Mathf.RoundToInt(linearColorHdr.b * 255f);
35+
}
36+
else
37+
{
38+
// calibrate exposure to the max float color component
39+
var scaleFactor = k_MaxByteForOverexposedColor / maxColorComponent;
40+
exposure = Mathf.Log(255f / scaleFactor) / Mathf.Log(2f);
41+
42+
// maintain maximal integrity of byte values to prevent off-by-one errors when scaling up a color one component at a time
43+
baseLinearColor.r = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * linearColorHdr.r));
44+
baseLinearColor.g = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * linearColorHdr.g));
45+
baseLinearColor.b = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * linearColorHdr.b));
46+
}
47+
}
48+
2349
public Color originalColor
2450
{
2551
get { return m_OriginalColor; }
@@ -177,28 +203,11 @@ void OnRgbaHdrChannelChanged(int channel)
177203
if (channel == (int)RgbaChannel.A)
178204
return;
179205

180-
var newColor = exposureAdjustedColor;
181-
var maxColorComponent = newColor.maxColorComponent;
182-
// replicate Photoshops's decomposition behaviour
183-
if (maxColorComponent == 0f || maxColorComponent <= 1f && maxColorComponent > 1 / 255f)
184-
{
185-
m_ExposureValue = 0f;
186-
187-
m_Color[(int)RgbaChannel.R] = (byte)Mathf.RoundToInt(newColor.r * 255f);
188-
m_Color[(int)RgbaChannel.G] = (byte)Mathf.RoundToInt(newColor.g * 255f);
189-
m_Color[(int)RgbaChannel.B] = (byte)Mathf.RoundToInt(newColor.b * 255f);
190-
}
191-
else
192-
{
193-
// calibrate exposure to the max float color component
194-
var scaleFactor = k_MaxByteForOverexposedColor / maxColorComponent;
195-
m_ExposureValue = Mathf.Log(255f / scaleFactor) / Mathf.Log(2f);
196-
197-
// maintain maximal integrity of byte values to prevent off-by-one errors when scaling up a color one component at a time
198-
m_Color[0] = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * m_ColorHdr[0]));
199-
m_Color[1] = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * m_ColorHdr[1]));
200-
m_Color[2] = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * m_ColorHdr[2]));
201-
}
206+
Color32 baseColor;
207+
DecomposeHdrColor(exposureAdjustedColor, out baseColor, out m_ExposureValue);
208+
m_Color[(int)RgbaChannel.R] = baseColor.r;
209+
m_Color[(int)RgbaChannel.G] = baseColor.g;
210+
m_Color[(int)RgbaChannel.B] = baseColor.b;
202211
Color.RGBToHSV(
203212
color,
204213
out m_Hsv[(int)HsvChannel.H],

0 commit comments

Comments
 (0)