回答編集履歴
2
元のコードのスタイルに合わせてthisを削除
test
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
GetWidthAndHeightDelegate getWidthAndHeight;
|
29
29
|
|
30
30
|
GetWidthAndHeightDelegate GetWidthAndHeight =>
|
31
|
-
|
31
|
+
getWidthAndHeight ??= (GetWidthAndHeightDelegate)Delegate.CreateDelegate(
|
32
32
|
typeof(GetWidthAndHeightDelegate),
|
33
33
|
typeof(TextureImporter).GetMethod(
|
34
34
|
"GetWidthAndHeight",
|
@@ -36,29 +36,29 @@
|
|
36
36
|
|
37
37
|
void OnPreprocessTexture()
|
38
38
|
{
|
39
|
-
if (Directory.GetParent(
|
39
|
+
if (Directory.GetParent(assetPath).Parent.Name != "AutoProcessedSpriteSheets") return;
|
40
40
|
|
41
|
-
TextureImporter ti = (TextureImporter)
|
41
|
+
TextureImporter ti = (TextureImporter)assetImporter;
|
42
42
|
ti.textureType = TextureImporterType.Sprite;
|
43
43
|
ti.spriteImportMode = SpriteImportMode.Multiple;
|
44
44
|
ti.mipmapEnabled = false;
|
45
45
|
ti.filterMode = FilterMode.Point;
|
46
46
|
ti.textureCompression = TextureImporterCompression.Uncompressed;
|
47
47
|
|
48
|
-
string[] parentDir = Directory.GetParent(
|
48
|
+
string[] parentDir = Directory.GetParent(assetPath).Name.Split('_');
|
49
49
|
|
50
50
|
//If we can't parse the parent directory values as integers, don't continue processing the sprite
|
51
|
-
if (int.TryParse(parentDir[0], out
|
51
|
+
if (int.TryParse(parentDir[0], out spriteSizeX) && int.TryParse(parentDir[1], out spriteSizeY) && int.TryParse(parentDir[2], out ppu))
|
52
52
|
{
|
53
|
-
ti.spritePixelsPerUnit =
|
53
|
+
ti.spritePixelsPerUnit = ppu;
|
54
|
-
if (
|
54
|
+
if (spriteSizeX > 0 && spriteSizeY > 0)
|
55
55
|
{
|
56
56
|
int textureWidth = 0;
|
57
57
|
int textureHeight = 0;
|
58
|
-
|
58
|
+
GetWidthAndHeight(ti, ref textureWidth, ref textureHeight);
|
59
|
-
int colCount = textureWidth /
|
59
|
+
int colCount = textureWidth / spriteSizeX;
|
60
|
-
int rowCount = textureHeight /
|
60
|
+
int rowCount = textureHeight / spriteSizeY;
|
61
|
-
string fileName = Path.GetFileNameWithoutExtension(
|
61
|
+
string fileName = Path.GetFileNameWithoutExtension(assetPath);
|
62
62
|
int i = 0;
|
63
63
|
|
64
64
|
List<SpriteMetaData> metas = new List<SpriteMetaData>();
|
@@ -68,7 +68,7 @@
|
|
68
68
|
for (int c = 0; c < colCount; c++)
|
69
69
|
{
|
70
70
|
SpriteMetaData meta = new SpriteMetaData();
|
71
|
-
meta.rect = new Rect(c *
|
71
|
+
meta.rect = new Rect(c * spriteSizeX, r * spriteSizeY, spriteSizeX, spriteSizeY);
|
72
72
|
meta.name = fileName + "_" + i;
|
73
73
|
metas.Add(meta);
|
74
74
|
i++;
|
1
末尾のtextureImporter変数を削除
test
CHANGED
@@ -75,8 +75,7 @@
|
|
75
75
|
}
|
76
76
|
}
|
77
77
|
|
78
|
-
TextureImporter textureImporter = (TextureImporter)this.assetImporter;
|
79
|
-
t
|
78
|
+
ti.spritesheet = metas.ToArray();
|
80
79
|
}
|
81
80
|
}
|
82
81
|
}
|