Skip to content

Commit

Permalink
Unity 2018.2.0a1 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Feb 20, 2018
1 parent d0c56c7 commit 02f8e8c
Show file tree
Hide file tree
Showing 827 changed files with 43,950 additions and 47,656 deletions.
Expand Up @@ -16,7 +16,14 @@ public static GUID GetSpriteID(this Sprite sprite)
return new GUID(GetSpriteIDScripting(sprite));
}

public static void SetSpriteID(this Sprite sprite, GUID guid)
{
SetSpriteIDScripting(sprite, guid.ToString());
}

[FreeFunction("SpriteEditorExtension::GetSpriteIDScripting")]
private static extern string GetSpriteIDScripting(Sprite sprite);
private static extern string GetSpriteIDScripting([NotNull] Sprite sprite);
[FreeFunction("SpriteEditorExtension::SetSpriteIDScripting")]
private static extern void SetSpriteIDScripting([NotNull] Sprite sprite, string spriteID);
}
}
3 changes: 1 addition & 2 deletions Editor/Mono/2D/Common/TexturePlatformSettingsController.cs
Expand Up @@ -134,8 +134,7 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
bool showAsEnum =
buildTarget == BuildTarget.iOS ||
buildTarget == BuildTarget.tvOS ||
buildTarget == BuildTarget.Android ||
buildTarget == BuildTarget.Tizen
buildTarget == BuildTarget.Android
;

if (showAsEnum)
Expand Down
8 changes: 2 additions & 6 deletions Editor/Mono/2D/SpriteAtlas/SpriteAtlasInspector.cs
Expand Up @@ -643,16 +643,12 @@ public override void OnPreviewGUI(Rect r, GUIStyle background)
{
Texture2D t = m_PreviewTextures[m_PreviewPage];

float oldBias = t.mipMapBias;
float bias = m_MipLevel - (float)(System.Math.Log(t.width / r.width) / System.Math.Log(2));
TextureUtil.SetMipMapBiasNoDirty(t, bias);

if (m_ShowAlpha)
EditorGUI.DrawTextureAlpha(r, t, ScaleMode.ScaleToFit);
EditorGUI.DrawTextureAlpha(r, t, ScaleMode.ScaleToFit, 0, bias);
else
EditorGUI.DrawTextureTransparent(r, t, ScaleMode.ScaleToFit);

TextureUtil.SetMipMapBiasNoDirty(t, oldBias);
EditorGUI.DrawTextureTransparent(r, t, ScaleMode.ScaleToFit, 0, bias);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Editor/Mono/2D/SpriteEditorModule/SpriteEditorData.cs
Expand Up @@ -16,6 +16,9 @@ internal class SpriteDataExt : SpriteRect
{
public List<SpriteBone> spriteBone;
public float tessellationDetail = 0;

// The following lists are to be left un-initialized.
// If they never loaded or assign explicitly, we avoid writing empty list to metadata.
public List<Vector2[]> spriteOutline;
public List<Vertex2DMetaData> vertices;
public List<int> indices;
Expand All @@ -36,9 +39,6 @@ internal SpriteDataExt(SpriteRect sr)
spriteID = sr.spriteID;
alignment = sr.alignment;
pivot = sr.pivot;
spriteOutline = new List<Vector2[]>();
spritePhysicsOutline = new List<Vector2[]>();
spriteBone = new List<SpriteBone>();
}

public void Apply(SerializedObject so)
Expand Down
Expand Up @@ -134,10 +134,10 @@ private void AddSprite(Rect frame, int alignment, Vector2 pivot, AutoSlicingMeth
}
}
else
AddSpriteWithUniqueName(frame, alignment, pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, index++);
AddSpriteWithUniqueName(frame, alignment, pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, index++, Vector4.zero);
}
else
AddSprite(frame, alignment, pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, GetSpriteNamePrefix() + "_" + index++);
AddSprite(frame, alignment, pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, GetSpriteNamePrefix() + "_" + index++, Vector4.zero);
}

private SpriteRect GetExistingOverlappingSprite(Rect rect)
Expand Down Expand Up @@ -165,7 +165,7 @@ private bool PixelHasAlpha(int x, int y, UnityTexture2D texture)
return m_AlphaPixelCache[index];
}

