1
1
using System . Linq ;
2
2
using UnityEditor ;
3
3
using UnityEngine ;
4
+ using UnityEditor . Localization . Editor ;
4
5
5
6
namespace Unity . Animations . SpringBones
6
7
{
7
8
public class LoadSpringBoneSetupWindow : EditorWindow
8
9
{
10
+ private static class Styles
11
+ {
12
+ public static readonly string editorWindowTitle = Localization . Tr ( "Load spring bone setup" ) ;
13
+ public static readonly string stopPlayModeMessage = Localization . Tr ( "Do not setup in Play Mode" ) ;
14
+ public static readonly string selectObjectRootsMessage = Localization . Tr ( "Select parent object of the spring bone" ) ;
15
+ public static readonly string resultFormat = Localization . Tr ( "Set up complete:{0}\n Number of bones: {1} Number of colliders: {2}" ) ;
16
+ public static readonly string csvFile = Localization . Tr ( "CSV File" ) ;
17
+ public static readonly string textFile = Localization . Tr ( "Text File" ) ;
18
+ public static readonly string loadSpringBoneSetup = Localization . Tr ( "Load spring bone setup" ) ;
19
+ public static readonly string errorFormat = Localization . Tr (
20
+ "SpringBone setup failed.\n "
21
+ + "Souce data may contain errors,\n "
22
+ + "or the data don't match the character.\n "
23
+ + "Please refer console logs for further info.\n "
24
+ + "\n "
25
+ + "Character: {0}\n "
26
+ + "\n "
27
+ + "Path: {1}" ) ;
28
+
29
+ public static readonly string springBoneSetup = Localization . Tr ( "SpringBone Setup" ) ;
30
+ public static readonly string springBoneSetupFailedFormat = Localization . Tr ( "SpringBone Setup failed:{0}\n Path:{1}" ) ;
31
+ public static readonly string labelSpringBoneRoot = Localization . Tr ( "SpringBone Root" ) ;
32
+
33
+ public static readonly GUIContent labelLoadingConfig = new GUIContent ( Localization . Tr ( "Loading Configuration" ) ) ;
34
+ public static readonly GUIContent labelSpringBone = new GUIContent ( Localization . Tr ( "SpringBone" ) ) ;
35
+ public static readonly GUIContent labelCollider = new GUIContent ( Localization . Tr ( "Collider" ) ) ;
36
+
37
+ public static readonly GUIContent labelSelectFromRoot = new GUIContent ( Localization . Tr ( "Get root from selection" ) ) ;
38
+ public static readonly GUIContent labelSetupLoadCSV = new GUIContent ( Localization . Tr ( "Set up from CSV file" ) ) ;
39
+ }
40
+
9
41
public static void ShowWindow ( )
10
42
{
11
- var editorWindow = GetWindow < LoadSpringBoneSetupWindow > (
12
- "スプリングボーンセットアップを読み込む" ) ;
43
+ var editorWindow = GetWindow < LoadSpringBoneSetupWindow > ( Styles . editorWindowTitle ) ;
13
44
if ( editorWindow != null )
14
45
{
15
46
editorWindow . SelectObjectsFromSelection ( ) ;
@@ -35,8 +66,6 @@ ref int yPos
35
66
36
67
// private
37
68
38
- private const string StopPlayModeMessage = "再生モードでセットアップしないでください。" ;
39
- private const string SelectObjectRootsMessage = "スプリングボーンの親オブジェクトを指定してください。" ;
40
69
private const int UIRowHeight = 24 ;
41
70
private const int UISpacing = 8 ;
42
71
private const int LabelWidth = 200 ;
@@ -74,11 +103,11 @@ private void ShowImportSettingsUI(ref Rect uiRect)
74
103
importSettings = new DynamicsSetup . ImportSettings ( ) ;
75
104
}
76
105
77
- GUI . Label ( uiRect , "読み込み設定" , SpringBoneGUIStyles . HeaderLabelStyle ) ;
106
+ GUI . Label ( uiRect , Styles . labelLoadingConfig , SpringBoneGUIStyles . HeaderLabelStyle ) ;
78
107
uiRect . y += uiRect . height ;
79
- importSettings . ImportSpringBones = GUI . Toggle ( uiRect , importSettings . ImportSpringBones , "スプリングボーン" , SpringBoneGUIStyles . ToggleStyle ) ;
108
+ importSettings . ImportSpringBones = GUI . Toggle ( uiRect , importSettings . ImportSpringBones , Styles . labelSpringBone , SpringBoneGUIStyles . ToggleStyle ) ;
80
109
uiRect . y += uiRect . height ;
81
- importSettings . ImportCollision = GUI . Toggle ( uiRect , importSettings . ImportCollision , "コライダー" , SpringBoneGUIStyles . ToggleStyle ) ;
110
+ importSettings . ImportCollision = GUI . Toggle ( uiRect , importSettings . ImportCollision , Styles . labelCollider , SpringBoneGUIStyles . ToggleStyle ) ;
82
111
uiRect . y += uiRect . height ;
83
112
}
84
113
@@ -90,9 +119,9 @@ private void OnGUI()
90
119
91
120
var uiWidth = ( int ) position . width - UISpacing * 2 ;
92
121
var yPos = UISpacing ;
93
- springBoneRoot = DoObjectPicker ( "スプリングボーンのルート" , springBoneRoot , uiWidth , UIRowHeight , ref yPos ) ;
122
+ springBoneRoot = DoObjectPicker ( Styles . labelSpringBoneRoot , springBoneRoot , uiWidth , UIRowHeight , ref yPos ) ;
94
123
var buttonRect = new Rect ( UISpacing , yPos , uiWidth , ButtonHeight ) ;
95
- if ( GUI . Button ( buttonRect , "選択からルートを取得" , SpringBoneGUIStyles . ButtonStyle ) )
124
+ if ( GUI . Button ( buttonRect , Styles . labelSelectFromRoot , SpringBoneGUIStyles . ButtonStyle ) )
96
125
{
97
126
SelectObjectsFromSelection ( ) ;
98
127
}
@@ -104,7 +133,7 @@ private void OnGUI()
104
133
string errorMessage ;
105
134
if ( IsOkayToSetup ( out errorMessage ) )
106
135
{
107
- if ( GUI . Button ( buttonRect , "CSVを読み込んでセットアップ" , SpringBoneGUIStyles . ButtonStyle ) )
136
+ if ( GUI . Button ( buttonRect , Styles . labelSetupLoadCSV , SpringBoneGUIStyles . ButtonStyle ) )
108
137
{
109
138
BrowseAndLoadSpringSetup ( ) ;
110
139
}
@@ -122,13 +151,13 @@ private bool IsOkayToSetup(out string errorMessage)
122
151
errorMessage = "" ;
123
152
if ( EditorApplication . isPlaying )
124
153
{
125
- errorMessage = StopPlayModeMessage ;
154
+ errorMessage = Styles . stopPlayModeMessage ;
126
155
return false ;
127
156
}
128
157
129
158
if ( springBoneRoot == null )
130
159
{
131
- errorMessage = SelectObjectRootsMessage ;
160
+ errorMessage = Styles . selectObjectRootsMessage ;
132
161
return false ;
133
162
}
134
163
return true ;
@@ -169,11 +198,10 @@ public void Perform()
169
198
setup . Build ( ) ;
170
199
AssetDatabase . Refresh ( ) ;
171
200
172
- const string ResultFormat = "セットアップ完了: {0}\n ボーン数: {1} コライダー数: {2}" ;
173
201
var boneCount = springBoneRoot . GetComponentsInChildren < SpringBone > ( true ) . Length ;
174
202
var colliderCount = SpringColliderSetup . GetColliderTypes ( )
175
203
. Sum ( type => springBoneRoot . GetComponentsInChildren ( type , true ) . Length ) ;
176
- var resultMessage = string . Format ( ResultFormat , path , boneCount , colliderCount ) ;
204
+ var resultMessage = string . Format ( Styles . resultFormat , path , boneCount , colliderCount ) ;
177
205
Debug . Log ( resultMessage ) ;
178
206
}
179
207
@@ -184,18 +212,17 @@ public void Perform()
184
212
185
213
private void BrowseAndLoadSpringSetup ( )
186
214
{
187
- string checkErrorMessage ;
188
- if ( ! IsOkayToSetup ( out checkErrorMessage ) )
215
+ if ( ! IsOkayToSetup ( out var checkErrorMessage ) )
189
216
{
190
217
Debug . LogError ( checkErrorMessage ) ;
191
218
return ;
192
219
}
193
220
194
221
// var initialPath = "";
195
222
var initialDirectory = "" ; // System.IO.Path.GetDirectoryName(initialPath);
196
- var fileFilters = new string [ ] { "CSVファイル" , "csv" , "テキストファイル" , "txt" } ;
223
+ var fileFilters = new string [ ] { Styles . csvFile , "csv" , Styles . textFile , "txt" } ;
197
224
var path = EditorUtility . OpenFilePanelWithFilters (
198
- "スプリングボーンセットアップを読み込む" , initialDirectory , fileFilters ) ;
225
+ Styles . loadSpringBoneSetup , initialDirectory , fileFilters ) ;
199
226
if ( path . Length == 0 ) { return ; }
200
227
201
228
var sourceText = FileUtil . ReadAllText ( path ) ;
@@ -216,16 +243,10 @@ private void BrowseAndLoadSpringSetup()
216
243
}
217
244
else
218
245
{
219
- const string ErrorFormat =
220
- "スプリングボーンセットアップが失敗しました。\n "
221
- + "元データにエラーがあるか、もしくは\n "
222
- + "キャラクターにデータが一致しません。\n "
223
- + "詳しくはConsoleのログをご覧下さい。\n \n "
224
- + "キャラクター: {0}\n \n "
225
- + "パス: {1}" ;
226
- var resultErrorMessage = string . Format ( ErrorFormat , springBoneRoot . name , path ) ;
227
- EditorUtility . DisplayDialog ( "スプリングボーンセットアップ" , resultErrorMessage , "OK" ) ;
228
- Debug . LogError ( "スプリングボーンセットアップ失敗: " + springBoneRoot . name + "\n " + path ) ;
246
+ var resultErrorMessage = string . Format ( Styles . errorFormat , springBoneRoot . name , path ) ;
247
+ EditorUtility . DisplayDialog ( Styles . springBoneSetup , resultErrorMessage , "OK" ) ;
248
+ Debug . LogFormat ( LogType . Error , LogOption . None , springBoneRoot ,
249
+ Styles . springBoneSetupFailedFormat , springBoneRoot . name , path ) ;
229
250
}
230
251
Close ( ) ;
231
252
}
0 commit comments