Skip to content

Commit 9be0e82

Browse files
author
Unity Technologies
committed
Unity 2017.2.0a1 C# reference source code
1 parent c8b8696 commit 9be0e82

File tree

409 files changed

+14930
-5577
lines changed

Some content is hidden

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

409 files changed

+14930
-5577
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System.Collections.Generic;
6+
using UnityEditor.U2D.Interface;
7+
using UnityEngine;
8+
using UnityEngine.Assertions;
9+
10+
namespace UnityEditor.U2D.Common
11+
{
12+
internal class TexturePlatformSettingsViewController : ITexturePlatformSettingsController
13+
{
14+
public bool HandleDefaultSettings(List<TextureImporterPlatformSettings> platformSettings, ITexturePlatformSettingsView view)
15+
{
16+
Assert.IsTrue(platformSettings.Count > 0, "At least 1 platform setting is needed to display the texture platform setting UI.");
17+
18+
int allSize = platformSettings[0].maxTextureSize;
19+
TextureImporterCompression allCompression = platformSettings[0].textureCompression;
20+
bool allUseCrunchedCompression = platformSettings[0].crunchedCompression;
21+
int allCompressionQuality = platformSettings[0].compressionQuality;
22+
23+
var newSize = allSize;
24+
var newCompression = allCompression;
25+
var newUseCrunchedCompression = allUseCrunchedCompression;
26+
var newCompressionQuality = allCompressionQuality;
27+
28+
bool mixedSize = false;
29+
bool mixedCompression = false;
30+
bool mixedUseCrunchedCompression = false;
31+
bool mixedCompressionQuality = false;
32+
33+
bool sizeChanged = false;
34+
bool compressionChanged = false;
35+
bool useCrunchedCompressionChanged = false;
36+
bool compressionQualityChanged = false;
37+
38+
for (var i = 1; i < platformSettings.Count; ++i)
39+
{
40+
var settings = platformSettings[i];
41+
if (settings.maxTextureSize != allSize)
42+
mixedSize = true;
43+
if (settings.textureCompression != allCompression)
44+
mixedCompression = true;
45+
if (settings.crunchedCompression != allUseCrunchedCompression)
46+
mixedUseCrunchedCompression = true;
47+
if (settings.compressionQuality != allCompressionQuality)
48+
mixedCompressionQuality = true;
49+
}
50+
51+
newSize = view.DrawMaxSize(allSize, mixedSize, out sizeChanged);
52+
newCompression = view.DrawCompression(allCompression, mixedCompression, out compressionChanged);
53+
if (!mixedCompression && allCompression != TextureImporterCompression.Uncompressed)
54+
{
55+
newUseCrunchedCompression = view.DrawUseCrunchedCompression(allUseCrunchedCompression, mixedUseCrunchedCompression, out useCrunchedCompressionChanged);
56+
57+
if (!mixedUseCrunchedCompression && allUseCrunchedCompression)
58+
{
59+
newCompressionQuality = view.DrawCompressionQualitySlider(allCompressionQuality, mixedCompressionQuality, out compressionQualityChanged);
60+
}
61+
}
62+
63+
if (sizeChanged || compressionChanged || useCrunchedCompressionChanged || compressionQualityChanged)
64+
{
65+
for (var i = 0; i < platformSettings.Count; ++i)
66+
{
67+
if (sizeChanged)
68+
platformSettings[i].maxTextureSize = newSize;
69+
if (compressionChanged)
70+
platformSettings[i].textureCompression = newCompression;
71+
if (useCrunchedCompressionChanged)
72+
platformSettings[i].crunchedCompression = newUseCrunchedCompression;
73+
if (compressionQualityChanged)
74+
platformSettings[i].compressionQuality = newCompressionQuality;
75+
}
76+
return true;
77+
}
78+
else
79+
return false;
80+
}
81+
82+
public bool HandlePlatformSettings(BuildTarget buildTarget, List<TextureImporterPlatformSettings> platformSettings, ITexturePlatformSettingsView view, ITexturePlatformSettingsFormatHelper formatHelper)
83+
{
84+
Assert.IsTrue(platformSettings.Count > 0, "At least 1 platform setting is needed to display the texture platform setting UI.");
85+
86+
bool allOverride = platformSettings[0].overridden;
87+
int allSize = platformSettings[0].maxTextureSize;
88+
TextureImporterFormat allFormat = platformSettings[0].format;
89+
int allCompressionQuality = platformSettings[0].compressionQuality;
90+
91+
var newOverride = allOverride;
92+
var newSize = allSize;
93+
var newFormat = allFormat;
94+
var newCompressionQuality = allCompressionQuality;
95+
96+
bool mixedOverride = false;
97+
bool mixedSize = false;
98+
bool mixedFormat = false;
99+
bool mixedCompression = false;
100+
101+
bool overrideChanged = false;
102+
bool sizeChanged = false;
103+
bool formatChanged = false;
104+
bool compressionChanged = false;
105+
106+
for (var i = 1; i < platformSettings.Count; ++i)
107+
{
108+
var settings = platformSettings[i];
109+
if (settings.overridden != allOverride)
110+
mixedOverride = true;
111+
if (settings.maxTextureSize != allSize)
112+
mixedSize = true;
113+
if (settings.format != allFormat)
114+
mixedFormat = true;
115+
if (settings.compressionQuality != allCompressionQuality)
116+
mixedCompression = true;
117+
}
118+
119+
newOverride = view.DrawOverride(allOverride, mixedOverride, out overrideChanged);
120+
121+
if (!mixedOverride && allOverride)
122+
{
123+
newSize = view.DrawMaxSize(allSize, mixedSize, out sizeChanged);
124+
}
125+
126+
int[] formatValues = null;
127+
string[] formatStrings = null;
128+
formatHelper.AcquireTextureFormatValuesAndStrings(buildTarget, out formatValues, out formatStrings);
129+
130+
newFormat = view.DrawFormat(allFormat, formatValues, formatStrings, mixedFormat, mixedOverride || !allOverride, out formatChanged);
131+
132+
if (!mixedFormat && !mixedOverride && allOverride && formatHelper.TextureFormatRequireCompressionQualityInput(allFormat))
133+
{
134+
bool showAsEnum =
135+
buildTarget == BuildTarget.iOS ||
136+
buildTarget == BuildTarget.tvOS ||
137+
buildTarget == BuildTarget.Android ||
138+
buildTarget == BuildTarget.Tizen ||
139+
buildTarget == BuildTarget.SamsungTV
140+
;
141+
142+
if (showAsEnum)
143+
{
144+
int compressionMode = 1;
145+
if (allCompressionQuality == (int)TextureCompressionQuality.Fast)
146+
compressionMode = 0;
147+
else if (allCompressionQuality == (int)TextureCompressionQuality.Best)
148+
compressionMode = 2;
149+
150+
var returnValue = view.DrawCompressionQualityPopup(compressionMode, mixedCompression, out compressionChanged);
151+
152+
if (compressionChanged)
153+
{
154+
switch (returnValue)
155+
{
156+
case 0: newCompressionQuality = (int)TextureCompressionQuality.Fast; break;
157+
case 1: newCompressionQuality = (int)TextureCompressionQuality.Normal; break;
158+
case 2: newCompressionQuality = (int)TextureCompressionQuality.Best; break;
159+
160+
default:
161+
Assert.IsTrue(false, "ITexturePlatformSettingsView.DrawCompressionQualityPopup should never return compression option value that's not 0, 1 or 2.");
162+
break;
163+
}
164+
}
165+
}
166+
else
167+
{
168+
newCompressionQuality = view.DrawCompressionQualitySlider(allCompressionQuality, mixedCompression, out compressionChanged);
169+
}
170+
}
171+
172+
if (overrideChanged || sizeChanged || formatChanged || compressionChanged)
173+
{
174+
for (var i = 0; i < platformSettings.Count; ++i)
175+
{
176+
if (overrideChanged)
177+
platformSettings[i].overridden = newOverride;
178+
if (sizeChanged)
179+
platformSettings[i].maxTextureSize = newSize;
180+
if (formatChanged)
181+
platformSettings[i].format = newFormat;
182+
if (compressionChanged)
183+
platformSettings[i].compressionQuality = newCompressionQuality;
184+
}
185+
186+
return true;
187+
}
188+
else
189+
return false;
190+
}
191+
}
192+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using UnityEngine;
6+
using UnityEditor.U2D.Interface;
7+
8+
namespace UnityEditor.U2D.Common
9+
{
10+
internal class TexturePlatformSettingsFormatHelper : ITexturePlatformSettingsFormatHelper
11+
{
12+
public void AcquireTextureFormatValuesAndStrings(BuildTarget buildTarget, out int[] formatValues, out string[] formatStrings)
13+
{
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 if (buildTarget == BuildTarget.SamsungTV)
22+
{
23+
formatValues = TextureImportPlatformSettings.kTextureFormatsValueSTV;
24+
formatStrings = TextureImporterInspector.s_TextureFormatStringsSTV;
25+
}
26+
else
27+
{
28+
formatValues = TextureImportPlatformSettings.kTextureFormatsValueAndroid;
29+
formatStrings = TextureImporterInspector.s_TextureFormatStringsAndroid;
30+
}
31+
}
32+
else
33+
{
34+
if (buildTarget == BuildTarget.WebGL)
35+
{
36+
formatValues = TextureImportPlatformSettings.kTextureFormatsValueWebGL;
37+
formatStrings = TextureImporterInspector.s_TextureFormatStringsWebGL;
38+
}
39+
else if (buildTarget == BuildTarget.WiiU)
40+
{
41+
formatValues = TextureImportPlatformSettings.kTextureFormatsValueWiiU;
42+
formatStrings = TextureImporterInspector.s_TextureFormatStringsWiiU;
43+
}
44+
else
45+
{
46+
formatValues = TextureImportPlatformSettings.kTextureFormatsValueDefault;
47+
formatStrings = TextureImporterInspector.s_TextureFormatStringsDefault;
48+
}
49+
}
50+
}
51+
52+
public bool TextureFormatRequireCompressionQualityInput(TextureImporterFormat format)
53+
{
54+
return TextureImporterInspector.IsFormatRequireCompressionSetting(format);
55+
}
56+
}
57+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using UnityEngine;
6+
using UnityEditor.U2D.Interface;
7+
8+
namespace UnityEditor.U2D.Common
9+
{
10+
internal class TexturePlatformSettingsView : ITexturePlatformSettingsView
11+
{
12+
class Styles
13+
{
14+
public readonly GUIContent textureFormatLabel = EditorGUIUtility.TextContent("Format");
15+
public readonly GUIContent maxTextureSizeLabel = EditorGUIUtility.TextContent("Max Texture Size|Maximum size of the packed texture.");
16+
public readonly GUIContent compressionLabel = EditorGUIUtility.TextContent("Compression|How will this texture be compressed?");
17+
public readonly GUIContent useCrunchedCompressionLabel = EditorGUIUtility.TextContent("Use Crunch Compression|Texture is crunch-compressed to save space on disk when applicable.");
18+
public readonly GUIContent compressionQualityLabel = EditorGUIUtility.TextContent("Compressor Quality");
19+
public readonly GUIContent compressionQualitySliderLabel = EditorGUIUtility.TextContent("Compressor Quality|Use the slider to adjust compression quality from 0 (Fastest) to 100 (Best)");
20+
21+
public readonly int[] kMaxTextureSizeValues = { 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
22+
public readonly GUIContent[] kMaxTextureSizeStrings;
23+
24+
public readonly GUIContent[] kTextureCompressionOptions =
25+
{
26+
EditorGUIUtility.TextContent("None|Texture is not compressed."),
27+
EditorGUIUtility.TextContent("Low Quality|Texture compressed with low quality but high performance, high compression format."),
28+
EditorGUIUtility.TextContent("Normal Quality|Texture is compressed with a standard format."),
29+
EditorGUIUtility.TextContent("High Quality|Texture compressed with a high quality format."),
30+
};
31+
32+
public readonly int[] kTextureCompressionValues =
33+
{
34+
(int)TextureImporterCompression.Uncompressed,
35+
(int)TextureImporterCompression.CompressedLQ,
36+
(int)TextureImporterCompression.Compressed,
37+
(int)TextureImporterCompression.CompressedHQ
38+
};
39+
40+
public readonly GUIContent[] kMobileCompressionQualityOptions =
41+
{
42+
EditorGUIUtility.TextContent("Fast"),
43+
EditorGUIUtility.TextContent("Normal"),
44+
EditorGUIUtility.TextContent("Best")
45+
};
46+
47+
public Styles()
48+
{
49+
kMaxTextureSizeStrings = new GUIContent[kMaxTextureSizeValues.Length];
50+
for (var i = 0; i < kMaxTextureSizeValues.Length; ++i)
51+
kMaxTextureSizeStrings[i] = EditorGUIUtility.TextContent(string.Format("{0}", kMaxTextureSizeValues[i]));
52+
}
53+
}
54+
55+
private static Styles s_Styles;
56+
57+
public string buildPlatformTitle { get; set; }
58+
59+
internal TexturePlatformSettingsView()
60+
{
61+
s_Styles = s_Styles ?? new Styles();
62+
}
63+
64+
public virtual TextureImporterCompression DrawCompression(TextureImporterCompression defaultValue, bool isMixedValue, out bool changed)
65+
{
66+
EditorGUI.BeginChangeCheck();
67+
EditorGUI.showMixedValue = isMixedValue;
68+
defaultValue = (TextureImporterCompression)EditorGUILayout.IntPopup(s_Styles.compressionLabel, (int)defaultValue, s_Styles.kTextureCompressionOptions, s_Styles.kTextureCompressionValues);
69+
EditorGUI.showMixedValue = false;
70+
changed = EditorGUI.EndChangeCheck();
71+
return defaultValue;
72+
}
73+
74+
public virtual bool DrawUseCrunchedCompression(bool defaultValue, bool isMixedValue, out bool changed)
75+
{
76+
EditorGUI.BeginChangeCheck();
77+
EditorGUI.showMixedValue = isMixedValue;
78+
defaultValue = EditorGUILayout.Toggle(s_Styles.useCrunchedCompressionLabel, defaultValue);
79+
EditorGUI.showMixedValue = false;
80+
changed = EditorGUI.EndChangeCheck();
81+
return defaultValue;
82+
}
83+
84+
public virtual bool DrawOverride(bool defaultValue, bool isMixedValue, out bool changed)
85+
{
86+
EditorGUI.BeginChangeCheck();
87+
EditorGUI.showMixedValue = isMixedValue;
88+
defaultValue = EditorGUILayout.ToggleLeft(EditorGUIUtility.TempContent("Override for " + buildPlatformTitle), defaultValue);
89+
EditorGUI.showMixedValue = false;
90+
changed = EditorGUI.EndChangeCheck();
91+
return defaultValue;
92+
}
93+
94+
public virtual int DrawMaxSize(int defaultValue, bool isMixedValue, out bool changed)
95+
{
96+
EditorGUI.BeginChangeCheck();
97+
EditorGUI.showMixedValue = isMixedValue;
98+
defaultValue = EditorGUILayout.IntPopup(s_Styles.maxTextureSizeLabel, defaultValue, s_Styles.kMaxTextureSizeStrings, s_Styles.kMaxTextureSizeValues);
99+
EditorGUI.showMixedValue = false;
100+
changed = EditorGUI.EndChangeCheck();
101+
return defaultValue;
102+
}
103+
104+
public virtual TextureImporterFormat DrawFormat(TextureImporterFormat defaultValue, int[] displayValues, string[] displayStrings, bool isMixedValue, bool isDisabled, out bool changed)
105+
{
106+
using (new EditorGUI.DisabledScope(isDisabled))
107+
{
108+
EditorGUI.BeginChangeCheck();
109+
EditorGUI.showMixedValue = isMixedValue;
110+
defaultValue = (TextureImporterFormat)EditorGUILayout.IntPopup(s_Styles.textureFormatLabel, (int)defaultValue, EditorGUIUtility.TempContent(displayStrings), displayValues);
111+
EditorGUI.showMixedValue = false;
112+
changed = EditorGUI.EndChangeCheck();
113+
return defaultValue;
114+
}
115+
}
116+
117+
public virtual int DrawCompressionQualityPopup(int defaultValue, bool isMixedValue, out bool changed)
118+
{
119+
EditorGUI.BeginChangeCheck();
120+
EditorGUI.showMixedValue = isMixedValue;
121+
defaultValue = EditorGUILayout.Popup(s_Styles.compressionQualityLabel, defaultValue, s_Styles.kMobileCompressionQualityOptions);
122+
EditorGUI.showMixedValue = false;
123+
changed = EditorGUI.EndChangeCheck();
124+
return defaultValue;
125+
}
126+
127+
public virtual int DrawCompressionQualitySlider(int defaultValue, bool isMixedValue, out bool changed)
128+
{
129+
EditorGUI.BeginChangeCheck();
130+
EditorGUI.showMixedValue = isMixedValue;
131+
defaultValue = EditorGUILayout.IntSlider(s_Styles.compressionQualitySliderLabel, defaultValue, 0, 100);
132+
EditorGUI.showMixedValue = false;
133+
changed = EditorGUI.EndChangeCheck();
134+
return defaultValue;
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)