/
TextureImporterInspector.cs
1851 lines (1574 loc) · 96 KB
/
TextureImporterInspector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEditor.Build;
using System.Collections.Generic;
using System;
using UnityEditor.AssetImporters;
using UnityEngine.Experimental.Rendering;
using Object = UnityEngine.Object;
using VirtualTexturing = UnityEngine.Rendering.VirtualTexturing;
namespace UnityEditor
{
// Cubemap convolution mode
public enum TextureImporterCubemapConvolution
{
// Do not convolve cubemap (default).
None = 0,
// Convolve for specular reflections with varying roughness.
Specular = 1,
// Convolve for diffuse-only reflection (irradiance cubemap).
Diffuse = 2
}
// Kept for backward compatibility
public enum TextureImporterRGBMMode
{
Auto = 0,
On = 1,
Off = 2,
Encoded = 3,
}
[CustomEditor(typeof(TextureImporter))]
[CanEditMultipleObjects]
internal class TextureImporterInspector : AssetImporterEditor
{
public static string s_DefaultPlatformName = "DefaultTexturePlatform";
[Flags]
private enum TextureInspectorGUIElement
{
None = 0,
PowerOfTwo = 1 << 0,
Readable = 1 << 1,
AlphaHandling = 1 << 2,
ColorSpace = 1 << 3,
MipMaps = 1 << 4,
NormalMap = 1 << 5,
Sprite = 1 << 6,
Cookie = 1 << 7,
CubeMapConvolution = 1 << 8,
CubeMapping = 1 << 9,
SingleChannelComponent = 1 << 11,
PngGamma = 1 << 12,
VTOnly = 1 << 13,
ElementsAtlas = 1 << 14,
Swizzle = 1 << 15,
}
private struct TextureInspectorTypeGUIProperties
{
public TextureInspectorGUIElement commonElements;
public TextureInspectorGUIElement advancedElements;
public TextureImporterShape shapeCaps;
public TextureInspectorTypeGUIProperties(TextureInspectorGUIElement _commonElements, TextureInspectorGUIElement _advancedElements, TextureImporterShape _shapeCaps)
{
commonElements = _commonElements;
advancedElements = _advancedElements;
shapeCaps = _shapeCaps;
}
}
SerializedProperty m_TextureType;
internal TextureImporterType textureType
{
get
{
if (m_TextureType.hasMultipleDifferentValues)
return (TextureImporterType)0;
return (TextureImporterType)(m_TextureType.intValue);
}
}
private delegate void GUIMethod(TextureInspectorGUIElement guiElements);
private Dictionary<TextureInspectorGUIElement, GUIMethod> m_GUIElementMethods = new Dictionary<TextureInspectorGUIElement, GUIMethod>();
internal bool textureTypeHasMultipleDifferentValues
{
get { return m_TextureType.hasMultipleDifferentValues; }
}
public override void OnDisable()
{
base.OnDisable();
EditorPrefs.SetBool("TextureImporterShowAdvanced", m_ShowAdvanced);
EditorPrefs.SetBool("TextureImporterShowMipmapGenerationSettings", m_ShowMipmapGenerationSettings);
}
// Don't show the imported texture as a separate editor
public override bool showImportedObject { get { return false; } }
public static bool IsCompressedDXTTextureFormat(TextureImporterFormat format)
{
return (format == TextureImporterFormat.DXT1 || format == TextureImporterFormat.DXT5);
}
// Which platforms should we display?
// For each of these, what are the formats etc. to display?
[SerializeField]
internal List<TextureImportPlatformSettings> m_PlatformSettings;
TextureInspector textureInspector
{
get => preview as TextureInspector;
}
internal static readonly TextureImporterFormat[] kFormatsWithCompressionSettings =
{
TextureImporterFormat.DXT1Crunched,
TextureImporterFormat.DXT5Crunched,
TextureImporterFormat.ETC_RGB4Crunched,
TextureImporterFormat.ETC2_RGBA8Crunched,
TextureImporterFormat.PVRTC_RGB2,
TextureImporterFormat.PVRTC_RGB4,
TextureImporterFormat.PVRTC_RGBA2,
TextureImporterFormat.PVRTC_RGBA4,
TextureImporterFormat.ETC_RGB4,
TextureImporterFormat.ETC2_RGB4,
TextureImporterFormat.ETC2_RGB4_PUNCHTHROUGH_ALPHA,
TextureImporterFormat.ETC2_RGBA8,
TextureImporterFormat.ASTC_4x4,
TextureImporterFormat.ASTC_5x5,
TextureImporterFormat.ASTC_6x6,
TextureImporterFormat.ASTC_8x8,
TextureImporterFormat.ASTC_10x10,
TextureImporterFormat.ASTC_12x12,
TextureImporterFormat.ASTC_HDR_4x4,
TextureImporterFormat.ASTC_HDR_5x5,
TextureImporterFormat.ASTC_HDR_6x6,
TextureImporterFormat.ASTC_HDR_8x8,
TextureImporterFormat.ASTC_HDR_10x10,
TextureImporterFormat.ASTC_HDR_12x12,
TextureImporterFormat.BC6H,
TextureImporterFormat.BC7
};
readonly AnimBool m_ShowBumpGenerationSettings = new AnimBool();
readonly AnimBool m_ShowCubeMapSettings = new AnimBool();
readonly AnimBool m_ShowElementsAtlasSettings = new AnimBool();
readonly AnimBool m_ShowGenericSpriteSettings = new AnimBool();
readonly AnimBool m_ShowMipMapSettings = new AnimBool();
readonly AnimBool m_ShowSpriteMeshTypeOption = new AnimBool();
readonly GUIContent m_EmptyContent = new GUIContent(" ");
readonly int[] m_FilterModeOptions = (int[])(Enum.GetValues(typeof(FilterMode)));
string m_ImportWarning = null;
private void UpdateImportWarning()
{
TextureImporter importer = target as TextureImporter;
m_ImportWarning = importer ? importer.GetImportWarnings() : null;
}
internal class Styles
{
public readonly GUIContent textureTypeTitle = EditorGUIUtility.TrTextContent("Texture Type", "What will this texture be used for?");
public readonly GUIContent[] textureTypeOptions =
{
EditorGUIUtility.TrTextContent("Default", "Texture is a normal image such as a diffuse texture or other."),
EditorGUIUtility.TrTextContent("Normal map", "Texture is a bump or normal map."),
EditorGUIUtility.TrTextContent("Editor GUI and Legacy GUI", "Texture is used for a GUI element."),
EditorGUIUtility.TrTextContent("Sprite (2D and UI)", "Texture is used for a sprite."),
EditorGUIUtility.TrTextContent("Cursor", "Texture is used for a cursor."),
EditorGUIUtility.TrTextContent("Cookie", "Texture is a cookie you put on a light."),
EditorGUIUtility.TrTextContent("Lightmap", "Texture is a lightmap."),
EditorGUIUtility.TrTextContent("Directional Lightmap", "Texture is a directional lightmap."),
EditorGUIUtility.TrTextContent("Shadowmask", "Texture is a shadowmask texture."),
EditorGUIUtility.TrTextContent("Single Channel", "Texture is a one component texture."),
};
public readonly int[] textureTypeValues =
{
(int)TextureImporterType.Default,
(int)TextureImporterType.NormalMap,
(int)TextureImporterType.GUI,
(int)TextureImporterType.Sprite,
(int)TextureImporterType.Cursor,
(int)TextureImporterType.Cookie,
(int)TextureImporterType.Lightmap,
(int)TextureImporterType.DirectionalLightmap,
(int)TextureImporterType.Shadowmask,
(int)TextureImporterType.SingleChannel,
};
public readonly GUIContent textureShape = EditorGUIUtility.TrTextContent("Texture Shape", "What shape is this texture?");
readonly GUIContent textureShape2D = EditorGUIUtility.TrTextContent("2D", "Texture is 2D.");
readonly GUIContent textureShapeCube = EditorGUIUtility.TrTextContent("Cube", "Texture is a Cubemap.");
readonly GUIContent textureShape2DArray = EditorGUIUtility.TrTextContent("2D Array", "Texture is a 2D Array.");
readonly GUIContent textureShape3D = EditorGUIUtility.TrTextContent("3D", "Texture is 3D.");
public readonly Dictionary<TextureImporterShape, GUIContent[]> textureShapeOptionsDictionnary = new Dictionary<TextureImporterShape, GUIContent[]>();
public readonly Dictionary<TextureImporterShape, int[]> textureShapeValuesDictionnary = new Dictionary<TextureImporterShape, int[]>();
public readonly GUIContent defaultPlatform = EditorGUIUtility.TrTextContent("Default");
public readonly GUIContent filterMode = EditorGUIUtility.TrTextContent("Filter Mode");
public readonly GUIContent[] filterModeOptions =
{
EditorGUIUtility.TrTextContent("Point (no filter)"),
EditorGUIUtility.TrTextContent("Bilinear"),
EditorGUIUtility.TrTextContent("Trilinear")
};
public readonly GUIContent cookieType = EditorGUIUtility.TrTextContent("Light Type");
public readonly GUIContent[] cookieOptions =
{
EditorGUIUtility.TrTextContent("Spot Light"),
EditorGUIUtility.TrTextContent("Directional Light"),
EditorGUIUtility.TrTextContent("Point Light"),
};
public readonly GUIContent generateFromBump = EditorGUIUtility.TrTextContent("Create from Grayscale", "The grayscale of the image is used as a heightmap for generating the normal map.");
public readonly GUIContent bumpiness = EditorGUIUtility.TrTextContent("Bumpiness");
public readonly GUIContent bumpFiltering = EditorGUIUtility.TrTextContent("Filtering");
public readonly GUIContent[] bumpFilteringOptions =
{
EditorGUIUtility.TrTextContent("Sharp"),
EditorGUIUtility.TrTextContent("Smooth"),
};
public readonly GUIContent flipGreenChannel = EditorGUIUtility.TrTextContent("Flip Green Channel",
"Invert values in the normal map green (Y) channel. Use on normal maps that were produced for non-Unity normal orientation convention.");
public readonly GUIContent swizzle = EditorGUIUtility.TrTextContent("Swizzle",
"Reorder and invert texture color channels. For each of R,G,B,A channels pick where the channel data comes from.");
public readonly GUIContent cubemap = EditorGUIUtility.TrTextContent("Mapping");
public readonly GUIContent[] cubemapOptions =
{
EditorGUIUtility.TrTextContent("Auto"),
EditorGUIUtility.TrTextContent("6 Frames Layout (Cubic Environment)", "Texture contains 6 images arranged in one of the standard cubemap layouts - cross or sequence (+x, -x, +y, -y, +z, -z). Texture can be in vertical or horizontal orientation."),
EditorGUIUtility.TrTextContent("Latitude-Longitude Layout (Cylindrical)", "Texture contains an image of a ball unwrapped such that latitude and longitude are mapped to horizontal and vertical dimensions (as on a globe)."),
EditorGUIUtility.TrTextContent("Mirrored Ball (Spheremap)", "Texture contains an image of a mirrored ball.")
};
public readonly int[] cubemapValues2 =
{
(int)TextureImporterGenerateCubemap.AutoCubemap,
(int)TextureImporterGenerateCubemap.FullCubemap,
(int)TextureImporterGenerateCubemap.Cylindrical,
(int)TextureImporterGenerateCubemap.Spheremap
};
public readonly GUIContent cubemapConvolution = EditorGUIUtility.TrTextContent("Convolution Type");
public readonly GUIContent[] cubemapConvolutionOptions =
{
EditorGUIUtility.TrTextContent("None"),
EditorGUIUtility.TrTextContent("Specular (Glossy Reflection)", "Convolve cubemap for specular reflections with varying smoothness (Glossy Reflections)."),
EditorGUIUtility.TrTextContent("Diffuse (Irradiance)", "Convolve cubemap for diffuse-only reflection (Irradiance Cubemap).")
};
public readonly int[] cubemapConvolutionValues =
{
(int)TextureImporterCubemapConvolution.None,
(int)TextureImporterCubemapConvolution.Specular,
(int)TextureImporterCubemapConvolution.Diffuse
};
public readonly GUIContent seamlessCubemap = EditorGUIUtility.TrTextContent("Fixup Edge Seams", "Enable if this texture is used for glossy reflections.");
public readonly GUIContent textureFormat = EditorGUIUtility.TrTextContent("Format");
public readonly GUIContent mipmapFadeOutToggle = EditorGUIUtility.TrTextContent("Fadeout to Gray");
public readonly GUIContent mipmapFadeStartMip = EditorGUIUtility.TrTextContent("Fade Start Mip");
public readonly GUIContent mipmapFadeEndMip = EditorGUIUtility.TrTextContent("Fade End Mip");
public readonly GUIContent mipmapFadeOut = EditorGUIUtility.TrTextContent("Fade Range");
public readonly GUIContent readWrite = EditorGUIUtility.TrTextContent("Read/Write", "Enable to be able to access the raw pixel data from code.");
public readonly GUIContent useMipmapLimits = EditorGUIUtility.TrTextContent("Mipmap Limit", "Disable this if the number of mipmap levels to upload should not be limited by the quality settings. (effectively: always upload at full resolution, regardless of the global mipmap limit or mipmap limit groups)");
public readonly GUIContent mipmapLimitGroupName = EditorGUIUtility.TrTextContent("Mipmap Limit Group", "Select a Mipmap Limit Group for this texture. If you do not add this texture to a Mipmap Limit Group, or Unity cannot find the group name you provide, Unity limits the number of mipmap levels it uploads to the maximum defined by the Global Texture Mipmap Limit (see Quality Settings). If Unity can find the Mipmap Limit Group you specify, it respects that group's limit.");
public readonly GUIContent mipmapLimitGroupWarning = EditorGUIUtility.TrTextContent("This texture takes the default mipmap limit settings because Unity cannot find the mipmap limit group you have designated. Consult your project's Quality Settings for a list of mipmap limit groups.");
public readonly GUIContent streamingMipmaps = EditorGUIUtility.TrTextContent("Stream Mipmap Levels", "Only load larger mipmap levels as needed to render the current game cameras. Requires Texture Mipmap Streaming to be enabled in quality settings.");
public readonly GUIContent streamingMipmapsPriority = EditorGUIUtility.TrTextContent("Priority", "Mipmap streaming priority when there's contention for resources. Positive numbers represent higher priority. Valid range is -128 to 127.");
public readonly GUIContent vtOnly = EditorGUIUtility.TrTextContent("Virtual Texture Only", "Texture is optimized for use as a virtual texture and can only be used as a virtual texture.");
public readonly GUIContent alphaSource = EditorGUIUtility.TrTextContent("Alpha Source", "How is the alpha generated for the imported texture.");
public readonly GUIContent[] alphaSourceOptions =
{
EditorGUIUtility.TrTextContent("None", "No Alpha will be used."),
EditorGUIUtility.TrTextContent("Input Texture Alpha", "Use Alpha from the input texture if one is provided."),
EditorGUIUtility.TrTextContent("From Gray Scale", "Generate Alpha from image gray scale."),
};
public readonly int[] alphaSourceValues =
{
(int)TextureImporterAlphaSource.None,
(int)TextureImporterAlphaSource.FromInput,
(int)TextureImporterAlphaSource.FromGrayScale,
};
public readonly GUIContent singleChannelComponent = EditorGUIUtility.TrTextContent("Channel", "As which color/alpha component the single channel texture is treated.");
public readonly GUIContent[] singleChannelComponentOptions =
{
EditorGUIUtility.TrTextContent("Alpha", "Use the alpha channel (compression not supported)."),
EditorGUIUtility.TrTextContent("Red", "Use the red color component."),
};
public readonly int[] singleChannelComponentValues =
{
(int)TextureImporterSingleChannelComponent.Alpha,
(int)TextureImporterSingleChannelComponent.Red,
};
public readonly GUIContent generateMipMaps = EditorGUIUtility.TrTextContent("Generate Mipmap", "Create progressively smaller versions of the texture, for reduced texture shimmering and better GPU performance when the texture is viewed at a distance.");
public readonly GUIContent showMipmapGenerationSettings = EditorGUIUtility.TrTextContent("Generation Settings", "Set up how the mipmap levels are generated from the imported image.");
public readonly GUIContent sRGBTexture = EditorGUIUtility.TrTextContent("sRGB (Color Texture)", "Texture content is stored in gamma space. Non-HDR color textures should enable this flag (except if used for IMGUI).");
public readonly GUIContent sRGBForEtc1Warning = EditorGUIUtility.TrTextContent("Unity does not support importing textures as ETC when that texture is in the sRGB color space and the project is set to use a Linear color space. One or more of the textures you have selected are imported as ETC2 instead.");
public readonly GUIContent borderMipMaps = EditorGUIUtility.TrTextContent("Replicate Border", "Replicate pixel values from texture borders into smaller mipmap levels. Mostly used for Cookie texture types.");
public readonly GUIContent mipMapsPreserveCoverage = EditorGUIUtility.TrTextContent("Preserve Coverage", "The alpha channel of generated mipmaps will preserve coverage for the alpha test. Useful for foliage textures.");
public readonly GUIContent alphaTestReferenceValue = EditorGUIUtility.TrTextContent("Alpha Cutoff", "The reference value used during the alpha test. Controls mipmap coverage.");
public readonly GUIContent mipMapFilter = EditorGUIUtility.TrTextContent("Mipmap Filtering");
public readonly GUIContent[] mipMapFilterOptions =
{
EditorGUIUtility.TrTextContent("Box"),
EditorGUIUtility.TrTextContent("Kaiser"),
};
public readonly GUIContent npot = EditorGUIUtility.TrTextContent("Non-Power of 2", "How non-power-of-two textures are scaled on import.");
public readonly GUIContent generateCubemap = EditorGUIUtility.TrTextContent("Generate Cubemap");
public readonly GUIContent spriteMode = EditorGUIUtility.TrTextContent("Sprite Mode");
public readonly GUIContent[] spriteModeOptions =
{
EditorGUIUtility.TrTextContent("Single"),
EditorGUIUtility.TrTextContent("Multiple"),
EditorGUIUtility.TrTextContent("Polygon"),
};
public readonly GUIContent[] spriteMeshTypeOptions =
{
EditorGUIUtility.TrTextContent("Full Rect"),
EditorGUIUtility.TrTextContent("Tight"),
};
public readonly GUIContent spritePixelsPerUnit = EditorGUIUtility.TrTextContent("Pixels Per Unit", "How many pixels in the sprite correspond to one unit in the world.");
public readonly GUIContent spriteExtrude = EditorGUIUtility.TrTextContent("Extrude Edges", "How much empty area to leave around the sprite in the generated mesh.");
public readonly GUIContent spriteMeshType = EditorGUIUtility.TrTextContent("Mesh Type", "Type of sprite mesh to generate.");
public readonly GUIContent spriteAlignment = EditorGUIUtility.TrTextContent("Pivot", "Sprite pivot point in its localspace. May be used for syncing animation frames of different sizes.");
public readonly GUIContent[] spriteAlignmentOptions =
{
EditorGUIUtility.TrTextContent("Center"),
EditorGUIUtility.TrTextContent("Top Left"),
EditorGUIUtility.TrTextContent("Top"),
EditorGUIUtility.TrTextContent("Top Right"),
EditorGUIUtility.TrTextContent("Left"),
EditorGUIUtility.TrTextContent("Right"),
EditorGUIUtility.TrTextContent("Bottom Left"),
EditorGUIUtility.TrTextContent("Bottom"),
EditorGUIUtility.TrTextContent("Bottom Right"),
EditorGUIUtility.TrTextContent("Custom"),
};
public readonly GUIContent spriteGenerateFallbackPhysicsShape = EditorGUIUtility.TrTextContent("Generate Physics Shape", "Generates a default physics shape from the outline of the Sprite/s when a physics shape has not been set in the Sprite Editor.");
public readonly GUIContent applyAndContinueToSpriteEditor = EditorGUIUtility.TrTextContent("Unapplied import settings for \'{0}\'.\n Apply changes and continue to Sprite Editor Window?");
public readonly GUIContent unappliedImportSettings = EditorGUIUtility.TrTextContent("Unapplied import settings");
public readonly GUIContent yes = EditorGUIUtility.TrTextContent("Yes");
public readonly GUIContent no = EditorGUIUtility.TrTextContent("No");
public readonly GUIContent alphaIsTransparency = EditorGUIUtility.TrTextContent("Alpha Is Transparency", "If the alpha channel of your texture represents transparency, enable this property to dilate the color channels of visible texels into fully transparent areas. This effectively adds padding around transparent areas that prevents filtering artifacts from forming on their edges. Unity does not support this property for HDR textures. \n\nThis property makes the color data of invisible texels undefined. Disable this property to preserve invisible texels' original color data.");
public readonly GUIContent showAdvanced = EditorGUIUtility.TrTextContent("Advanced", "Show advanced settings.");
public readonly GUIContent psdRemoveMatte = EditorGUIUtility.TrTextContent("Remove PSD Matte", "Enable special processing for PSD that has transparency, as color pixels will be tweaked (blended with white color).");
public readonly GUIContent ignorePngGamma = EditorGUIUtility.TrTextContent("Ignore PNG Gamma", "Ignore the Gamma attribute value in PNG files.");
public readonly GUIContent readWriteWarning = EditorGUIUtility.TrTextContent("When you enable Read/Write, Unity stores an additional copy of your textures in CPU-addressable memory. One or more of the textures you have selected use a considerable amount of memory (more than 512MB).");
public readonly GUIContent flipbookColumns = EditorGUIUtility.TrTextContent("Columns", "Source image is divided into this amount of columns.");
public readonly GUIContent flipbookRows = EditorGUIUtility.TrTextContent("Rows", "Source image is divided into this amount of rows.");
public Styles()
{
// This is far from ideal, but it's better than having tons of logic in the GUI code itself.
// The combination should not grow too much.
GUIContent[] s2D_Options = { textureShape2D };
GUIContent[] sCube_Options = { textureShapeCube };
GUIContent[] s2D_Cube_Options = { textureShape2D, textureShapeCube };
GUIContent[] sAll_Options = { textureShape2D, textureShapeCube, textureShape2DArray, textureShape3D };
textureShapeOptionsDictionnary.Add(TextureImporterShape.Texture2D, s2D_Options);
textureShapeOptionsDictionnary.Add(TextureImporterShape.TextureCube, sCube_Options);
textureShapeOptionsDictionnary.Add(TextureImporterShape.Texture2D | TextureImporterShape.TextureCube, s2D_Cube_Options);
textureShapeOptionsDictionnary.Add(TextureImporterShape.Texture2D | TextureImporterShape.TextureCube | TextureImporterShape.Texture2DArray | TextureImporterShape.Texture3D, sAll_Options);
int[] s2D_Values = { (int)TextureImporterShape.Texture2D };
int[] sCube_Values = { (int)TextureImporterShape.TextureCube };
int[] s2D_Cube_Values = { (int)TextureImporterShape.Texture2D, (int)TextureImporterShape.TextureCube };
int[] sAll_Values = { (int)TextureImporterShape.Texture2D, (int)TextureImporterShape.TextureCube, (int)TextureImporterShape.Texture2DArray, (int)TextureImporterShape.Texture3D };
textureShapeValuesDictionnary.Add(TextureImporterShape.Texture2D, s2D_Values);
textureShapeValuesDictionnary.Add(TextureImporterShape.TextureCube, sCube_Values);
textureShapeValuesDictionnary.Add(TextureImporterShape.Texture2D | TextureImporterShape.TextureCube, s2D_Cube_Values);
textureShapeValuesDictionnary.Add(TextureImporterShape.Texture2D | TextureImporterShape.TextureCube | TextureImporterShape.Texture2DArray | TextureImporterShape.Texture3D, sAll_Values);
}
}
internal static Styles s_Styles;
TextureInspectorTypeGUIProperties[] m_TextureTypeGUIElements = new TextureInspectorTypeGUIProperties[Enum.GetValues(typeof(TextureImporterType)).Length];
List<TextureInspectorGUIElement> m_GUIElementsDisplayOrder = new List<TextureInspectorGUIElement>();
void ToggleFromInt(SerializedProperty property, GUIContent label)
{
var content = EditorGUI.BeginProperty(EditorGUILayout.BeginHorizontal(), label, property);
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
int value = EditorGUILayout.Toggle(content, property.intValue > 0) ? 1 : 0;
EditorGUI.showMixedValue = false;
if (EditorGUI.EndChangeCheck())
property.intValue = value;
EditorGUILayout.EndHorizontal();
EditorGUI.EndProperty();
}
void EnumPopup(SerializedProperty property, System.Type type, GUIContent label)
{
EditorGUILayout.IntPopup(property,
EditorGUIUtility.TempContent(System.Enum.GetNames(type)),
System.Enum.GetValues(type) as int[],
label);
}
SerializedProperty m_AlphaSource;
SerializedProperty m_ConvertToNormalMap;
SerializedProperty m_HeightScale;
SerializedProperty m_NormalMapFilter;
SerializedProperty m_FlipGreenChannel;
SerializedProperty m_Swizzle;
SerializedProperty m_GenerateCubemap;
SerializedProperty m_CubemapConvolution;
SerializedProperty m_SeamlessCubemap;
SerializedProperty m_BorderMipMap;
SerializedProperty m_MipMapsPreserveCoverage;
SerializedProperty m_AlphaTestReferenceValue;
SerializedProperty m_NPOTScale;
SerializedProperty m_IsReadable;
SerializedProperty m_StreamingMipmaps;
SerializedProperty m_StreamingMipmapsPriority;
SerializedProperty m_IgnoreMipmapLimit;
SerializedProperty m_MipmapLimitGroupName;
SerializedProperty m_VTOnly;
SerializedProperty m_sRGBTexture;
SerializedProperty m_EnableMipMap;
SerializedProperty m_MipMapMode;
SerializedProperty m_FadeOut;
SerializedProperty m_MipMapFadeDistanceStart;
SerializedProperty m_MipMapFadeDistanceEnd;
SerializedProperty m_Aniso;
SerializedProperty m_FilterMode;
SerializedProperty m_WrapU;
SerializedProperty m_WrapV;
SerializedProperty m_WrapW;
SerializedProperty m_SpritePixelsToUnits;
SerializedProperty m_SpriteExtrude;
SerializedProperty m_SpriteMeshType;
SerializedProperty m_Alignment;
SerializedProperty m_SpritePivot;
SerializedProperty m_SpriteGenerateFallbackPhysicsShape;
SerializedProperty m_AlphaIsTransparency;
SerializedProperty m_IgnorePngGamma;
SerializedProperty m_PSDRemoveMatte;
SerializedProperty m_TextureShape;
SerializedProperty m_SpriteMode;
SerializedProperty m_FlipbookRows;
SerializedProperty m_FlipbookColumns;
SerializedProperty m_SingleChannelComponent;
SerializedProperty m_CookieLightType;
SerializedProperty m_PlatformSettingsArrProp;
List<TextureImporterType> m_TextureTypes;
internal SpriteImportMode spriteImportMode
{
get
{
return (SpriteImportMode)m_SpriteMode.intValue;
}
}
bool m_ShowAdvanced = false;
bool m_ShowMipmapGenerationSettings = true;
int m_TextureWidth = 0;
int m_TextureHeight = 0;
bool m_IsPOT = false;
bool m_IsPNG, m_IsPSD;
void CacheSerializedProperties()
{
m_AlphaSource = serializedObject.FindProperty("m_AlphaUsage");
m_ConvertToNormalMap = serializedObject.FindProperty("m_ConvertToNormalMap");
m_HeightScale = serializedObject.FindProperty("m_HeightScale");
m_NormalMapFilter = serializedObject.FindProperty("m_NormalMapFilter");
m_FlipGreenChannel = serializedObject.FindProperty("m_FlipGreenChannel");
m_Swizzle = serializedObject.FindProperty("m_Swizzle");
m_GenerateCubemap = serializedObject.FindProperty("m_GenerateCubemap");
m_SeamlessCubemap = serializedObject.FindProperty("m_SeamlessCubemap");
m_BorderMipMap = serializedObject.FindProperty("m_BorderMipMap");
m_MipMapsPreserveCoverage = serializedObject.FindProperty("m_MipMapsPreserveCoverage");
m_AlphaTestReferenceValue = serializedObject.FindProperty("m_AlphaTestReferenceValue");
m_NPOTScale = serializedObject.FindProperty("m_NPOTScale");
m_IsReadable = serializedObject.FindProperty("m_IsReadable");
m_StreamingMipmaps = serializedObject.FindProperty("m_StreamingMipmaps");
m_StreamingMipmapsPriority = serializedObject.FindProperty("m_StreamingMipmapsPriority");
m_IgnoreMipmapLimit = serializedObject.FindProperty("m_IgnoreMipmapLimit");
m_MipmapLimitGroupName = serializedObject.FindProperty("m_MipmapLimitGroupName");
m_VTOnly = serializedObject.FindProperty("m_VTOnly");
m_sRGBTexture = serializedObject.FindProperty("m_sRGBTexture");
m_EnableMipMap = serializedObject.FindProperty("m_EnableMipMap");
m_MipMapMode = serializedObject.FindProperty("m_MipMapMode");
m_FadeOut = serializedObject.FindProperty("m_FadeOut");
m_MipMapFadeDistanceStart = serializedObject.FindProperty("m_MipMapFadeDistanceStart");
m_MipMapFadeDistanceEnd = serializedObject.FindProperty("m_MipMapFadeDistanceEnd");
m_Aniso = serializedObject.FindProperty("m_TextureSettings.m_Aniso");
m_FilterMode = serializedObject.FindProperty("m_TextureSettings.m_FilterMode");
m_WrapU = serializedObject.FindProperty("m_TextureSettings.m_WrapU");
m_WrapV = serializedObject.FindProperty("m_TextureSettings.m_WrapV");
m_WrapW = serializedObject.FindProperty("m_TextureSettings.m_WrapW");
m_CubemapConvolution = serializedObject.FindProperty("m_CubemapConvolution");
m_SpriteMode = serializedObject.FindProperty("m_SpriteMode");
m_SpritePixelsToUnits = serializedObject.FindProperty("m_SpritePixelsToUnits");
m_SpriteExtrude = serializedObject.FindProperty("m_SpriteExtrude");
m_SpriteMeshType = serializedObject.FindProperty("m_SpriteMeshType");
m_Alignment = serializedObject.FindProperty("m_Alignment");
m_SpritePivot = serializedObject.FindProperty("m_SpritePivot");
m_SpriteGenerateFallbackPhysicsShape = serializedObject.FindProperty("m_SpriteGenerateFallbackPhysicsShape");
m_AlphaIsTransparency = serializedObject.FindProperty("m_AlphaIsTransparency");
m_IgnorePngGamma = serializedObject.FindProperty("m_IgnorePngGamma");
m_PSDRemoveMatte = serializedObject.FindProperty("m_PSDRemoveMatte");
m_TextureType = serializedObject.FindProperty("m_TextureType");
m_TextureShape = serializedObject.FindProperty("m_TextureShape");
m_SingleChannelComponent = serializedObject.FindProperty("m_SingleChannelComponent");
m_FlipbookRows = serializedObject.FindProperty("m_FlipbookRows");
m_FlipbookColumns = serializedObject.FindProperty("m_FlipbookColumns");
m_CookieLightType = serializedObject.FindProperty("m_CookieLightType");
m_PlatformSettingsArrProp = serializedObject.FindProperty("m_PlatformSettings");
m_TextureTypes = new List<TextureImporterType>();
foreach (var o in targets)
{
var targetObject = (TextureImporter)o;
m_TextureTypes.Add(targetObject.textureType);
}
}
void InitializeGUI()
{
// This is where we decide what GUI elements are displayed depending on the texture type.
// TODO: Maybe complement the bitfield with a list to add a concept of order in the display. Not sure if necessary...
TextureImporterShape shapeCapsAll =
TextureImporterShape.Texture2D |
TextureImporterShape.TextureCube |
TextureImporterShape.Texture2DArray |
TextureImporterShape.Texture3D;
var sharedAdvanced = TextureInspectorGUIElement.PowerOfTwo | TextureInspectorGUIElement.Readable | TextureInspectorGUIElement.MipMaps | TextureInspectorGUIElement.PngGamma | TextureInspectorGUIElement.Swizzle;
m_TextureTypeGUIElements[(int)TextureImporterType.Default] = new TextureInspectorTypeGUIProperties(
TextureInspectorGUIElement.ColorSpace | TextureInspectorGUIElement.AlphaHandling | TextureInspectorGUIElement.CubeMapConvolution | TextureInspectorGUIElement.CubeMapping | TextureInspectorGUIElement.ElementsAtlas,
sharedAdvanced
| TextureInspectorGUIElement.VTOnly
, shapeCapsAll);
m_TextureTypeGUIElements[(int)TextureImporterType.NormalMap] = new TextureInspectorTypeGUIProperties(
TextureInspectorGUIElement.NormalMap | TextureInspectorGUIElement.CubeMapping | TextureInspectorGUIElement.ElementsAtlas,
sharedAdvanced
| TextureInspectorGUIElement.VTOnly
, shapeCapsAll);
m_TextureTypeGUIElements[(int)TextureImporterType.Sprite] = new TextureInspectorTypeGUIProperties(
TextureInspectorGUIElement.Sprite,
TextureInspectorGUIElement.Readable | TextureInspectorGUIElement.AlphaHandling | TextureInspectorGUIElement.MipMaps | TextureInspectorGUIElement.ColorSpace,
TextureImporterShape.Texture2D);
m_TextureTypeGUIElements[(int)TextureImporterType.Cookie] = new TextureInspectorTypeGUIProperties(
TextureInspectorGUIElement.Cookie | TextureInspectorGUIElement.AlphaHandling | TextureInspectorGUIElement.CubeMapping,
sharedAdvanced,
TextureImporterShape.Texture2D | TextureImporterShape.TextureCube);
m_TextureTypeGUIElements[(int)TextureImporterType.SingleChannel] = new TextureInspectorTypeGUIProperties(
TextureInspectorGUIElement.AlphaHandling | TextureInspectorGUIElement.SingleChannelComponent | TextureInspectorGUIElement.CubeMapping | TextureInspectorGUIElement.ElementsAtlas,
sharedAdvanced
, shapeCapsAll);
m_TextureTypeGUIElements[(int)TextureImporterType.GUI] = new TextureInspectorTypeGUIProperties(
0,
TextureInspectorGUIElement.AlphaHandling | sharedAdvanced,
TextureImporterShape.Texture2D);
m_TextureTypeGUIElements[(int)TextureImporterType.Cursor] = new TextureInspectorTypeGUIProperties(
0,
TextureInspectorGUIElement.AlphaHandling | sharedAdvanced,
TextureImporterShape.Texture2D);
m_TextureTypeGUIElements[(int)TextureImporterType.Lightmap] = new TextureInspectorTypeGUIProperties(
0,
sharedAdvanced
, TextureImporterShape.Texture2D);
m_TextureTypeGUIElements[(int)TextureImporterType.DirectionalLightmap] = new TextureInspectorTypeGUIProperties(
0,
sharedAdvanced
, TextureImporterShape.Texture2D);
m_TextureTypeGUIElements[(int)TextureImporterType.Shadowmask] = new TextureInspectorTypeGUIProperties(
0,
sharedAdvanced
, TextureImporterShape.Texture2D);
m_GUIElementMethods.Clear();
m_GUIElementMethods.Add(TextureInspectorGUIElement.PowerOfTwo, this.POTScaleGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.Readable, this.ReadableGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.VTOnly, this.VTOnlyGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.ColorSpace, this.ColorSpaceGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.AlphaHandling, this.AlphaHandlingGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.PngGamma, this.PngGammaGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.MipMaps, this.MipMapGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.NormalMap, this.BumpGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.Sprite, this.SpriteGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.Cookie, this.CookieGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.CubeMapping, this.CubemapMappingGUI);
m_GUIElementMethods.Add(TextureInspectorGUIElement.ElementsAtlas, this.ElementsAtlasGui);
m_GUIElementMethods.Add(TextureInspectorGUIElement.Swizzle, this.SwizzleGui);
// This list dictates the order in which the GUI Elements are displayed.
// It could be different for each TextureImporterType but let's keep it simple for now.
m_GUIElementsDisplayOrder.Clear();
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.ElementsAtlas);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.CubeMapping);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.CubeMapConvolution);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.Cookie);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.ColorSpace);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.AlphaHandling);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.SingleChannelComponent);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.NormalMap);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.Sprite);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.PowerOfTwo);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.Readable);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.VTOnly);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.MipMaps);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.PngGamma);
m_GUIElementsDisplayOrder.Add(TextureInspectorGUIElement.Swizzle);
UnityEngine.Debug.Assert(m_GUIElementsDisplayOrder.Count == (Enum.GetValues(typeof(TextureInspectorGUIElement)).Length - 1), "Some GUIElement are not present in the list."); // -1 because TextureInspectorGUIElement.None
}
public override void OnEnable()
{
base.OnEnable();
s_DefaultPlatformName = TextureImporter.defaultPlatformName; // Can't be called everywhere so we save it here for later use.
m_ShowAdvanced = EditorPrefs.GetBool("TextureImporterShowAdvanced", m_ShowAdvanced);
m_ShowMipmapGenerationSettings = EditorPrefs.GetBool("TextureImporterShowMipmapGenerationSettings", m_ShowMipmapGenerationSettings);
CacheSerializedProperties();
BuildTargetList();
m_ShowBumpGenerationSettings.valueChanged.AddListener(Repaint);
m_ShowBumpGenerationSettings.value = m_ConvertToNormalMap.intValue > 0;
m_ShowCubeMapSettings.valueChanged.AddListener(Repaint);
m_ShowCubeMapSettings.value = (TextureImporterShape)m_TextureShape.intValue == TextureImporterShape.TextureCube;
m_ShowElementsAtlasSettings.valueChanged.AddListener(Repaint);
m_ShowElementsAtlasSettings.value = (TextureImporterShape)m_TextureShape.intValue == TextureImporterShape.Texture2DArray || (TextureImporterShape)m_TextureShape.intValue == TextureImporterShape.Texture3D;
//@TODO change to use spriteMode enum when available
m_ShowGenericSpriteSettings.valueChanged.AddListener(Repaint);
m_ShowGenericSpriteSettings.value = m_SpriteMode.intValue != 0;
m_ShowSpriteMeshTypeOption.valueChanged.AddListener(Repaint);
m_ShowSpriteMeshTypeOption.value = ShouldShowSpriteMeshTypeOption();
m_ShowMipMapSettings.valueChanged.AddListener(Repaint);
m_ShowMipMapSettings.value = m_EnableMipMap.boolValue && (TextureImporterShape)m_TextureShape.intValue != TextureImporterShape.Texture3D;
InitializeGUI();
var importer = target as TextureImporter;
if (importer == null)
return;
importer.GetWidthAndHeight(ref m_TextureWidth, ref m_TextureHeight);
m_IsPOT = IsPowerOfTwo(m_TextureWidth) && IsPowerOfTwo(m_TextureHeight);
var ext = FileUtil.GetPathExtension(importer.assetPath).ToLowerInvariant();
m_IsPSD = ext == "psd";
m_IsPNG = ext == "png";
}
void SetSerializedPropertySettings(TextureImporterSettings settings)
{
m_AlphaSource.intValue = (int)settings.alphaSource;
m_ConvertToNormalMap.intValue = settings.convertToNormalMap ? 1 : 0;
m_HeightScale.floatValue = settings.heightmapScale;
m_NormalMapFilter.intValue = (int)settings.normalMapFilter;
m_FlipGreenChannel.intValue = settings.flipGreenChannel ? 1 : 0;
m_Swizzle.uintValue = settings.swizzleRaw;
m_GenerateCubemap.intValue = (int)settings.generateCubemap;
m_CubemapConvolution.intValue = (int)settings.cubemapConvolution;
m_SeamlessCubemap.intValue = settings.seamlessCubemap ? 1 : 0;
m_BorderMipMap.intValue = settings.borderMipmap ? 1 : 0;
m_MipMapsPreserveCoverage.intValue = settings.mipMapsPreserveCoverage ? 1 : 0;
m_AlphaTestReferenceValue.floatValue = settings.alphaTestReferenceValue;
m_NPOTScale.intValue = (int)settings.npotScale;
m_IsReadable.intValue = settings.readable ? 1 : 0;
m_StreamingMipmaps.intValue = settings.streamingMipmaps ? 1 : 0;
m_StreamingMipmapsPriority.intValue = settings.streamingMipmapsPriority;
m_IgnoreMipmapLimit.intValue = settings.ignoreMipmapLimit ? 1 : 0;
m_VTOnly.intValue = settings.vtOnly ? 1 : 0;
m_EnableMipMap.intValue = settings.mipmapEnabled ? 1 : 0;
m_sRGBTexture.intValue = settings.sRGBTexture ? 1 : 0;
m_MipMapMode.intValue = (int)settings.mipmapFilter;
m_FadeOut.intValue = settings.fadeOut ? 1 : 0;
m_MipMapFadeDistanceStart.intValue = settings.mipmapFadeDistanceStart;
m_MipMapFadeDistanceEnd.intValue = settings.mipmapFadeDistanceEnd;
m_SpriteMode.intValue = settings.spriteMode;
m_SpritePixelsToUnits.floatValue = settings.spritePixelsPerUnit;
m_SpriteExtrude.intValue = (int)settings.spriteExtrude;
m_SpriteMeshType.intValue = (int)settings.spriteMeshType;
m_Alignment.intValue = settings.spriteAlignment;
m_SpriteGenerateFallbackPhysicsShape.intValue = settings.spriteGenerateFallbackPhysicsShape ? 1 : 0;
m_WrapU.intValue = (int)settings.wrapMode;
m_WrapV.intValue = (int)settings.wrapMode;
m_FilterMode.intValue = (int)settings.filterMode;
m_Aniso.intValue = settings.aniso;
m_AlphaIsTransparency.intValue = settings.alphaIsTransparency ? 1 : 0;
m_IgnorePngGamma.intValue = settings.ignorePngGamma ? 1 : 0;
m_TextureType.intValue = (int)settings.textureType;
m_TextureShape.intValue = (int)settings.textureShape;
m_SingleChannelComponent.intValue = (int)settings.singleChannelComponent;
m_FlipbookRows.intValue = settings.flipbookRows;
m_FlipbookColumns.intValue = settings.flipbookColumns;
}
internal TextureImporterSettings GetSerializedPropertySettings()
{
return GetSerializedPropertySettings(new TextureImporterSettings());
}
internal TextureImporterSettings GetSerializedPropertySettings(TextureImporterSettings settings)
{
if (!m_AlphaSource.hasMultipleDifferentValues)
settings.alphaSource = (TextureImporterAlphaSource)m_AlphaSource.intValue;
if (!m_ConvertToNormalMap.hasMultipleDifferentValues)
settings.convertToNormalMap = m_ConvertToNormalMap.intValue > 0;
if (!m_HeightScale.hasMultipleDifferentValues)
settings.heightmapScale = m_HeightScale.floatValue;
if (!m_NormalMapFilter.hasMultipleDifferentValues)
settings.normalMapFilter = (TextureImporterNormalFilter)m_NormalMapFilter.intValue;
if (!m_FlipGreenChannel.hasMultipleDifferentValues)
settings.flipGreenChannel = m_FlipGreenChannel.intValue > 0;
if (!m_Swizzle.hasMultipleDifferentValues)
settings.swizzleRaw = m_Swizzle.uintValue;
if (!m_GenerateCubemap.hasMultipleDifferentValues)
settings.generateCubemap = (TextureImporterGenerateCubemap)m_GenerateCubemap.intValue;
if (!m_CubemapConvolution.hasMultipleDifferentValues)
settings.cubemapConvolution = (TextureImporterCubemapConvolution)m_CubemapConvolution.intValue;
if (!m_SeamlessCubemap.hasMultipleDifferentValues)
settings.seamlessCubemap = m_SeamlessCubemap.intValue > 0;
if (!m_BorderMipMap.hasMultipleDifferentValues)
settings.borderMipmap = m_BorderMipMap.intValue > 0;
if (!m_MipMapsPreserveCoverage.hasMultipleDifferentValues)
settings.mipMapsPreserveCoverage = m_MipMapsPreserveCoverage.intValue > 0;
if (!m_AlphaTestReferenceValue.hasMultipleDifferentValues)
settings.alphaTestReferenceValue = m_AlphaTestReferenceValue.floatValue;
if (!m_NPOTScale.hasMultipleDifferentValues)
settings.npotScale = (TextureImporterNPOTScale)m_NPOTScale.intValue;
if (!m_IsReadable.hasMultipleDifferentValues)
settings.readable = m_IsReadable.intValue > 0;
if (!m_StreamingMipmaps.hasMultipleDifferentValues)
settings.streamingMipmaps = m_StreamingMipmaps.intValue > 0;
if (!m_StreamingMipmapsPriority.hasMultipleDifferentValues)
settings.streamingMipmapsPriority = m_StreamingMipmapsPriority.intValue;
if (!m_IgnoreMipmapLimit.hasMultipleDifferentValues)
settings.ignoreMipmapLimit = m_IgnoreMipmapLimit.intValue > 0;
if (!m_VTOnly.hasMultipleDifferentValues)
settings.vtOnly = m_VTOnly.intValue > 0;
if (!m_sRGBTexture.hasMultipleDifferentValues)
settings.sRGBTexture = m_sRGBTexture.intValue > 0;
if (!m_EnableMipMap.hasMultipleDifferentValues)
settings.mipmapEnabled = m_EnableMipMap.intValue > 0;
if (!m_MipMapMode.hasMultipleDifferentValues)
settings.mipmapFilter = (TextureImporterMipFilter)m_MipMapMode.intValue;
if (!m_FadeOut.hasMultipleDifferentValues)
settings.fadeOut = m_FadeOut.intValue > 0;
if (!m_MipMapFadeDistanceStart.hasMultipleDifferentValues)
settings.mipmapFadeDistanceStart = m_MipMapFadeDistanceStart.intValue;
if (!m_MipMapFadeDistanceEnd.hasMultipleDifferentValues)
settings.mipmapFadeDistanceEnd = m_MipMapFadeDistanceEnd.intValue;
if (!m_SpriteMode.hasMultipleDifferentValues)
settings.spriteMode = m_SpriteMode.intValue;
if (!m_SpritePixelsToUnits.hasMultipleDifferentValues)
settings.spritePixelsPerUnit = m_SpritePixelsToUnits.floatValue;
if (!m_SpriteExtrude.hasMultipleDifferentValues)
settings.spriteExtrude = (uint)m_SpriteExtrude.intValue;
if (!m_SpriteMeshType.hasMultipleDifferentValues)
settings.spriteMeshType = (SpriteMeshType)m_SpriteMeshType.intValue;
if (!m_Alignment.hasMultipleDifferentValues)
settings.spriteAlignment = m_Alignment.intValue;
if (!m_SpritePivot.hasMultipleDifferentValues)
settings.spritePivot = m_SpritePivot.vector2Value;
if (!m_SpriteGenerateFallbackPhysicsShape.hasMultipleDifferentValues)
settings.spriteGenerateFallbackPhysicsShape = m_SpriteGenerateFallbackPhysicsShape.intValue > 0;
if (!m_WrapU.hasMultipleDifferentValues)
settings.wrapModeU = (TextureWrapMode)m_WrapU.intValue;
if (!m_WrapV.hasMultipleDifferentValues)
settings.wrapModeU = (TextureWrapMode)m_WrapV.intValue;
if (!m_WrapW.hasMultipleDifferentValues)
settings.wrapModeU = (TextureWrapMode)m_WrapW.intValue;
if (!m_FilterMode.hasMultipleDifferentValues)
settings.filterMode = (FilterMode)m_FilterMode.intValue;
if (!m_Aniso.hasMultipleDifferentValues)
settings.aniso = m_Aniso.intValue;
if (!m_AlphaIsTransparency.hasMultipleDifferentValues)
settings.alphaIsTransparency = m_AlphaIsTransparency.intValue > 0;
if (!m_TextureType.hasMultipleDifferentValues)
settings.textureType = (TextureImporterType)m_TextureType.intValue;
if (!m_TextureShape.hasMultipleDifferentValues)
settings.textureShape = (TextureImporterShape)m_TextureShape.intValue;
if (!m_SingleChannelComponent.hasMultipleDifferentValues)
settings.singleChannelComponent = (TextureImporterSingleChannelComponent)m_SingleChannelComponent.intValue;
if (!m_IgnorePngGamma.hasMultipleDifferentValues)
settings.ignorePngGamma = m_IgnorePngGamma.intValue > 0;
if (!m_FlipbookRows.hasMultipleDifferentValues)
settings.flipbookRows = m_FlipbookRows.intValue;
if (!m_FlipbookColumns.hasMultipleDifferentValues)
settings.flipbookColumns = m_FlipbookColumns.intValue;
return settings;
}
void CookieGUI(TextureInspectorGUIElement guiElements)
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.Popup(m_CookieLightType, s_Styles.cookieOptions, s_Styles.cookieType);
if (EditorGUI.EndChangeCheck())
SetCookieLightTypeDefaults((TextureImporterCookieLightType)m_CookieLightType.intValue);
}
void CubemapMappingGUI(TextureInspectorGUIElement guiElements)
{
m_ShowCubeMapSettings.target = (TextureImporterShape)m_TextureShape.intValue == TextureImporterShape.TextureCube;
if (EditorGUILayout.BeginFadeGroup(m_ShowCubeMapSettings.faded))
{
if ((TextureImporterShape)m_TextureShape.intValue == TextureImporterShape.TextureCube)
{
Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUI.kSingleLineHeight, EditorStyles.popup);
GUIContent label = EditorGUI.BeginProperty(controlRect, s_Styles.cubemap, m_GenerateCubemap);
EditorGUI.showMixedValue = m_GenerateCubemap.hasMultipleDifferentValues || m_SeamlessCubemap.hasMultipleDifferentValues;
EditorGUI.BeginChangeCheck();
int value = EditorGUI.IntPopup(controlRect, label, m_GenerateCubemap.intValue, s_Styles.cubemapOptions, s_Styles.cubemapValues2);
if (EditorGUI.EndChangeCheck())
m_GenerateCubemap.intValue = value;
EditorGUI.EndProperty();
EditorGUI.indentLevel++;
// Convolution
if (ShouldDisplayGUIElement(guiElements, TextureInspectorGUIElement.CubeMapConvolution))
{
EditorGUILayout.IntPopup(m_CubemapConvolution,
s_Styles.cubemapConvolutionOptions,
s_Styles.cubemapConvolutionValues,
s_Styles.cubemapConvolution);
}
ToggleFromInt(m_SeamlessCubemap, s_Styles.seamlessCubemap);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
}
EditorGUILayout.EndFadeGroup();
}
void ElementsAtlasGui(TextureInspectorGUIElement guiElements)
{
var shape = (TextureImporterShape)m_TextureShape.intValue;
var isLayerShape = shape == TextureImporterShape.Texture2DArray || shape == TextureImporterShape.Texture3D;
m_ShowElementsAtlasSettings.target = isLayerShape;
if (EditorGUILayout.BeginFadeGroup(m_ShowElementsAtlasSettings.faded) && isLayerShape)
{
var isEditorTargetPreset = Presets.Preset.IsEditorTargetAPreset(target);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_FlipbookColumns, s_Styles.flipbookColumns);
if (EditorGUI.EndChangeCheck())
{
var val = m_FlipbookColumns.intValue;
// It happens when we are directly changing a TextureImporter preset and not an ImportSettings (targetting a 2D texture).
// We don't wanna clamp the value to 'm_TextureWidth', or it will always be set to -1 since there's no texture targeted.
val = Mathf.Clamp(val, 1, !isEditorTargetPreset ? m_TextureWidth : val);
m_FlipbookColumns.intValue = val;
}
if (!isEditorTargetPreset && m_TextureWidth % m_FlipbookColumns.intValue != 0)
EditorGUILayout.HelpBox($"Image width {m_TextureWidth} does not divide into {m_FlipbookColumns.intValue} columns exactly", MessageType.Warning, true);
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_FlipbookRows, s_Styles.flipbookRows);
if (EditorGUI.EndChangeCheck())
{
var val = m_FlipbookRows.intValue;
// It happens when we are directly changing a TextureImporter preset and not an ImportSettings (targetting a 2D texture).
// We don't wanna clamp the value to 'm_TextureHeight', or it will always be set to -1 since there's no texture targeted.
val = Mathf.Clamp(val, 1, !isEditorTargetPreset ? m_TextureHeight : val);
m_FlipbookRows.intValue = val;
}
if (!isEditorTargetPreset && m_TextureHeight % m_FlipbookRows.intValue != 0)
EditorGUILayout.HelpBox($"Image height {m_TextureHeight} does not divide into {m_FlipbookRows.intValue} rows exactly", MessageType.Warning, true);
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFadeGroup();
}
bool ShouldDisplaySRGBForEtc1Warning()
{
if (PlayerSettings.colorSpace == ColorSpace.Gamma)
{
return false;
}
BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget;
string platformName = BuildPipeline.GetBuildTargetName(buildTarget);
for (int i = 0; i < targets.Length; i++)
{
TextureImporter t = (TextureImporter)targets[i];
if (!t.sRGBTexture)
{
continue;
}
TextureImporterPlatformSettings settings = t.GetPlatformTextureSettings(platformName);
if (!settings.overridden)
{
settings = t.GetDefaultPlatformTextureSettings();
platformName = settings.name;
}
TextureImporterFormat textureImporterFormat = t.GetPlatformTextureSettings(platformName).format;
TextureFormat textureFormat;
// If Automatic+Compressed is used, we cannot determine if ETC1 -> ETC2 conversion occurred using only the Texture / TexImporter.
// Instead, let's check PlayerSettings / BuildSettings.