11using System . Linq ;
22using UnityEditor ;
33using UnityEngine ;
4+ using UnityEditor . Localization . Editor ;
45
56namespace Unity . Animations . SpringBones
67{
78 public class LoadSpringBoneSetupWindow : EditorWindow
89 {
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+
941 public static void ShowWindow ( )
1042 {
11- var editorWindow = GetWindow < LoadSpringBoneSetupWindow > (
12- "スプリングボーンセットアップを読み込む" ) ;
43+ var editorWindow = GetWindow < LoadSpringBoneSetupWindow > ( Styles . editorWindowTitle ) ;
1344 if ( editorWindow != null )
1445 {
1546 editorWindow . SelectObjectsFromSelection ( ) ;
@@ -35,8 +66,6 @@ ref int yPos
3566
3667 // private
3768
38- private const string StopPlayModeMessage = "再生モードでセットアップしないでください。" ;
39- private const string SelectObjectRootsMessage = "スプリングボーンの親オブジェクトを指定してください。" ;
4069 private const int UIRowHeight = 24 ;
4170 private const int UISpacing = 8 ;
4271 private const int LabelWidth = 200 ;
@@ -74,11 +103,11 @@ private void ShowImportSettingsUI(ref Rect uiRect)
74103 importSettings = new DynamicsSetup . ImportSettings ( ) ;
75104 }
76105
77- GUI . Label ( uiRect , "読み込み設定" , SpringBoneGUIStyles . HeaderLabelStyle ) ;
106+ GUI . Label ( uiRect , Styles . labelLoadingConfig , SpringBoneGUIStyles . HeaderLabelStyle ) ;
78107 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 ) ;
80109 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 ) ;
82111 uiRect . y += uiRect . height ;
83112 }
84113
@@ -90,9 +119,9 @@ private void OnGUI()
90119
91120 var uiWidth = ( int ) position . width - UISpacing * 2 ;
92121 var yPos = UISpacing ;
93- springBoneRoot = DoObjectPicker ( "スプリングボーンのルート" , springBoneRoot , uiWidth , UIRowHeight , ref yPos ) ;
122+ springBoneRoot = DoObjectPicker ( Styles . labelSpringBoneRoot , springBoneRoot , uiWidth , UIRowHeight , ref yPos ) ;
94123 var buttonRect = new Rect ( UISpacing , yPos , uiWidth , ButtonHeight ) ;
95- if ( GUI . Button ( buttonRect , "選択からルートを取得" , SpringBoneGUIStyles . ButtonStyle ) )
124+ if ( GUI . Button ( buttonRect , Styles . labelSelectFromRoot , SpringBoneGUIStyles . ButtonStyle ) )
96125 {
97126 SelectObjectsFromSelection ( ) ;
98127 }
@@ -104,7 +133,7 @@ private void OnGUI()
104133 string errorMessage ;
105134 if ( IsOkayToSetup ( out errorMessage ) )
106135 {
107- if ( GUI . Button ( buttonRect , "CSVを読み込んでセットアップ" , SpringBoneGUIStyles . ButtonStyle ) )
136+ if ( GUI . Button ( buttonRect , Styles . labelSetupLoadCSV , SpringBoneGUIStyles . ButtonStyle ) )
108137 {
109138 BrowseAndLoadSpringSetup ( ) ;
110139 }
@@ -122,13 +151,13 @@ private bool IsOkayToSetup(out string errorMessage)
122151 errorMessage = "" ;
123152 if ( EditorApplication . isPlaying )
124153 {
125- errorMessage = StopPlayModeMessage ;
154+ errorMessage = Styles . stopPlayModeMessage ;
126155 return false ;
127156 }
128157
129158 if ( springBoneRoot == null )
130159 {
131- errorMessage = SelectObjectRootsMessage ;
160+ errorMessage = Styles . selectObjectRootsMessage ;
132161 return false ;
133162 }
134163 return true ;
@@ -169,11 +198,10 @@ public void Perform()
169198 setup . Build ( ) ;
170199 AssetDatabase . Refresh ( ) ;
171200
172- const string ResultFormat = "セットアップ完了: {0}\n ボーン数: {1} コライダー数: {2}" ;
173201 var boneCount = springBoneRoot . GetComponentsInChildren < SpringBone > ( true ) . Length ;
174202 var colliderCount = SpringColliderSetup . GetColliderTypes ( )
175203 . 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 ) ;
177205 Debug . Log ( resultMessage ) ;
178206 }
179207
@@ -184,18 +212,17 @@ public void Perform()
184212
185213 private void BrowseAndLoadSpringSetup ( )
186214 {
187- string checkErrorMessage ;
188- if ( ! IsOkayToSetup ( out checkErrorMessage ) )
215+ if ( ! IsOkayToSetup ( out var checkErrorMessage ) )
189216 {
190217 Debug . LogError ( checkErrorMessage ) ;
191218 return ;
192219 }
193220
194221 // var initialPath = "";
195222 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" } ;
197224 var path = EditorUtility . OpenFilePanelWithFilters (
198- "スプリングボーンセットアップを読み込む" , initialDirectory , fileFilters ) ;
225+ Styles . loadSpringBoneSetup , initialDirectory , fileFilters ) ;
199226 if ( path . Length == 0 ) { return ; }
200227
201228 var sourceText = FileUtil . ReadAllText ( path ) ;
@@ -216,16 +243,10 @@ private void BrowseAndLoadSpringSetup()
216243 }
217244 else
218245 {
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 ) ;
229250 }
230251 Close ( ) ;
231252 }
0 commit comments