private SpriteRect AddSprite(Rect rect, int alignment, Vector2 pivot, int colliderAlphaCutoff, float colliderDetail, string name)
private SpriteRect AddSprite(Rect rect, int alignment, Vector2 pivot, int colliderAlphaCutoff, float colliderDetail, string name, Vector4 border)
{
SpriteRect spriteRect = new SpriteRect();

Expand All @@ -175,7 +175,7 @@ private SpriteRect AddSprite(Rect rect, int alignment, Vector2 pivot, int collid

spriteRect.name = name;
spriteRect.originalName = spriteRect.name;
spriteRect.border = Vector4.zero;
spriteRect.border = border;
spriteEditor.SetDataModified();

m_RectsCache.spriteRects.Add(spriteRect);
Expand All @@ -184,10 +184,10 @@ private SpriteRect AddSprite(Rect rect, int alignment, Vector2 pivot, int collid
return spriteRect;
}

public SpriteRect AddSpriteWithUniqueName(Rect rect, int alignment, Vector2 pivot, int colliderAlphaCutoff, float colliderDetail, int nameIndexingHint)
public SpriteRect AddSpriteWithUniqueName(Rect rect, int alignment, Vector2 pivot, int colliderAlphaCutoff, float colliderDetail, int nameIndexingHint, Vector4 border)
{
string name = GetUniqueName(GetSpriteNamePrefix(), nameIndexingHint);
return AddSprite(rect, alignment, pivot, colliderAlphaCutoff, colliderDetail, name);
return AddSprite(rect, alignment, pivot, colliderAlphaCutoff, colliderDetail, name, border);
}

private string GetSpriteNamePrefix()
Expand Down Expand Up @@ -225,7 +225,7 @@ public void DoGridSlicing(Vector2 size, Vector2 offset, Vector2 padding, int ali
m_RectsCache.spriteRects.Clear();

foreach (Rect frame in frames)
AddSprite(frame, alignment, pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, GetSpriteNamePrefix() + "_" + index++);
AddSprite(frame, alignment, pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, GetSpriteNamePrefix() + "_" + index++, Vector4.zero);

selected = null;
spriteEditor.SetDataModified();
Expand Down Expand Up @@ -296,15 +296,15 @@ public void DuplicateSprite()
if (selected != null)
{
undoSystem.RegisterCompleteObjectUndo(m_RectsCache, "Duplicate sprite");
selected = AddSpriteWithUniqueName(selected.rect, (int)selected.alignment, selected.pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, 0);
selected = AddSpriteWithUniqueName(selected.rect, (int)selected.alignment, selected.pivot, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, 0, selected.border);
}
}

public void CreateSprite(Rect rect)
{
rect = ClampSpriteRect(rect, textureActualWidth, textureActualHeight);
undoSystem.RegisterCompleteObjectUndo(m_RectsCache, "Create sprite");
selected = AddSpriteWithUniqueName(rect, 0, Vector2.zero, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, 0);
selected = AddSpriteWithUniqueName(rect, 0, Vector2.zero, kDefaultColliderAlphaCutoff, kDefaultColliderDetail, 0, Vector4.zero);
}

public void DeleteSprite()
Expand Down
Expand Up @@ -50,6 +50,7 @@ public override void OnModuleActivate()
textureActualHeight = height;
m_RectsCache = ScriptableObject.CreateInstance<SpriteRectModel>();
m_RectsCache.spriteRects = m_SpriteDataProvider.GetSpriteRects().ToList();
spriteEditor.spriteRects = m_RectsCache.spriteRects;
if (spriteEditor.selectedSpriteRect != null)
spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID);
}
Expand Down
42 changes: 20 additions & 22 deletions Editor/Mono/2D/SpriteEditorModule/SpriteOutlineModule.cs
Expand Up @@ -182,7 +182,7 @@ internal class SpriteOutlineModule : SpriteEditorModuleBase
{
class Styles
{
public GUIContent generateOutlineLabel = EditorGUIUtility.TrTextContent("Update", "Update new outline based on mesh detail value.");
public GUIContent generateOutlineLabel = EditorGUIUtility.TrTextContent("Generate", "Generate new outline based on mesh detail value.");
public GUIContent outlineTolerance = EditorGUIUtility.TrTextContent("Outline Tolerance", "Sets how tight the outline should be from the sprite.");
public GUIContent snapButtonLabel = EditorGUIUtility.TrTextContent("Snap", "Snap points to nearest pixel");
public GUIContent generatingOutlineDialogTitle = EditorGUIUtility.TrTextContent("Outline");
Expand Down Expand Up @@ -227,7 +227,7 @@ public SpriteOutlineModule(ISpriteEditor sem, IEventSystem es, IUndoSystem us, I

public override string moduleName
{
get { return "Edit Outline"; }
get { return "Custom Outline"; }
}

public override bool ApplyRevert(bool apply)
Expand Down Expand Up @@ -614,7 +614,8 @@ public void SetupShapeEditor()

if (m_Selected != null)
{
SetupShapeEditorOutline(m_Selected);
if (!HasShapeOutline(m_Selected))
SetupShapeEditorOutline(m_Selected);
m_ShapeEditors = new ShapeEditor[selectedShapeOutline.Count];

for (int i = 0; i < selectedShapeOutline.Count; ++i)
Expand Down Expand Up @@ -655,36 +656,33 @@ public void SetupShapeEditor()
protected virtual bool HasShapeOutline(SpriteRect spriteRect)
{
var outline = m_Outline[spriteRect.spriteID]?.spriteOutlines;
return outline != null && outline.Count > 0;
return outline != null;
}

protected virtual void SetupShapeEditorOutline(SpriteRect spriteRect)
{
var outline = m_Outline[spriteRect.spriteID];
if (outline.spriteOutlines == null || outline.spriteOutlines.Count == 0)
var outlines = GenerateSpriteRectOutline(spriteRect.rect,
Math.Abs(outline.tessellationDetail - (-1f)) < Mathf.Epsilon ? 0 : outline.tessellationDetail,
0, m_TextureDataProvider);
if (outlines.Count == 0)
{
var outlines = GenerateSpriteRectOutline(spriteRect.rect,
Math.Abs(outline.tessellationDetail - (-1f)) < Mathf.Epsilon ? 0 : outline.tessellationDetail,
0, m_TextureDataProvider);
if (outlines.Count == 0)
Vector2 halfSize = spriteRect.rect.size * 0.5f;
outlines = new List<SpriteOutline>()
{
Vector2 halfSize = spriteRect.rect.size * 0.5f;
outlines = new List<SpriteOutline>()
new SpriteOutline()
{
new SpriteOutline()
m_Path = new List<Vector2>()
{
m_Path = new List<Vector2>()
{
new Vector2(-halfSize.x, -halfSize.y),
new Vector2(-halfSize.x, halfSize.y),
new Vector2(halfSize.x, halfSize.y),
new Vector2(halfSize.x, -halfSize.y),
}
new Vector2(-halfSize.x, -halfSize.y),
new Vector2(-halfSize.x, halfSize.y),
new Vector2(halfSize.x, halfSize.y),
new Vector2(halfSize.x, -halfSize.y),
}
};
}
m_Outline[spriteRect.spriteID].spriteOutlines = outlines;
}
};
}
m_Outline[spriteRect.spriteID].spriteOutlines = outlines;
}

public Vector3 SnapPoint(Vector3 position)
Expand Down
15 changes: 6 additions & 9 deletions Editor/Mono/2D/SpriteEditorModule/SpritePhysicsShapeModule.cs
Expand Up @@ -26,7 +26,7 @@ public SpritePhysicsShapeModule(ISpriteEditor sem, IEventSystem ege, IUndoSystem

public override string moduleName
{
get { return "Edit Physics Shape"; }
get { return "Custom Physics Shape"; }
}

private ISpriteEditor spriteEditorWindow
Expand Down Expand Up @@ -71,14 +71,11 @@ protected override void LoadOutline()
protected override void SetupShapeEditorOutline(SpriteRect spriteRect)
{
var physicsShape = m_Outline[spriteRect.spriteID];
if (physicsShape.spriteOutlines == null || physicsShape.spriteOutlines.Count == 0)
{
var physicsShapes = GenerateSpriteRectOutline(spriteRect.rect,
Math.Abs(physicsShape.tessellationDetail - (-1f)) < Mathf.Epsilon ? kDefaultPhysicsTessellationDetail : physicsShape.tessellationDetail,
kDefaultPhysicsAlphaTolerance, m_TextureDataProvider);
spriteEditorWindow.SetDataModified();
m_Outline[spriteRect.spriteID].spriteOutlines = physicsShapes;
}
var physicsShapes = GenerateSpriteRectOutline(spriteRect.rect,
Math.Abs(physicsShape.tessellationDetail - (-1f)) < Mathf.Epsilon ? kDefaultPhysicsTessellationDetail : physicsShape.tessellationDetail,
kDefaultPhysicsAlphaTolerance, m_TextureDataProvider);
m_Outline[spriteRect.spriteID].spriteOutlines = physicsShapes;
spriteEditorWindow.SetDataModified();
}
}
}
2 changes: 1 addition & 1 deletion Editor/Mono/2D/SpriteEditorModule/TextureImporter.cs
Expand Up @@ -32,7 +32,7 @@ SpriteRect[] ISpriteEditorDataProvider.GetSpriteRects()

void ISpriteEditorDataProvider.SetSpriteRects(SpriteRect[] spriteRects)
{
if (spriteImportMode == SpriteImportMode.Single && spriteRects.Length == 1)
if (spriteImportMode != SpriteImportMode.Multiple && spriteImportMode != SpriteImportMode.None && spriteRects.Length == 1)
{
m_SpriteSingle.CopyFromSpriteRect(spriteRects[0]);
}
Expand Down
10 changes: 10 additions & 0 deletions Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs
Expand Up @@ -928,6 +928,16 @@ public void TransformSelectedKeys(Matrix4x4 matrix, bool flipX, bool flipY, bool
{
liveEditKey.key.inTangent = (liveEditKey.keySnapshot.outTangent != Mathf.Infinity) ? -liveEditKey.keySnapshot.outTangent : Mathf.Infinity;
liveEditKey.key.outTangent = (liveEditKey.keySnapshot.inTangent != Mathf.Infinity) ? -liveEditKey.keySnapshot.inTangent : Mathf.Infinity;

if (liveEditKey.keySnapshot.weightedMode == WeightedMode.In)
liveEditKey.key.weightedMode = WeightedMode.Out;
else if (liveEditKey.keySnapshot.weightedMode == WeightedMode.Out)
liveEditKey.key.weightedMode = WeightedMode.In;
else
liveEditKey.key.weightedMode = liveEditKey.keySnapshot.weightedMode;

liveEditKey.key.inWeight = liveEditKey.keySnapshot.outWeight;
liveEditKey.key.outWeight = liveEditKey.keySnapshot.inWeight;
}

if (!liveEditKey.key.isPPtrCurve)
Expand Down
28 changes: 21 additions & 7 deletions Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs
Expand Up @@ -186,24 +186,38 @@ public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve cu
else if (type == typeof(bool) || type == typeof(float) || type == typeof(int))
{
Keyframe tempKey = new Keyframe(time.time, (float)value);
if (type == typeof(bool) || type == typeof(int))
if (type == typeof(bool))
{
if (type == typeof(int) && !curve.isDiscreteCurve)
AnimationUtility.SetKeyLeftTangentMode(ref tempKey, TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(ref tempKey, TangentMode.Constant);

AnimationUtility.SetKeyBroken(ref tempKey, true);
}
else if (type == typeof(int))
{
// Create temporary curve to get proper tangents
AnimationCurve animationCurve = curve.ToAnimationCurve();
if (animationCurve.length <= 1)
{
AnimationUtility.SetKeyLeftTangentMode(ref tempKey, TangentMode.Linear);
AnimationUtility.SetKeyRightTangentMode(ref tempKey, TangentMode.Linear);
TangentMode tangentMode = curve.isDiscreteCurve ? TangentMode.Constant : TangentMode.Linear;
AnimationUtility.SetKeyLeftTangentMode(ref tempKey, tangentMode);
AnimationUtility.SetKeyRightTangentMode(ref tempKey, tangentMode);
}
else
{
AnimationUtility.SetKeyLeftTangentMode(ref tempKey, TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(ref tempKey, TangentMode.Constant);
int keyIndex = animationCurve.AddKey(tempKey);
if (keyIndex != -1)
{
CurveUtility.SetKeyModeFromContext(animationCurve, keyIndex);
tempKey = animationCurve[keyIndex];
}
}

AnimationUtility.SetKeyBroken(ref tempKey, true);
}
else
{
// Create temporary curve for getting proper tangents
// Create temporary curve to get proper tangents
AnimationCurve animationCurve = curve.ToAnimationCurve();

int keyIndex = animationCurve.AddKey(tempKey);
Expand Down

0 comments on commit 02f8e8c

Please sign in to comment.