Skip to content

Commit f5e9c23

Browse files
committed
Quick refactor and cleanup
1 parent 92a098a commit f5e9c23

File tree

3 files changed

+47
-109
lines changed

3 files changed

+47
-109
lines changed

Runtime/Editor/QoiImporter.Editor.cs

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,48 @@
33
using UnityEditor.AssetImporters;
44
using static UnityEditor.EditorGUILayout;
55

6+
/// <summary>
7+
/// Qoi Importer Editor
8+
/// </summary>
69
[CustomEditor(typeof(QoiImporter))]
710
public class QoiImporterEditor: ScriptedImporterEditor
811
{
9-
SerializedProperty _greyscaleToAlpha;
12+
// SerializedProperty _greyscaleToAlpha;
1013
SerializedProperty _alphaIsTransparency;
1114
SerializedProperty _mipMapEnabled;
1215
SerializedProperty _npotScale;
1316
SerializedProperty _sRGBTexture;
14-
// SerializedProperty _textureFormat;
15-
SerializedProperty _compressionQuality;
16-
SerializedProperty _crunchedCompressionQuality;
17-
SerializedProperty _crunchedCompression;
17+
1818
SerializedProperty _textureType;
19-
// SerializedProperty _linearTexture;
20-
// SerializedProperty _textureShape;
19+
// SerializedProperty _linearTexture; // Unused ?
2120
SerializedProperty _wrapMode;
2221
SerializedProperty _filterMode;
2322
SerializedProperty _anisoLevel;
2423
SerializedProperty _maxTextureSize;
25-
SerializedProperty _dimension;
26-
27-
// public bool grayscaleToAlpha;
28-
// public bool alphaIsTransparency;
29-
// // public TextureImporterMipFilter mipmapFilter;
30-
// // public int mipMapBias = 0;
31-
// public bool mipMapEnabled = true;
32-
// public TextureImporterNPOTScale npotScale = TextureImporterNPOTScale.None;
33-
// // public bool isReadable;
34-
// // public bool streamingMipmaps = true;
35-
// // public int streamingMipmapsPriority = 0;
36-
// public bool sRGBTexture = true;
37-
// public TextureFormat textureFormat = TextureFormat.DXT5;
38-
// public TextureCompressionQuality compressionQuality;
39-
// public TextureCompressionQuality crunchedCompressionQuality = TextureCompressionQuality.Best;
40-
// public bool crunchedCompression = false;
41-
// public TextureImporterType textureType = TextureImporterType.Default;
42-
// public bool linearTexture = false;
43-
// public TextureImporterShape textureShape;
44-
// public TextureWrapMode wrapMode;
45-
// public FilterMode filterMode;
46-
// public int anisoLevel = 1;
47-
// public int maxTextureSize = 2048;
48-
// public TextureDimension dimension = TextureDimension.Tex2D;
24+
25+
// Compression
26+
SerializedProperty _compressionQuality;
27+
SerializedProperty _crunchedCompression;
4928

5029
private void Initialize()
5130
{
52-
_greyscaleToAlpha = Find("grayscaleToAlpha");
31+
_textureType = Find("textureType");
32+
// _greyscaleToAlpha = Find("grayscaleToAlpha");
5333
_alphaIsTransparency = Find("alphaIsTransparency");
5434
_mipMapEnabled = Find("mipMapEnabled");
5535
_npotScale = Find("npotScale");
5636
_sRGBTexture = Find("sRGBTexture");
57-
// _textureFormat = Find("textureFormat");
58-
_compressionQuality = Find("compressionQuality");
59-
// _crunchedCompressionQuality = Find("crunchedCompressionQuality");
60-
_crunchedCompression = Find("crunchedCompression");
61-
_textureType = Find("textureType");
6237
// _linearTexture = Find("linearTexture");
63-
// _textureShape = Find("textureShape");
38+
6439
_wrapMode = Find("wrapMode");
6540
_filterMode = Find("filterMode");
6641
_anisoLevel = Find("anisoLevel");
6742
_maxTextureSize = Find("maxTextureSize");
68-
// _dimension = Find("dimension");
43+
44+
_compressionQuality = Find("compressionQuality");
45+
_crunchedCompression = Find("crunchedCompression");
46+
47+
6948
}
7049

7150
public override void OnInspectorGUI()
@@ -75,26 +54,26 @@ public override void OnInspectorGUI()
7554
PropertyField(_textureType, new GUIContent("Texture Type"));
7655
// PropertyField(_linearTexture, new GUIContent("Linear Texture"));
7756

78-
GUILayout.Space(20);
79-
PropertyField(_greyscaleToAlpha, new GUIContent("Grayscale to Alpha"));
57+
58+
// PropertyField(_greyscaleToAlpha, new GUIContent("Grayscale to Alpha"));
8059
PropertyField(_alphaIsTransparency, new GUIContent("Alpha is Transparency"));
8160
PropertyField(_mipMapEnabled, new GUIContent("Enable MipMaps"));
82-
PropertyField(_npotScale, new GUIContent("NPOT Scale"));
83-
PropertyField(_sRGBTexture, new GUIContent("sRGB Texture"));
84-
// PropertyField(_textureFormat, new GUIContent("Texture Format"));
85-
61+
PropertyField(_npotScale, new GUIContent("NPOT Scaling", "Non Power of Two Scaling"));
62+
PropertyField(_sRGBTexture, new GUIContent("sRGB", "sRGB Texture"));
63+
8664

65+
GUILayout.Space(20);
8766
// PropertyField(_textureShape, new GUIContent("Texture Shape"));
8867
PropertyField(_wrapMode, new GUIContent("Wrap Mode"));
8968
PropertyField(_filterMode, new GUIContent("Filter Mode"));
9069
PropertyField(_anisoLevel, new GUIContent("Aniso Level"));
91-
PropertyField(_maxTextureSize, new GUIContent("Max Texture Size"));
92-
// PropertyField(_dimension, new GUIContent("Dimension"));
70+
PropertyField(_maxTextureSize, new GUIContent("Max Size"));
71+
9372

9473
// [Header("CompressionLevel")]
9574
GUILayout.Space(20);
9675
GUILayout.Label("Compression", EditorStyles.boldLabel);
97-
PropertyField(_compressionQuality, new GUIContent("Compression Quality"));
76+
PropertyField(_compressionQuality, new GUIContent("Quality"));
9877
// PropertyField(_crunchedCompressionQuality, new GUIContent("Crunched Compression Quality"));
9978
PropertyField(_crunchedCompression, new GUIContent("Crunch"));
10079
// HasModified();

Runtime/QoiImporter.cs

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,37 @@
66
using static ImageProcessing;
77
using static UnityEditor.EditorUtility;
88
using static UnityEngine.TextureFormat;
9-
// using static MipGenerator; // Todo: Remove this
10-
119

10+
/// <summary>
11+
/// Qoi Importer
12+
/// </summary>
1213
[ScriptedImporter(1, "qoi")]
1314
public class QoiImporter : ScriptedImporter
1415
{
1516
// Texture import settings
1617
public TextureImporterType textureType = TextureImporterType.Default;
1718

1819
// Todo: Implement grayscaleToAlpha
19-
public bool grayscaleToAlpha;
20+
// public bool grayscaleToAlpha;
2021
public bool alphaIsTransparency;
2122
public bool mipMapEnabled = true;
2223
//Todo: Implement npotScale clamping
2324
public TextureImporterNPOTScale npotScale = TextureImporterNPOTScale.None;
2425
public bool sRGBTexture = true;
25-
public bool linearTexture = false;
26+
// public bool linearTexture = false;
2627

2728

2829
public TextureWrapMode wrapMode = TextureWrapMode.Repeat;
2930
public FilterMode filterMode = FilterMode.Trilinear;
30-
public int anisoLevel = 2048;
31+
[Range(0,16)]
32+
public int anisoLevel = 1;
3133

3234
// Size and compression
3335
public MaxTextureSize maxTextureSize = MaxTextureSize.x2048;
3436
public TextureCompressionQuality compressionQuality;
35-
// public TextureCompressionQuality crunchedCompressionQuality = TextureCompressionQuality.Best;
3637
public bool crunchedCompression = false;
3738

38-
// ¨rivate Fields
39-
// private TextureImporterShape textureShape = TextureImporterShape.Texture2D;
40-
// private TextureDimension dimension = TextureDimension.Tex2D;
39+
// Private Fields
4140
private TextureFormat textureFormat = DXT5;
4241

4342
public override void OnImportAsset(AssetImportContext ctx)
@@ -85,44 +84,4 @@ public override void OnImportAsset(AssetImportContext ctx)
8584
ctx.AddObjectToAsset(tex.name, tex, tex);
8685
ctx.SetMainObject(tex);
8786
}
88-
89-
// private static string GetName(string path)
90-
// {
91-
// int slashIdx = path.LastIndexOf('/');
92-
// if (slashIdx < 0) slashIdx = 0;
93-
// int dotIdx = path.LastIndexOf('.');
94-
// // Debug.Assert(dotIdx >= 0);
95-
// return path.Substring(slashIdx, dotIdx - slashIdx);
96-
// }
97-
}
98-
99-
// public class QOIImageImporter : ScriptedImporter
100-
// {
101-
// public int mipmapLevels = 3;
102-
// public TextureWrapMode wrapMode = TextureWrapMode.Repeat;
103-
// public FilterMode filterMode = FilterMode.Bilinear;
104-
// public int anisoLevel = 1;
105-
// public TextureImporterType textureType;
106-
// public bool mipmapEnabled;
107-
// public TextureCompressionQuality CompressionQuality = TextureCompressionQuality.Best;
108-
// private TextureFormat textureFormat = DXT1Crunched;
109-
//
110-
// public override void OnImportAsset(AssetImportContext ctx)
111-
// {
112-
// // Load the texture data from the file
113-
// byte[] data = File.ReadAllBytes(ctx.assetPath);
114-
// Texture2D texture = new Texture2D(2, 2);
115-
// texture.LoadImage(data);
116-
//
117-
// // Set the texture import settings
118-
// this.textureType = TextureImporterType.Default;
119-
// this.mipmapEnabled = true;
120-
// this.wrapMode = wrapMode;
121-
// this.filterMode = filterMode;
122-
// this.anisoLevel = anisoLevel;
123-
//
124-
// // Apply the texture to the asset
125-
// ctx.AddObjectToAsset("QOI Image", texture);
126-
// ctx.SetMainObject(texture);
127-
// }
128-
// }
87+
}

Runtime/Utility/ImageProcessing.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ public static Texture2D ToTexture2D(this RenderTexture renderTexture)
175175
[Serializable]
176176
public enum MaxTextureSize
177177
{
178-
x16 = 16,
179-
x32 = 32,
180-
x64 = 64,
181-
x128 = 128,
182-
x256 = 256,
183-
x512 = 512,
184-
x1024 = 1024,
185-
x2048 = 2048,
186-
x4096 = 4096,
187-
x8192 = 8192,
188-
x16384 = 16384
178+
[Description("16")] x16 = 16,
179+
[Description("32")] x32 = 32,
180+
[Description("64")] x64 = 64,
181+
[Description("128")] x128 = 128,
182+
[Description("256")] x256 = 256,
183+
[Description("512")] x512 = 512,
184+
[Description("1024")] x1024 = 1024,
185+
[Description("2048")] x2048 = 2048,
186+
[Description("4096")] x4096 = 4096,
187+
[Description("8192")] x8192 = 8192,
188+
[Description("16384")] x16384 = 16384
189189
}
190190

191191
}

0 commit comments

Comments
 (0)