-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultipleSpritePivotEditor.cs
More file actions
91 lines (78 loc) · 2.61 KB
/
Copy pathMultipleSpritePivotEditor.cs
File metadata and controls
91 lines (78 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class MultipleSpritePivotEditor : EditorWindow
{
TextureImporterSettings TI_Settings = new TextureImporterSettings();
List<Object> seleceted = new List<Object>();
List<string> paths = new List<string>();
List<TextureImporter> TI = new List<TextureImporter>();
float xValue = 0.5f;
float yValue = 0.5f;
bool edidMode = false;
[MenuItem("Tools/SpritePivot")]
static void ToolBarWindow()
{
MultipleSpritePivotEditor window = (MultipleSpritePivotEditor)EditorWindow.GetWindow(typeof(MultipleSpritePivotEditor));
window.Show();
}
void OnGUI()
{
if (!edidMode)
{
if (GUILayout.Button("EditPivot"))
{
if (Selection.objects.Length > 0)
{
seleceted = Selection.objects.ToList();
for (int i = 0; i < seleceted.Count; i++)
{
string path = AssetDatabase.GetAssetPath(seleceted[i]);
paths.Add(path);
TI.Add(AssetImporter.GetAtPath(path) as TextureImporter);
}
for (int i = 0; i < TI.Count; i++)
{
TI[i].ReadTextureSettings(TI_Settings);
TI_Settings.spriteAlignment = (int)SpriteAlignment.Custom;
TI[i].SetTextureSettings(TI_Settings);
}
edidMode = true;
}
else
{
EditorUtility.DisplayDialog("Message", "선택된 스프라이트가 없습니다.", "OK");
}
}
}
if (edidMode)
{
xValue = EditorGUILayout.Slider(xValue, -0, 1);
yValue = EditorGUILayout.Slider(yValue, -0, 1);
if (GUILayout.Button("Complete"))
{
CompleteWork();
}
}
if (GUI.changed && edidMode)
{
for (int i = 0; i < TI.Count; i++)
{
TI[i].spritePivot = new Vector2(xValue, yValue);
}
}
}
void CompleteWork()
{
foreach (var t in paths)
{
AssetDatabase.ImportAsset(t, ImportAssetOptions.ForceUpdate);
}
seleceted.Clear();
paths.Clear();
paths.Clear();
edidMode = false;
}
}