Skip to content

Commit a330bae

Browse files
author
Unity Technologies
committed
Unity 2017.4.11f1 C# reference source code
1 parent c37adb1 commit a330bae

File tree

14 files changed

+88
-40
lines changed

14 files changed

+88
-40
lines changed

Editor/Mono/2D/Common/TexturePlatformSettingsController.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,25 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
8787
int allSize = platformSettings[0].maxTextureSize;
8888
TextureImporterFormat allFormat = platformSettings[0].format;
8989
int allCompressionQuality = platformSettings[0].compressionQuality;
90+
var allAlphaSplit = platformSettings[0].allowsAlphaSplitting;
9091

9192
var newOverride = allOverride;
9293
var newSize = allSize;
9394
var newFormat = allFormat;
9495
var newCompressionQuality = allCompressionQuality;
96+
var newAlphaSplit = allAlphaSplit;
9597

9698
bool mixedOverride = false;
9799
bool mixedSize = false;
98100
bool mixedFormat = false;
99101
bool mixedCompression = false;
102+
var mixedAlphaSplit = false;
100103

101104
bool overrideChanged = false;
102105
bool sizeChanged = false;
103106
bool formatChanged = false;
104107
bool compressionChanged = false;
108+
var alphaSplitChanged = false;
105109

106110
for (var i = 1; i < platformSettings.Count; ++i)
107111
{
@@ -114,6 +118,8 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
114118
mixedFormat = true;
115119
if (settings.compressionQuality != allCompressionQuality)
116120
mixedCompression = true;
121+
if (settings.allowsAlphaSplitting != allAlphaSplit)
122+
mixedAlphaSplit = true;
117123
}
118124

119125
newOverride = view.DrawOverride(allOverride, mixedOverride, out overrideChanged);
@@ -166,9 +172,17 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
166172
{
167173
newCompressionQuality = view.DrawCompressionQualitySlider(allCompressionQuality, mixedCompression, out compressionChanged);
168174
}
175+
176+
// show the ETC1 split option only for sprites on platforms supporting ETC.
177+
bool isETCPlatform = formatHelper.IsETC1SupportedByBuildTarget(buildTarget);
178+
bool isETCFormatSelected = formatHelper.IsTextureFormatETC1Compression((TextureFormat)allFormat);
179+
if (isETCPlatform && isETCFormatSelected)
180+
{
181+
newAlphaSplit = view.DrawAlphaSplit(allAlphaSplit, mixedAlphaSplit, mixedOverride || !allOverride, out alphaSplitChanged);
182+
}
169183
}
170184

171-
if (overrideChanged || sizeChanged || formatChanged || compressionChanged)
185+
if (overrideChanged || sizeChanged || formatChanged || compressionChanged || alphaSplitChanged)
172186
{
173187
for (var i = 0; i < platformSettings.Count; ++i)
174188
{
@@ -180,6 +194,8 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
180194
platformSettings[i].format = newFormat;
181195
if (compressionChanged)
182196
platformSettings[i].compressionQuality = newCompressionQuality;
197+
if (alphaSplitChanged)
198+
platformSettings[i].allowsAlphaSplitting = newAlphaSplit;
183199
}
184200

185201
return true;

Editor/Mono/2D/Common/TexturePlatformSettingsFormatHelper.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,15 @@ public bool TextureFormatRequireCompressionQualityInput(TextureImporterFormat fo
5858
{
5959
return TextureImporterInspector.IsFormatRequireCompressionSetting(format);
6060
}
61+
62+
public bool IsETC1SupportedByBuildTarget(BuildTarget buildTarget)
63+
{
64+
return TextureImporter.IsETC1SupportedByBuildTarget(buildTarget);
65+
}
66+
67+
public bool IsTextureFormatETC1Compression(TextureFormat format)
68+
{
69+
return TextureImporter.IsTextureFormatETC1Compression(format);
70+
}
6171
}
6272
}

Editor/Mono/2D/Common/TexturePlatformSettingsView.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Styles
1515
public readonly GUIContent maxTextureSizeLabel = EditorGUIUtility.TextContent("Max Texture Size|Maximum size of the packed texture.");
1616
public readonly GUIContent compressionLabel = EditorGUIUtility.TextContent("Compression|How will this texture be compressed?");
1717
public readonly GUIContent useCrunchedCompressionLabel = EditorGUIUtility.TextContent("Use Crunch Compression|Texture is crunch-compressed to save space on disk when applicable.");
18+
public readonly GUIContent useAlphaSplitLabel = EditorGUIUtility.TrTextContent("Split Alpha Channel", "Alpha for this texture will be preserved by splitting the alpha channel to another texture, and both resulting textures will be compressed using ETC1.");
1819
public readonly GUIContent compressionQualityLabel = EditorGUIUtility.TextContent("Compressor Quality");
1920
public readonly GUIContent compressionQualitySliderLabel = EditorGUIUtility.TextContent("Compressor Quality|Use the slider to adjust compression quality from 0 (Fastest) to 100 (Best)");
2021

