Skip to content

Commit 84af4f4

Browse files
author
Unity Technologies
committed
Unity 2018.3.0a1 C# reference source code
1 parent 3cfc6c4 commit 84af4f4

File tree

839 files changed

+44342
-25628
lines changed

Some content is hidden

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

839 files changed

+44342
-25628
lines changed

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

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,24 @@ namespace UnityEditor.U2D.Common
1111
{
1212
internal class TexturePlatformSettingsViewController : ITexturePlatformSettingsController
1313
{
14-
public bool HandleDefaultSettings(List<TextureImporterPlatformSettings> platformSettings, ITexturePlatformSettingsView view)
14+
public bool HandleDefaultSettings(List<TextureImporterPlatformSettings> platformSettings, ITexturePlatformSettingsView view, ITexturePlatformSettingsFormatHelper formatHelper)
1515
{
1616
Assert.IsTrue(platformSettings.Count > 0, "At least 1 platform setting is needed to display the texture platform setting UI.");
1717

1818
var allSize = platformSettings[0].maxTextureSize;
19+
var allFormat = platformSettings[0].format;
1920
var allCompression = platformSettings[0].textureCompression;
2021
var allUseCrunchedCompression = platformSettings[0].crunchedCompression;
2122
var allCompressionQuality = platformSettings[0].compressionQuality;
2223

23-
var newSize = allSize;
24-
var newCompression = allCompression;
25-
var newUseCrunchedCompression = allUseCrunchedCompression;
26-
var newCompressionQuality = allCompressionQuality;
27-
2824
var mixedSize = false;
25+
var mixedFormat = false;
2926
var mixedCompression = false;
3027
var mixedUseCrunchedCompression = false;
3128
var mixedCompressionQuality = false;
3229

3330
var sizeChanged = false;
31+
var formatChanged = false;
3432
var compressionChanged = false;
3533
var useCrunchedCompressionChanged = false;
3634
var compressionQualityChanged = false;
@@ -40,6 +38,8 @@ public bool HandleDefaultSettings(List<TextureImporterPlatformSettings> platform
4038
var settings = platformSettings[i];
4139
if (settings.maxTextureSize != allSize)
4240
mixedSize = true;
41+
if (settings.format != allFormat)
42+
mixedFormat = true;
4343
if (settings.textureCompression != allCompression)
4444
mixedCompression = true;
4545
if (settings.crunchedCompression != allUseCrunchedCompression)
@@ -48,30 +48,45 @@ public bool HandleDefaultSettings(List<TextureImporterPlatformSettings> platform
4848
mixedCompressionQuality = true;
4949
}
5050

51-
newSize = view.DrawMaxSize(allSize, mixedSize, out sizeChanged);
52-
newCompression = view.DrawCompression(allCompression, mixedCompression, out compressionChanged);
53-
if (!mixedCompression && allCompression != TextureImporterCompression.Uncompressed)
51+
allSize = view.DrawMaxSize(allSize, mixedSize, false, out sizeChanged);
52+
53+
int[] formatValues = null;
54+
string[] formatStrings = null;
55+
formatHelper.AcquireDefaultTextureFormatValuesAndStrings(out formatValues, out formatStrings);
56+
57+
allFormat = view.DrawFormat(allFormat, formatValues, formatStrings, mixedFormat, false, out formatChanged);
58+
59+
if (allFormat == TextureImporterFormat.Automatic && (!mixedFormat || formatChanged))
5460
{
55-
newUseCrunchedCompression = view.DrawUseCrunchedCompression(allUseCrunchedCompression, mixedUseCrunchedCompression, out useCrunchedCompressionChanged);
61+
allCompression = view.DrawCompression(allCompression, mixedCompression, false, out compressionChanged);
5662

57-
if (!mixedUseCrunchedCompression && allUseCrunchedCompression)
63+
if (allCompression != TextureImporterCompression.Uncompressed && (!mixedCompression || compressionChanged))
5864
{
59-
newCompressionQuality = view.DrawCompressionQualitySlider(allCompressionQuality, mixedCompressionQuality, out compressionQualityChanged);
65+
allUseCrunchedCompression = view.DrawUseCrunchedCompression(allUseCrunchedCompression,
66+
mixedUseCrunchedCompression, false, out useCrunchedCompressionChanged);
67+
68+
if (allUseCrunchedCompression && (!mixedUseCrunchedCompression || useCrunchedCompressionChanged))
69+
{
70+
allCompressionQuality = view.DrawCompressionQualitySlider(allCompressionQuality,
71+
mixedCompressionQuality, false, out compressionQualityChanged);
72+
}
6073
}
6174
}
6275

63-
if (sizeChanged || compressionChanged || useCrunchedCompressionChanged || compressionQualityChanged)
76+
if (sizeChanged || compressionChanged || formatChanged || useCrunchedCompressionChanged || compressionQualityChanged)
6477
{
6578
for (var i = 0; i < platformSettings.Count; ++i)
6679
{
6780
if (sizeChanged)
68-
platformSettings[i].maxTextureSize = newSize;
81+
platformSettings[i].maxTextureSize = allSize;
82+
if (formatChanged)
83+
platformSettings[i].format = allFormat;
6984
if (compressionChanged)
70-
platformSettings[i].textureCompression = newCompression;
85+
platformSettings[i].textureCompression = allCompression;
7186
if (useCrunchedCompressionChanged)
72-
platformSettings[i].crunchedCompression = newUseCrunchedCompression;
87+
platformSettings[i].crunchedCompression = allUseCrunchedCompression;
7388
if (compressionQualityChanged)
74-
platformSettings[i].compressionQuality = newCompressionQuality;
89+
platformSettings[i].compressionQuality = allCompressionQuality;
7590
}
7691
return true;
7792
}
@@ -87,21 +102,19 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
87102
var allSize = platformSettings[0].maxTextureSize;
88103
var allFormat = platformSettings[0].format;
89104
var allCompressionQuality = platformSettings[0].compressionQuality;
90-
91-
var newOverride = allOverride;
92-
var newSize = allSize;
93-
var newFormat = allFormat;
94-
var newCompressionQuality = allCompressionQuality;
105+
var allAlphaSplit = platformSettings[0].allowsAlphaSplitting;
95106

96107
var mixedOverride = false;
97108
var mixedSize = false;
98109
var mixedFormat = false;
99110
var mixedCompression = false;
111+
var mixedAlphaSplit = false;
100112

101113
var overrideChanged = false;
102114
var sizeChanged = false;
103115
var formatChanged = false;
104116
var compressionChanged = false;
117+
var alphaSplitChanged = false;
105118

106119
for (var i = 1; i < platformSettings.Count; ++i)
107120
{
@@ -114,22 +127,22 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
114127
mixedFormat = true;
115128
if (settings.compressionQuality != allCompressionQuality)
116129
mixedCompression = true;
130+
if (settings.allowsAlphaSplitting != allAlphaSplit)
131+
mixedAlphaSplit = true;
117132
}
118133

119-
newOverride = view.DrawOverride(allOverride, mixedOverride, out overrideChanged);
134+
allOverride = view.DrawOverride(allOverride, mixedOverride, out overrideChanged);
120135

121-
if (!mixedOverride && allOverride)
122-
{
123-
newSize = view.DrawMaxSize(allSize, mixedSize, out sizeChanged);
124-
}
136+
allSize = view.DrawMaxSize(allSize, mixedSize, mixedOverride || !allOverride, out sizeChanged);
125137

126138
int[] formatValues = null;
127139
string[] formatStrings = null;
140+
128141
formatHelper.AcquireTextureFormatValuesAndStrings(buildTarget, out formatValues, out formatStrings);
129142

130-
newFormat = view.DrawFormat(allFormat, formatValues, formatStrings, mixedFormat, mixedOverride || !allOverride, out formatChanged);
143+
allFormat = view.DrawFormat(allFormat, formatValues, formatStrings, mixedFormat, mixedOverride || !allOverride, out formatChanged);
131144

132-
if (!mixedFormat && !mixedOverride && allOverride && formatHelper.TextureFormatRequireCompressionQualityInput(allFormat))
145+
if (!mixedFormat && formatHelper.TextureFormatRequireCompressionQualityInput(allFormat))
133146
{
134147
bool showAsEnum =
135148
buildTarget == BuildTarget.iOS ||
@@ -145,15 +158,15 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
145158
else if (allCompressionQuality == (int)TextureCompressionQuality.Best)
146159
compressionMode = 2;
147160

148-
var returnValue = view.DrawCompressionQualityPopup(compressionMode, mixedCompression, out compressionChanged);
161+
compressionMode = view.DrawCompressionQualityPopup(compressionMode, mixedCompression, mixedOverride || !allOverride, out compressionChanged);
149162

150163
if (compressionChanged)
151164
{
152-
switch (returnValue)
165+
switch (compressionMode)
153166
{
154-
case 0: newCompressionQuality = (int)TextureCompressionQuality.Fast; break;
155-
case 1: newCompressionQuality = (int)TextureCompressionQuality.Normal; break;
156-
case 2: newCompressionQuality = (int)TextureCompressionQuality.Best; break;
167+
case 0: allCompressionQuality = (int)TextureCompressionQuality.Fast; break;
168+
case 1: allCompressionQuality = (int)TextureCompressionQuality.Normal; break;
169+
case 2: allCompressionQuality = (int)TextureCompressionQuality.Best; break;
157170

158171
default:
159172
Assert.IsTrue(false, "ITexturePlatformSettingsView.DrawCompressionQualityPopup should never return compression option value that's not 0, 1 or 2.");
@@ -163,22 +176,32 @@ public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporter
163176
}
164177
else
165178
{
166-
newCompressionQuality = view.DrawCompressionQualitySlider(allCompressionQuality, mixedCompression, out compressionChanged);
179+
allCompressionQuality = view.DrawCompressionQualitySlider(allCompressionQuality, mixedCompression, mixedOverride || !allOverride, out compressionChanged);
180+
}
181+
182+
// show the ETC1 split option only for sprites on platforms supporting ETC.
183+
bool isETCPlatform = TextureImporter.IsETC1SupportedByBuildTarget(buildTarget);
184+
bool isETCFormatSelected = TextureImporter.IsTextureFormatETC1Compression((TextureFormat)allFormat);
185+
if (isETCPlatform && isETCFormatSelected)
186+
{
187+
allAlphaSplit = view.DrawAlphaSplit(allAlphaSplit, mixedAlphaSplit, mixedOverride || !allOverride, out alphaSplitChanged);
167188
}
168189
}
169190

170-
if (overrideChanged || sizeChanged || formatChanged || compressionChanged)
191+
if (overrideChanged || sizeChanged || formatChanged || compressionChanged || alphaSplitChanged)
171192
{
172193
for (var i = 0; i < platformSettings.Count; ++i)
173194
{
174195
if (overrideChanged)
175-
platformSettings[i].overridden = newOverride;
196+
platformSettings[i].overridden = allOverride;
176197
if (sizeChanged)
177-
platformSettings[i].maxTextureSize = newSize;
198+
platformSettings[i].maxTextureSize = allSize;
178199
if (formatChanged)
179-
platformSettings[i].format = newFormat;
200+
platformSettings[i].format = allFormat;
180201
if (compressionChanged)
181-
platformSettings[i].compressionQuality = newCompressionQuality;
202+
platformSettings[i].compressionQuality = allCompressionQuality;
203+
if (alphaSplitChanged)
204+
platformSettings[i].allowsAlphaSplitting = allAlphaSplit;
182205
}
183206

184207
return true;

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

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Unity Technologies. For terms of use, see
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

5-
using UnityEngine;
65
using UnityEditor.U2D.Interface;
76

87
namespace UnityEditor.U2D.Common
@@ -11,42 +10,14 @@ internal class TexturePlatformSettingsFormatHelper : ITexturePlatformSettingsFor
1110
{
1211
public void AcquireTextureFormatValuesAndStrings(BuildTarget buildTarget, out int[] formatValues, out string[] formatStrings)
1312
{
14-
if (TextureImporterInspector.IsGLESMobileTargetPlatform(buildTarget))
15-
{
16-
if (buildTarget == BuildTarget.iOS || buildTarget == BuildTarget.tvOS)
17-
{
18-
formatValues = TextureImportPlatformSettings.kTextureFormatsValueApplePVR;
19-
formatStrings = TextureImporterInspector.s_TextureFormatStringsApplePVR;
20-
}
21-
else
22-
{
23-
formatValues = TextureImportPlatformSettings.kTextureFormatsValueAndroid;
24-
formatStrings = TextureImporterInspector.s_TextureFormatStringsAndroid;
25-
}
26-
}
27-
else
28-
{
29-
if (buildTarget == BuildTarget.WebGL)
30-
{
31-
formatValues = TextureImportPlatformSettings.kTextureFormatsValueWebGL;
32-
formatStrings = TextureImporterInspector.s_TextureFormatStringsWebGL;
33-
}
34-
else if (buildTarget == BuildTarget.PSP2)
35-
{
36-
formatValues = TextureImportPlatformSettings.kTextureFormatsValuePSP2;
37-
formatStrings = TextureImporterInspector.s_TextureFormatStringsPSP2;
38-
}
39-
else if (buildTarget == BuildTarget.Switch)
40-
{
41-
formatValues = TextureImportPlatformSettings.kTextureFormatsValueSwitch;
42-
formatStrings = TextureImporterInspector.s_TextureFormatStringsSwitch;
43-
}
44-
else
45-
{
46-
formatValues = TextureImportPlatformSettings.kTextureFormatsValueDefault;
47-
formatStrings = TextureImporterInspector.s_TextureFormatStringsDefault;
48-
}
49-
}
13+
TextureImportValidFormats.GetPlatformTextureFormatValuesAndStrings(TextureImporterType.Sprite, buildTarget,
14+
out formatValues, out formatStrings);
15+
}
16+
17+
public void AcquireDefaultTextureFormatValuesAndStrings(out int[] formatValues, out string[] formatStrings)
18+
{
19+
TextureImportValidFormats.GetDefaultTextureFormatValuesAndStrings(TextureImporterType.Sprite,
20+
out formatValues, out formatStrings);
5021
}
5122

5223
public bool TextureFormatRequireCompressionQualityInput(TextureImporterFormat format)

0 commit comments

Comments
 (0)