回答編集履歴

2

元のコードのスタイルに合わせてthisを削除

2022/04/06 23:43

投稿

Bongo
Bongo

スコア10807

test CHANGED
@@ -28,7 +28,7 @@
28
28
  GetWidthAndHeightDelegate getWidthAndHeight;
29
29
 
30
30
  GetWidthAndHeightDelegate GetWidthAndHeight =>
31
- this.getWidthAndHeight ??= (GetWidthAndHeightDelegate)Delegate.CreateDelegate(
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(this.assetPath).Parent.Name != "AutoProcessedSpriteSheets") return;
39
+ if (Directory.GetParent(assetPath).Parent.Name != "AutoProcessedSpriteSheets") return;
40
40
 
41
- TextureImporter ti = (TextureImporter)this.assetImporter;
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(this.assetPath).Name.Split('_');
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 this.spriteSizeX) && int.TryParse(parentDir[1], out this.spriteSizeY) && int.TryParse(parentDir[2], out this.ppu))
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 = this.ppu;
53
+ ti.spritePixelsPerUnit = ppu;
54
- if (this.spriteSizeX > 0 && this.spriteSizeY > 0)
54
+ if (spriteSizeX > 0 && spriteSizeY > 0)
55
55
  {
56
56
  int textureWidth = 0;
57
57
  int textureHeight = 0;
58
- this.GetWidthAndHeight(ti, ref textureWidth, ref textureHeight);
58
+ GetWidthAndHeight(ti, ref textureWidth, ref textureHeight);
59
- int colCount = textureWidth / this.spriteSizeX;
59
+ int colCount = textureWidth / spriteSizeX;
60
- int rowCount = textureHeight / this.spriteSizeY;
60
+ int rowCount = textureHeight / spriteSizeY;
61
- string fileName = Path.GetFileNameWithoutExtension(this.assetPath);
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 * this.spriteSizeX, r * this.spriteSizeY, this.spriteSizeX, this.spriteSizeY);
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変数を削除

2022/04/06 23:16

投稿

Bongo
Bongo

スコア10807

test CHANGED
@@ -75,8 +75,7 @@
75
75
  }
76
76
  }
77
77
 
78
- TextureImporter textureImporter = (TextureImporter)this.assetImporter;
79
- textureImporter.spritesheet = metas.ToArray();
78
+ ti.spritesheet = metas.ToArray();
80
79
  }
81
80
  }
82
81
  }