【Unity】Sprite PivotをCustomに設定するサンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
/// <summary> | |
/// Sprite PivotをCustomに設定するサンプルコード | |
/// </summary> | |
public class CustomPivot : AssetPostprocessor | |
{ | |
private void OnPostprocessTexture(Texture2D target) | |
{ | |
var importer = assetImporter as TextureImporter; | |
if (importer == null) return; | |
importer.textureType = TextureImporterType.Sprite; | |
var so = new SerializedObject(importer); | |
// note : コメントを外すと全パラメータがログ出力されます | |
// PrintAllParameter(so); | |
var prop = so.FindProperty("m_Alignment"); | |
// set Pivot Custom | |
prop.intValue = 9; | |
so.ApplyModifiedProperties(); | |
} | |
private static void PrintAllParameter(SerializedObject so) | |
{ | |
var i = so.GetIterator(); | |
i.NextVisible(true); | |
string log = ""; | |
while (i.NextVisible(false)) log += $"{i.name}\n"; | |
Debug.Log(log); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment