Skip to content

Commit 5d19f52

Browse files
committed
replaced string.Format with C# 6 string interpolation, because it provides a more readable, convenient syntax to format strings. See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated for more details on string interpolation.
1 parent 136e5e5 commit 5d19f52

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

Editor/Texture2DArrayImporter.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
2-
// Texture2D Array Importer for Unity. Copyright (c) 2019-2021 Peter Schraut (www.console-dev.de). See LICENSE.md
2+
// Texture2D Array Importer for Unity. Copyright (c) 2019-2022 Peter Schraut (www.console-dev.de). See LICENSE.md
33
// https://github.com/pschraut/UnityTexture2DArrayImportPipeline
44
//
5-
#pragma warning disable IDE1006, IDE0017
5+
#pragma warning disable IDE1006, IDE0017, IDE0090
66
using UnityEngine;
77
using UnityEditor;
88
using System.IO;
@@ -69,10 +69,10 @@ public Texture2D[] textures
6969
for (var n=0; n< value.Length; ++n)
7070
{
7171
if (value[n] == null)
72-
throw new System.NotSupportedException(string.Format("The texture at array index '{0}' must not be 'null'.", n));
72+
throw new System.NotSupportedException($"The texture at array index '{n}' must not be 'null'.");
7373

7474
if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(value[n])))
75-
throw new System.NotSupportedException(string.Format("The texture '{1}' at array index '{0}' does not exist on disk. Only texture assets can be added.", n, value[n].name));
75+
throw new System.NotSupportedException($"The texture '{value[n].name}' at array index '{n}' does not exist on disk. Only texture assets can be added.");
7676
}
7777

7878
m_Textures = new List<Texture2D>(value);
@@ -239,7 +239,7 @@ bool Verify(AssetImportContext ctx, bool logToConsole)
239239
if (!SystemInfo.supports2DArrayTextures)
240240
{
241241
if (logToConsole)
242-
ctx.LogImportError(string.Format("Import failed '{0}'. Your system does not support texture arrays.", ctx.assetPath), ctx.mainObject);
242+
ctx.LogImportError($"Import failed '{ctx.assetPath}'. Your system does not support texture arrays.", ctx.mainObject);
243243

244244
return false;
245245
}
@@ -249,7 +249,7 @@ bool Verify(AssetImportContext ctx, bool logToConsole)
249249
if (m_Textures[0] == null)
250250
{
251251
if (logToConsole)
252-
ctx.LogImportError(string.Format("Import failed '{0}'. The first element in the 'Textures' list must not be 'None'.", ctx.assetPath), ctx.mainObject);
252+
ctx.LogImportError($"Import failed '{ctx.assetPath}'. The first element in the 'Textures' list must not be 'None'.", ctx.mainObject);
253253

254254
return false;
255255
}
@@ -267,7 +267,7 @@ bool Verify(AssetImportContext ctx, bool logToConsole)
267267
var error = GetVerifyString(n);
268268
if (!string.IsNullOrEmpty(error))
269269
{
270-
var msg = string.Format("Import failed '{0}'. {1}", ctx.assetPath, error);
270+
var msg = $"Import failed '{ctx.assetPath}'. {error}";
271271
ctx.LogImportError(msg, ctx.mainObject);
272272
}
273273
}
@@ -341,34 +341,31 @@ public string GetVerifyString(int slice)
341341

342342
case VerifyResult.Null:
343343
{
344-
return string.Format("The texture for slice {0} must not be 'None'.", slice);
344+
return $"The texture for slice {slice} must not be 'None'.";
345345
}
346346

347347
case VerifyResult.FormatMismatch:
348348
{
349349
var master = m_Textures[0];
350350
var texture = m_Textures[slice];
351351

352-
return string.Format("Texture '{0}' uses '{1}' as format, but must be using '{2}' instead, because the texture for slice 0 '{3}' is using '{2}' too.",
353-
texture.name, texture.format, master.format, master.name);
352+
return $"Texture '{texture.name}' uses '{texture.format}' as format, but must be using '{master.format}' instead, because the texture for slice 0 '{master.name}' is using '{master.format}' too.";
354353
}
355354

