Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active Aug 9, 2021
Embed
What would you like to do?
【Unity】Sprite PivotをCustomに設定するサンプルコード
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