@@ -133,5 +134,18 @@ public virtual int DrawCompressionQualitySlider(int defaultValue, bool isMixedVa
133134
changed = EditorGUI.EndChangeCheck();
134135
return defaultValue;
135136
}
137+
138+
public virtual bool DrawAlphaSplit(bool defaultValue, bool isMixedValue, bool isDisabled, out bool changed)
139+
{
140+
using (new EditorGUI.DisabledScope(isDisabled))
141+
{
142+
EditorGUI.BeginChangeCheck();
143+
EditorGUI.showMixedValue = isMixedValue;
144+
defaultValue = EditorGUILayout.Toggle(s_Styles.useAlphaSplitLabel, defaultValue);
145+
EditorGUI.showMixedValue = false;
146+
changed = EditorGUI.EndChangeCheck();
147+
return defaultValue;
148+
}
149+
}
136150
}
137151
}

Editor/Mono/2D/Interface/ITexturePlatformSetting.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal interface ITexturePlatformSettingsView
1212
string buildPlatformTitle { get; set; }
1313
TextureImporterCompression DrawCompression(TextureImporterCompression defaultValue, bool isMixedValue, out bool changed);
1414
bool DrawUseCrunchedCompression(bool defaultValue, bool isMixedValue, out bool changed);
15+
bool DrawAlphaSplit(bool defaultValue, bool isMixedValue, bool isDisabled, out bool changed);
1516
bool DrawOverride(bool defaultValue, bool isMixedValue, out bool changed);
1617
int DrawMaxSize(int defaultValue, bool isMixedValue, out bool changed);
1718
TextureImporterFormat DrawFormat(TextureImporterFormat defaultValue, int[] displayValues, string[] displayStrings, bool isMixedValue, bool isDisabled, out bool changed);
@@ -24,6 +25,10 @@ internal interface ITexturePlatformSettingsFormatHelper
2425
void AcquireTextureFormatValuesAndStrings(BuildTarget buildTarget, out int[] displayValues, out string[] displayStrings);
2526

2627
bool TextureFormatRequireCompressionQualityInput(TextureImporterFormat format);
28+
29+
bool IsETC1SupportedByBuildTarget(BuildTarget buildTarget);
30+
31+
bool IsTextureFormatETC1Compression(TextureFormat format);
2732
}
2833

2934
internal interface ITexturePlatformSettingsController

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private enum AtlasType { Undefined = -1, Master = 0, Variant = 1 }
125125
private int[] m_OptionValues = null;
126126
private string[] m_OptionDisplays = null;
127127
private Texture2D[] m_PreviewTextures = null;
128+
private Texture2D[] m_PreviewAlphaTextures = null;
128129

129130
private bool m_PackableListExpanded = true;
130131
private ReorderableList m_PackableList;
@@ -575,6 +576,7 @@ void CachePreviewTexture()
575576
if (m_PreviewTextures == null || m_Hash != spriteAtlas.GetHashString())
576577
{
577578
m_PreviewTextures = spriteAtlas.GetPreviewTextures();
579+
m_PreviewAlphaTextures = spriteAtlas.GetPreviewAlphaTextures();
578580
m_Hash = spriteAtlas.GetHashString();
579581

580582
if (m_PreviewTextures != null
@@ -623,7 +625,7 @@ public override void OnPreviewSettings()
623625
{
624626
Texture2D t = m_PreviewTextures[m_PreviewPage];
625627

626-
if (TextureUtil.HasAlphaTextureFormat(t.format))
628+
if (TextureUtil.HasAlphaTextureFormat(t.format) || (m_PreviewAlphaTextures != null && m_PreviewAlphaTextures.Length > 0))
627629
m_ShowAlpha = GUILayout.Toggle(m_ShowAlpha, m_ShowAlpha ? s_Styles.alphaIcon : s_Styles.RGBIcon, s_Styles.previewButton);
628630

629631
int mipCount = Mathf.Max(1, TextureUtil.GetMipmapCount(t));
@@ -639,7 +641,13 @@ public override void OnPreviewSettings()
639641
public override void OnPreviewGUI(Rect r, GUIStyle background)
640642
{
641643
CachePreviewTexture();
642-
if (m_PreviewTextures != null && m_PreviewPage < m_PreviewTextures.Length)
644+
645+
if (m_ShowAlpha && m_PreviewAlphaTextures != null && m_PreviewPage < m_PreviewAlphaTextures.Length)
646+
{
647+
var at = m_PreviewAlphaTextures[m_PreviewPage];
648+
EditorGUI.DrawTextureTransparent(r, at, ScaleMode.ScaleToFit);
649+
}
650+
else if (m_PreviewTextures != null && m_PreviewPage < m_PreviewTextures.Length)
643651
{
644652
Texture2D t = m_PreviewTextures[m_PreviewPage];
645653

Editor/Mono/AssetPipeline/ModelImporter.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ internal extern bool isAssetOlderOr42
816816
}
817817

818818
[FreeFunction("ModelImporterBindings::UpdateTransformMask")]
819-
extern internal static void UpdateTransformMask(AvatarMask mask, SerializedProperty serializedProperty);
819+
extern internal static void UpdateTransformMask([NotNull] AvatarMask mask, [NotNull] SerializedProperty serializedProperty);
820820

821821
extern internal AnimationClip GetPreviewAnimationClipForTake(string takeName);
822822

Editor/Mono/ImportSettings/PrefabUtility.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,20 @@ private static void GetObjectListFromHierarchy(List<Object> hierarchy, GameObjec
8989
{
9090
Transform transform = null;
9191
List<Component> components = new List<Component>();
92-
hierarchy.Add(gameObject);
9392
gameObject.GetComponents(components);
9493
foreach (var component in components)
9594
{
9695
if (component is Transform)
97-
{
9896
transform = component as Transform;
99-
}
100-
else
101-
{
102-
hierarchy.Add(component);
103-
}
104-
}
10597

106-
if (transform != null)
107-
{
108-
int childCount = transform.childCount;
109-
for (var i = 0; i < childCount; i++)
110-
{
111-
GetObjectListFromHierarchy(hierarchy, transform.GetChild(i).gameObject);
112-
}
98+
hierarchy.Add(component);
11399
}
100+
if (transform == null)
101+
return;
102+
103+
int childCount = transform.childCount;
104+
for (var i = 0; i < childCount; i++)
105+
GetObjectListFromHierarchy(hierarchy, transform.GetChild(i).gameObject);
114106
}
115107

116108
private static void RegisterNewObjects(List<Object> newHierarchy, List<Object> hierarchy, string actionName)
@@ -156,9 +148,11 @@ private static void RegisterNewObjects(List<Object> newHierarchy, List<Object> h
156148
break;
157149
}
158150
}
159-
160151
if (requiredComponentsExist)
161152
{
153+
if (danglingObject is Transform)
154+
danglingObject = ((Transform)danglingObject).gameObject;
155+
162156
Undo.RegisterCreatedObjectUndo(danglingObject, actionName);
163157
addedTypes.Add(danglingObject.GetType());
164158
danglingObjects.RemoveAt(i);
@@ -200,9 +194,9 @@ internal static void RevertPrefabInstanceWithUndo(GameObject target)
200194
}
201195

202196
RevertPrefabInstance(root);
203-
204197
List<Object> newHierarchy = new List<Object>();
205198
GetObjectListFromHierarchy(newHierarchy, FindPrefabRoot(root));
199+
206200
RegisterNewObjects(newHierarchy, hierarchy, actionName);
207201
}
208202

Editor/Mono/SceneView/SceneView.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,8 @@ internal void OnGUI()
16571657
if (!UseSceneFiltering())
16581658
{
16591659
// Blit to final target RT in deferred mode
1660-
Handles.DrawCameraStep2(m_Camera, m_RenderMode);
1660+
if (m_Camera.gameObject.activeInHierarchy)
1661+
Handles.DrawCameraStep2(m_Camera, m_RenderMode);
16611662

16621663
// Give editors a chance to kick in. Disable in search mode, editors rendering to the scene
16631664
// view won't be able to properly render to the rendertexture as needed.

Editor/Src/VR/Mono/PlayerSettingsEditorVR.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ private void ErrorOnARDeviceIncompatibility(BuildTargetGroup targetGroup)
488488
{
489489
if (targetGroup == BuildTargetGroup.Android)
490490
{
491-
if (PlayerSettings.Android.androidTangoEnabled && PlayerSettings.GetPlatformVuforiaEnabled(targetGroup))
491+
if (PlayerSettings.Android.ARCoreEnabled && PlayerSettings.GetPlatformVuforiaEnabled(targetGroup))
492492
{
493493
EditorGUILayout.HelpBox("Both ARCore and Vuforia XR Device support cannot be selected at the same time. Please select only one XR Device that will manage the Android device.", MessageType.Error);
494494
}
@@ -516,7 +516,7 @@ internal void TangoGUI(BuildTargetGroup targetGroup)
516516
// Google Tango settings
517517
EditorGUILayout.PropertyField(m_AndroidEnableTango, EditorGUIUtility.TextContent("ARCore Supported"));
518518

519-
if (PlayerSettings.Android.androidTangoEnabled)
519+
if (PlayerSettings.Android.ARCoreEnabled)
520520
{
521521
EditorGUI.indentLevel++;
522522

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Unity 2017.4.10f1 C# reference source code
1+
## Unity 2017.4.11f1 C# reference source code
22

33
The C# part of the Unity engine and editor source code.
44
May be used for reference purposes only.

Runtime/AR/ScriptBindings/ARBackgroundRenderer.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,11 @@ protected void DisableARBackgroundRendering()
162162
if (null == m_CommandBuffer)
163163
return;
164164

165-
Camera camera;
166-
167-
if (m_Camera != null)
168-
camera = m_Camera;
169-
else
170-
camera = Camera.main;
165+
Camera camera = m_Camera ?? Camera.main;
166+
if (camera == null)
167+
return;
171168

172-
if (camera != null)
173-
camera.clearFlags = m_CameraClearFlags;
169+
camera.clearFlags = m_CameraClearFlags;
174170

175171
// Command buffer
176172
camera.RemoveCommandBuffer(CameraEvent.BeforeForwardOpaque, m_CommandBuffer);

Runtime/Export/MouseEvents.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static void DoSendMouseEvents(int skipRTCameras)
123123

124124
Vector2 pos = new Vector2(eventPosition.x / w, eventPosition.y / h);
125125

126-
// If it's outside the camera's viewport, do nothing
126+
// If the mouse is outside the display bounds, do nothing
127127
if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
128128
continue;
129129
}
@@ -132,13 +132,13 @@ static void DoSendMouseEvents(int skipRTCameras)
132132
// The multiple display system is not supported on all platforms, when it is not supported the returned position
133133
// will be all zeros so when the returned index is 0 we will default to the mouse position to be safe.
134134
eventPosition = mousePosition;
135-
136-
// Is the mouse inside the cameras viewport?
137-
var rect = camera.pixelRect;
138-
if (!rect.Contains(eventPosition))
139-
continue;
140135
}
141136

137+
// Is the mouse inside the cameras viewport?
138+
var rect = camera.pixelRect;
139+
if (!rect.Contains(eventPosition))
140+
continue;
141+
142142
HitTestLegacyGUI(camera, eventPosition, ref m_CurrentHit[m_HitIndexGUI]);
143143

144144
// There is no need to continue if the camera shouldn't be sending out events

artifacts/generated/common/editor/EditorSpriteAtlasBindings.gen.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ internal static partial class SpriteAtlasExtensions
142142
[System.Runtime.CompilerServices.MethodImplAttribute((System.Runtime.CompilerServices.MethodImplOptions)0x1000)]
143143
extern internal static Texture2D[] GetPreviewTextures (this SpriteAtlas spriteAtlas) ;
144144

145+
[UnityEngine.Scripting.GeneratedByOldBindingsGeneratorAttribute] // Temporarily necessary for bindings migration
146+
[System.Runtime.CompilerServices.MethodImplAttribute((System.Runtime.CompilerServices.MethodImplOptions)0x1000)]
147+
extern internal static Texture2D[] GetPreviewAlphaTextures (this SpriteAtlas spriteAtlas) ;
148+
145149
[UnityEngine.Scripting.GeneratedByOldBindingsGeneratorAttribute] // Temporarily necessary for bindings migration
146150
[System.Runtime.CompilerServices.MethodImplAttribute((System.Runtime.CompilerServices.MethodImplOptions)0x1000)]
147151
extern internal static TextureImporterFormat FormatDetermineByAtlasSettings (this SpriteAtlas spriteAtlas, BuildTarget target) ;

artifacts/generated/common/editor/PlayerSettingsAndroidBindings.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public extern static bool androidIsGame
227227
set;
228228
}
229229

230-
internal extern static bool androidTangoEnabled
230+
public extern static bool ARCoreEnabled
231231
{
232232
[UnityEngine.Scripting.GeneratedByOldBindingsGeneratorAttribute] // Temporarily necessary for bindings migration
233233
[System.Runtime.CompilerServices.MethodImplAttribute((System.Runtime.CompilerServices.MethodImplOptions)0x1000)]

0 commit comments

Comments
 (0)