356355
case VerifyResult.MipmapMismatch:
357356
{
358357
var master = m_Textures[0];
359358
var texture = m_Textures[slice];
360359

361-
return string.Format("Texture '{0}' has '{1}' mipmap(s), but must have '{2}' instead, because the texture for slice 0 '{3}' is having '{2}' mipmap(s). Please check if the 'Generate Mip Maps' setting for both textures is the same.",
362-
texture.name, texture.mipmapCount, master.mipmapCount, master.name);
360+
return $"Texture '{texture.name}' has '{texture.mipmapCount}' mipmap(s), but must have '{master.mipmapCount}' instead, because the texture for slice 0 '{master.name}' is having '{master.mipmapCount}' mipmap(s). Please check if the 'Generate Mip Maps' setting for both textures is the same.";
363361
}
364362

365363
case VerifyResult.SRGBTextureMismatch:
366364
{
367365
var master = m_Textures[0];
368366
var texture = m_Textures[slice];
369367

370-
return string.Format("Texture '{0}' uses different 'sRGB' setting than slice 0 texture '{1}'.",
371-
texture.name, master.name);
368+
return $"Texture '{texture.name}' uses different 'sRGB' setting than slice 0 texture '{master.name}'.";
372369
}
373370

374371
case VerifyResult.WidthMismatch:
@@ -377,17 +374,15 @@ public string GetVerifyString(int slice)
377374
var master = m_Textures[0];
378375
var texture = m_Textures[slice];
379376

380-
return string.Format("Texture '{0}' is {1}x{2} in size, but must be using the same size as the texture for slice 0 '{3}', which is {4}x{5}.",
381-
texture.name, texture.width, texture.height, master.name, master.width, master.height);
377+
return $"Texture '{texture.name}' is {texture.width}x{texture.height} in size, but must be using the same size as the texture for slice 0 '{master.name}', which is {master.width}x{master.height}.";
382378
}
383379

384380
case VerifyResult.MasterNotAnAsset:
385381
case VerifyResult.NotAnAsset:
386382
{
387383
var texture = m_Textures[slice];
388384

389-
return string.Format("Texture '{0}' is not saved to disk. Only texture assets that exist on disk can be added to a Texture2DArray asset.",
390-
texture.name);
385+
return $"Texture '{texture.name}' is not saved to disk. Only texture assets that exist on disk can be added to a Texture2DArray asset.";
391386
}
392387
}
393388

@@ -414,7 +409,7 @@ static void CreateTexture2DArrayMenuItem()
414409
if (string.IsNullOrEmpty(directoryPath))
415410
directoryPath = "Assets/";
416411

417-
var fileName = string.Format("New Texture2DArray.{0}", kFileExtension);
412+
var fileName = $"New Texture2DArray.{kFileExtension}";
418413
directoryPath = AssetDatabase.GenerateUniqueAssetPath(directoryPath + fileName);
419414
ProjectWindowUtil.CreateAssetWithContent(directoryPath, "This file represents a Texture2DArray asset for Unity.\nYou need the 'Texture2DArray Import Pipeline' package available at https://github.com/pschraut/UnityTexture2DArrayImportPipeline to properly import this file in Unity.");
420415
}

Editor/Texture2DArrayImporterInspector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
2-
// Texture2D Array Importer for Unity. Copyright (c) 2019 Peter Schraut (www.console-dev.de). See LICENSE.md
2+
// Texture2D Array Importer for Unity. Copyright (c) 2019-2022 Peter Schraut (www.console-dev.de). See LICENSE.md
33
// https://github.com/pschraut/UnityTexture2DArrayImportPipeline
44
//
5-
#pragma warning disable IDE1006, IDE0017
5+
#pragma warning disable IDE1006, IDE0017, IDE0090
66
using UnityEngine;
77
using UnityEditor;
88
using UnityEditorInternal;
@@ -193,7 +193,7 @@ void OnDrawElement(Rect rect, int index, bool isActive, bool isFocused)
193193

194194
r = rect;
195195
rect.width = 24;
196-
EditorGUI.LabelField(rect, new GUIContent(string.Format("{0}", index), "Slice"), isFocused ? EditorStyles.whiteLabel : EditorStyles.label);
196+
EditorGUI.LabelField(rect, new GUIContent($"{index}", "Slice"), isFocused ? EditorStyles.whiteLabel : EditorStyles.label);
197197
rect = r;
198198
rect.width -= 24;
199199
rect.x += 24;

0 commit comments

Comments
 (0)