Last active
August 9, 2021 07:08
-
-
Save baobao/38bc50e2b7f4f0f840c85d3f9b1fd902 to your computer and use it in GitHub Desktop.
【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