Skip to content

Commit 0546568

Browse files
author
Unity Technologies
committed
Unity 2019.1.0a3 C# reference source code
1 parent 6ee67ea commit 0546568

File tree

174 files changed

+5800
-4404
lines changed

Some content is hidden

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

174 files changed

+5800
-4404
lines changed

Editor/Mono/2D/SpriteAtlas/SpriteAtlasInspector.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class Styles
6161
public readonly GUIContent variantMultiplierLabel = EditorGUIUtility.TrTextContent("Scale", "Down scale ratio.");
6262
public readonly GUIContent copyMasterButton = EditorGUIUtility.TrTextContent("Copy Master's Settings", "Copy all master's settings into this variant.");
6363
public readonly GUIContent packButton = EditorGUIUtility.TrTextContent("Pack Preview", "Pack this atlas.");
64-
public readonly GUIContent disabledPackLabel = EditorGUIUtility.TrTextContent("Sprite Atlas packing is disabled. Enable it in Edit > Project Settings > Editor.");
64+
65+
public readonly GUIContent disabledPackLabel = EditorGUIUtility.TrTextContent("Sprite Atlas packing is disabled. Enable it in Edit > Settings > Editor.", null, EditorGUIUtility.GetHelpIcon(MessageType.Info));
6566
public readonly GUIContent packableListLabel = EditorGUIUtility.TrTextContent("Objects for Packing", "Only accept Folder, Sprite Sheet(Texture) and Sprite.");
6667

6768
public readonly GUIContent notPowerOfTwoWarning = EditorGUIUtility.TrTextContent("This scale will produce a Sprite Atlas variant with a packed texture that is NPOT (non - power of two). This may cause visual artifacts in certain compression/texture formats.");
@@ -310,7 +311,10 @@ public override void OnInspectorGUI()
310311
}
311312
else
312313
{
313-
EditorGUILayout.HelpBox(s_Styles.disabledPackLabel.text, MessageType.Info);
314+
if (GUILayout.Button(s_Styles.disabledPackLabel, EditorStyles.helpBox))
315+
{
316+
SettingsWindow.OpenProjectSettings("Project/Editor");
317+
}
314318
}
315319

316320
serializedObject.ApplyModifiedProperties();

Editor/Mono/Animation/TickHandler.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ internal class TickHandler
2424

2525
public int tickLevels { get { return m_BiggestTick - m_SmallestTick + 1; } }
2626

27+
private List<float> m_TickList = new List<float>(1000);
28+
2729
public void SetTickModulos(float[] tickModulos)
2830
{
2931
m_TickModulos = tickModulos;
@@ -140,8 +142,17 @@ public float[] GetTicksAtLevel(int level, bool excludeTicksFromHigherlevels)
140142
if (level < 0)
141143
return new float[0] {};
142144

145+
m_TickList.Clear();
146+
GetTicksAtLevel(level, excludeTicksFromHigherlevels, m_TickList);
147+
return m_TickList.ToArray();
148+
}
149+
150+
public void GetTicksAtLevel(int level, bool excludeTicksFromHigherlevels, List<float> list)
151+
{
152+
if (list == null)
153+
throw new System.ArgumentNullException("list");
154+
143155
int l = Mathf.Clamp(m_SmallestTick + level, 0, m_TickModulos.Length - 1);
144-
List<float> ticks = new List<float>();
145156
int startTick = Mathf.FloorToInt(m_MinValue / m_TickModulos[l]);
146157
int endTick = Mathf.CeilToInt(m_MaxValue / m_TickModulos[l]);
147158
for (int i = startTick; i <= endTick; i++)
@@ -151,9 +162,8 @@ public float[] GetTicksAtLevel(int level, bool excludeTicksFromHigherlevels)
151162
&& l < m_BiggestTick
152163
&& (i % Mathf.RoundToInt(m_TickModulos[l + 1] / m_TickModulos[l]) == 0))
153164
continue;
154-
ticks.Add(i * m_TickModulos[l]);
165+
list.Add(i * m_TickModulos[l]);
155166
}
156-
return ticks.ToArray();
157167
}
158168

159169
public float GetStrengthOfLevel(int level)

Editor/Mono/Animation/TimeArea.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using UnityEngine;
6+
using System.Collections.Generic;
67

78
namespace UnityEditor
89
{
@@ -19,6 +20,8 @@ public TickHandler hTicks
1920

2021
[SerializeField] private TickHandler m_VTicks;
2122

23+
private List<float> m_TickCache = new List<float>(1000);
24+
2225
public TickHandler vTicks
2326
{
2427
get { return m_VTicks; }
@@ -111,11 +114,12 @@ public void DrawMajorTicks(Rect position, float frameRate)
111114
float strength = hTicks.GetStrengthOfLevel(l) * .9f;
112115
if (strength > kTickRulerFatThreshold)
113116
{
114-
float[] ticks = hTicks.GetTicksAtLevel(l, true);
115-
for (int i = 0; i < ticks.Length; i++)
117+
m_TickCache.Clear();
118+
hTicks.GetTicksAtLevel(l, true, m_TickCache);
119+
for (int i = 0; i < m_TickCache.Count; i++)
116120
{
117-
if (ticks[i] < 0) continue;
118-
int frame = Mathf.RoundToInt(ticks[i] * frameRate);
121+
if (m_TickCache[i] < 0) continue;
122+
int frame = Mathf.RoundToInt(m_TickCache[i] * frameRate);
119123
float x = FrameToPixel(frame, frameRate, position, theShowArea);
120124
// Draw line
121125
DrawVerticalLineFast(x, 0.0f, position.height, tickColor);
@@ -167,12 +171,13 @@ public void TimeRuler(Rect position, float frameRate, bool labels, bool useEntir
167171
for (int l = 0; l < hTicks.tickLevels; l++)
168172
{
169173
float strength = hTicks.GetStrengthOfLevel(l) * .9f;
170-
float[] ticks = hTicks.GetTicksAtLevel(l, true);
171-
for (int i = 0; i < ticks.Length; i++)
174+
m_TickCache.Clear();
175+
hTicks.GetTicksAtLevel(l, true, m_TickCache);
176+
for (int i = 0; i < m_TickCache.Count; i++)
172177
{
173-
if (ticks[i] < hRangeMin || ticks[i] > hRangeMax)
178+
if (m_TickCache[i] < hRangeMin || m_TickCache[i] > hRangeMax)
174179
continue;
175-
int frame = Mathf.RoundToInt(ticks[i] * frameRate);
180+
int frame = Mathf.RoundToInt(m_TickCache[i] * frameRate);
176181

177182
float height = useEntireHeight
178183
? position.height
@@ -192,18 +197,19 @@ public void TimeRuler(Rect position, float frameRate, bool labels, bool useEntir
192197
{
193198
// Draw tick labels
194199
int labelLevel = hTicks.GetLevelWithMinSeparation(kTickRulerDistLabel);
195-
float[] labelTicks = hTicks.GetTicksAtLevel(labelLevel, false);
196-
for (int i = 0; i < labelTicks.Length; i++)
200+
m_TickCache.Clear();
201+
hTicks.GetTicksAtLevel(labelLevel, false, m_TickCache);
202+
for (int i = 0; i < m_TickCache.Count; i++)
197203
{
198-
if (labelTicks[i] < hRangeMin || labelTicks[i] > hRangeMax)
204+
if (m_TickCache[i] < hRangeMin || m_TickCache[i] > hRangeMax)
199205
continue;
200206

201-
int frame = Mathf.RoundToInt(labelTicks[i] * frameRate);
207+
int frame = Mathf.RoundToInt(m_TickCache[i] * frameRate);
202208
// Important to take floor of positions of GUI stuff to get pixel correct alignment of
203209
// stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time.
204210

205211
float labelpos = Mathf.Floor(FrameToPixel(frame, frameRate, position));
206-
string label = FormatTickTime(labelTicks[i], frameRate, timeFormat);
212+
string label = FormatTickTime(m_TickCache[i], frameRate, timeFormat);
207213
GUI.Label(new Rect(labelpos + 3, -3, 40, 20), label, timeAreaStyles.timelineTick);
208214
}
209215
}

Editor/Mono/Animation/ZoomableArea.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,5 +992,20 @@ public float PixelDeltaToTime(Rect rect)
992992
{
993993
return shownArea.width / rect.width;
994994
}
995+
996+
public void UpdateZoomScale(float fMaxScaleValue, float fMinScaleValue)
997+
{
998+
// Update/reset the values of the scale to new zoom range, if the current values do not fall in the range of the new resolution
999+
1000+
if (m_Scale.y > fMaxScaleValue || m_Scale.y < fMinScaleValue)
1001+
{
1002+
m_Scale.y = m_Scale.y > fMaxScaleValue ? fMaxScaleValue : fMinScaleValue;
1003+
}
1004+
1005+
if (m_Scale.x > fMaxScaleValue || m_Scale.x < fMinScaleValue)
1006+
{
1007+
m_Scale.x = m_Scale.x > fMaxScaleValue ? fMaxScaleValue : fMinScaleValue;
1008+
}
1009+
}
9951010
}
9961011
} // namespace

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@
9393
[assembly: InternalsVisibleTo("Unity.InternalAPIEditorBridgeDev.004")]
9494
[assembly: InternalsVisibleTo("Unity.InternalAPIEditorBridgeDev.005")]
9595
[assembly: InternalsVisibleTo("Unity.XR.Remoting.Editor")]
96+
[assembly: InternalsVisibleTo("UnityEngine.Common")]
9697

9798
[assembly: AssemblyIsEditorAssembly]

Editor/Mono/AssetPipeline/AssetImporter.bindings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
using UnityEngine;
88
using Object = UnityEngine.Object;
99
using UnityEngine.Bindings;
10+
using UnityEngine.Scripting;
1011

1112
namespace UnityEditor
1213
{
1314
[NativeHeader("Editor/Src/AssetPipeline/AssetImporter.h")]
1415
[NativeHeader("Editor/Src/AssetPipeline/AssetImporter.bindings.h")]
1516
[ExcludeFromObjectFactory]
17+
[Preserve]
18+
[UsedByNativeCode]
1619
public partial class AssetImporter : Object
1720
{
1821
[NativeType(CodegenOptions.Custom, "MonoSourceAssetIdentifier")]

Editor/Mono/AssetStore/AssetStoreWindow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public static void OpenURL(string url)
3030
}
3131

3232
// Use this for initialization
33-
[MenuItem("Window/General/Asset Store %9", false, 301)]
33+
// Index at 1499 because "Package Manager" is 1500, pairing tools for user to get external content
34+
[MenuItem("Window/Asset Store %9", false, 1499)]
3435
public static AssetStoreWindow Init()
3536
{
3637
AssetStoreWindow window = EditorWindow.GetWindow<AssetStoreWindow>(typeof(SceneView));

Editor/Mono/BuildPipeline.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using UnityEngine.Bindings;
1010
using UnityEditor.Build.Reporting;
1111
using Mono.Cecil;
12+
using UnityEditor.Scripting.ScriptCompilation;
1213

1314
namespace UnityEditor
1415
{
@@ -179,6 +180,7 @@ public class BuildPipeline
179180
internal static extern BuildTargetGroup GetBuildTargetGroupByName(string platform);
180181

181182
internal static extern BuildTarget GetBuildTargetByName(string platform);
183+
internal static extern EditorScriptCompilationOptions GetScriptCompileFlags(BuildOptions buildOptions, BuildTarget buildTarget);
182184

183185
[FreeFunction]
184186
internal static extern string GetBuildTargetGroupDisplayName(BuildTargetGroup targetPlatformGroup);

Editor/Mono/BuildPipeline/AssemblyStripper.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ private static void RunAssemblyStripper(IEnumerable assemblies, string managedAs
270270
blacklists = blacklists.Concat(new[]
271271
{
272272
WriteMethodsToPreserveBlackList(rcr, platformProvider.target),
273-
WriteUnityEngineBlackList(),
274-
MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(managedAssemblyFolderPath, rcr)
273+
MonoAssemblyStripping.GenerateLinkXmlToPreserveDerivedTypes(managedAssemblyFolderPath, rcr),
274+
WriteTypesInScenesBlacklist(managedAssemblyFolderPath, rcr)
275275
});
276276
}
277277

@@ -367,6 +367,28 @@ private static void RunAssemblyStripper(IEnumerable assemblies, string managedAs
367367
Directory.Delete(tempStripPath);
368368
}
369369

370+
private static string WriteTypesInScenesBlacklist(string managedAssemblyDirectory, RuntimeClassRegistry rcr)
371+
{
372+
var items = rcr.GetAllManagedTypesInScenes();
373+
374+
var sb = new StringBuilder();
375+
sb.AppendLine("<linker>");
376+
foreach (var assemblyTypePair in items)
377+
{
378+
sb.AppendLine($"\t<assembly fullname=\"{Path.GetFileNameWithoutExtension(assemblyTypePair.Key)}\">");
379+
foreach (var type in assemblyTypePair.Value)
380+
{
381+
sb.AppendLine($"\t\t<type fullname=\"{type}\"/>");
382+
}
383+
sb.AppendLine("\t</assembly>");
384+
}
385+
sb.AppendLine("</linker>");
386+
387+
var path = Path.Combine(managedAssemblyDirectory, "TypesInScenes.xml");
388+
File.WriteAllText(path, sb.ToString());
389+
return path;
390+
}
391+
370392
private static string WriteMethodsToPreserveBlackList(RuntimeClassRegistry rcr, BuildTarget target)
371393
{
372394
var contents = GetMethodPreserveBlacklistContents(rcr, target);
@@ -377,15 +399,6 @@ private static string WriteMethodsToPreserveBlackList(RuntimeClassRegistry rcr,
377399
return methodPerserveBlackList;
378400
}
379401

380-
private static string WriteUnityEngineBlackList()
381-
{
382-
// UnityEngine.dll would be stripped, as it contains no referenced symbols, only type forwarders.
383-
// Since we need those type forwarders, we generate blacklist to preserve the assembly (but no members).
384-
var unityEngineBlackList = Path.GetTempFileName();
385-
File.WriteAllText(unityEngineBlackList, "<linker><assembly fullname=\"UnityEngine\" preserve=\"nothing\"/></linker>");
386-
return unityEngineBlackList;
387-
}
388-
389402
private static string GetMethodPreserveBlacklistContents(RuntimeClassRegistry rcr, BuildTarget target)
390403
{
391404
if (rcr.GetMethodsToPreserve().Count == 0)

Editor/Mono/BuildPipeline/RuntimeClassMetadata.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using UnityEditorInternal;
88
using System;
9+
using System.Linq;
910
using UnityEditor.Compilation;
1011
using UnityEditor.Scripting.ScriptCompilation;
1112

@@ -75,7 +76,7 @@ protected void AddManagedBaseClass(string className)
7576
monoBaseClasses.Add(className);
7677
}
7778

78-
protected void AddNativeClassFromName(string className)
79+
public void AddNativeClassFromName(string className)
7980
{
8081
if (objectUnityType == null)
8182
objectUnityType = UnityType.FindTypeByName("Object");
@@ -87,6 +88,32 @@ protected void AddNativeClassFromName(string className)
8788
allNativeClasses[t.persistentTypeID] = className;
8889
}
8990

91+
public Dictionary<string, string[]> GetAllManagedTypesInScenes()
92+
{
93+
var items = new Dictionary<string, string[]>();
94+
95+
// Use a hashset to remove duplicate types.
96+
// Duplicates of UnityEngine.Object will happen because native types without a managed type will come back as
97+
// UnityEngine.Object
98+
var engineModuleTypes = new HashSet<string>();
99+
foreach (var nativeClassID in allNativeClasses.Keys)
100+
{
101+
var managedName = RuntimeClassMetadataUtils.ScriptingWrapperTypeNameForNativeID(nativeClassID);
102+
103+
if (string.IsNullOrEmpty(managedName))
104+
continue;
105+
106+
engineModuleTypes.Add(managedName);
107+
}
108+
109+
items.Add("UnityEngine.dll", engineModuleTypes.ToArray());
110+
111+
foreach (var userAssembly in m_UsedTypesPerUserAssembly)
112+
items.Add(userAssembly.Key, userAssembly.Value);
113+
114+
return items;
115+
}
116+
90117
public List<string> GetAllNativeClassesIncludingManagersAsString()
91118
{
92119
return new List<string>(allNativeClasses.Values);

0 commit comments

Comments
 (0)