1- using UnityEngine ;
1+ using UnityEngine ;
22using UnityEditor ;
33using System ;
44using System . Collections . Generic ;
@@ -13,29 +13,35 @@ namespace MMD
1313 [ Serializable ]
1414 public class Config : ScriptableObject
1515 {
16- public InspectorConfig inspector_config ;
17- public DefaultPMDImportConfig pmd_config ;
18- public DefaultVMDImportConfig vmd_config ;
16+ static Config config_ = null ;
17+ public InspectorConfig inspector_config = null ;
18+ public PMDImportConfig pmd_config = null ;
19+ public VMDImportConfig vmd_config = null ;
1920
20- private List < ConfigBase > update_list ;
21+ private List < ConfigBase > update_list = null ;
2122 public void OnEnable ( )
2223 {
23- // Inspectorで編集をさせない
24- hideFlags = HideFlags . NotEditable ;
25- if ( pmd_config == null )
24+ if ( inspector_config == null )
2625 {
27- // ここで初期化処理を書く
28- pmd_config = new DefaultPMDImportConfig ( ) ;
29- vmd_config = new DefaultVMDImportConfig ( ) ;
3026 inspector_config = new InspectorConfig ( ) ;
3127 }
28+ if ( pmd_config == null )
29+ {
30+ pmd_config = new PMDImportConfig ( ) ;
31+ }
32+ if ( vmd_config == null )
33+ {
34+ vmd_config = new VMDImportConfig ( ) ;
35+ }
3236 if ( update_list == null )
3337 {
3438 update_list = new List < ConfigBase > ( ) ;
3539 update_list . Add ( inspector_config ) ;
3640 update_list . Add ( pmd_config ) ;
3741 update_list . Add ( vmd_config ) ;
3842 }
43+
44+ hideFlags = HideFlags . None ; //以前の書き換え不可assetが残っているかもしれないので明示的に書き換え可能を設定
3945 }
4046
4147 /// <summary>
@@ -48,6 +54,11 @@ public void OnGUI()
4854 {
4955 item . OnGUI ( ) ;
5056 } ) ;
57+
58+ //変更確認
59+ if ( GUI . changed ) {
60+ EditorUtility . SetDirty ( config_ ) ;
61+ }
5162 }
5263
5364 /// <summary>
@@ -67,18 +78,20 @@ public static string GetConfigPath()
6778 /// <returns>読み込んで生成したConfigオブジェクト</returns>
6879 public static Config LoadAndCreate ( )
6980 {
70- var path = Config . GetConfigPath ( ) ;
71- var config = ( Config ) AssetDatabase . LoadAssetAtPath ( path , typeof ( Config ) ) ;
72-
73- //// なかったら作成する
74- if ( config == null )
81+ if ( config_ == null )
7582 {
76- config = CreateInstance < Config > ( ) ;
77- AssetDatabase . CreateAsset ( config , path ) ;
78- EditorUtility . SetDirty ( config ) ;
83+ var path = Config . GetConfigPath ( ) ;
84+ config_ = ( Config ) AssetDatabase . LoadAssetAtPath ( path , typeof ( Config ) ) ;
85+
86+ //// なかったら作成する
87+ if ( config_ == null )
88+ {
89+ config_ = CreateInstance < Config > ( ) ;
90+ AssetDatabase . CreateAsset ( config_ , path ) ;
91+ EditorUtility . SetDirty ( config_ ) ;
92+ }
7993 }
80- Debug . Log ( config ) ;
81- return config ;
94+ return config_ ;
8295 }
8396 }
8497
@@ -88,79 +101,94 @@ public static Config LoadAndCreate()
88101 [ Serializable ]
89102 public class InspectorConfig : ConfigBase
90103 {
91- public bool use_pmd_preload = false ;
92- public bool use_vmd_preload = false ;
104+ public bool use_pmd_preload = true ;
105+ public bool use_vmd_preload = true ;
93106
94- public InspectorConfig ( )
107+ public override string GetTitle ( )
95108 {
96- this . title = "Inspector Config" ;
109+ return "Inspector Config" ;
97110 }
98111
99- public override void OnGUI ( )
112+ public override void OnGUIFunction ( )
100113 {
101- base . OnGUI ( ( ) =>
102- {
103- use_pmd_preload = EditorGUILayout . Toggle ( "Use PMD Preload" , use_pmd_preload ) ;
104- use_vmd_preload = EditorGUILayout . Toggle ( "Use VMD Preload" , use_vmd_preload ) ;
105- }
106- ) ;
114+ use_pmd_preload = EditorGUILayout . Toggle ( "Use PMD Preload" , use_pmd_preload ) ;
115+ use_vmd_preload = EditorGUILayout . Toggle ( "Use VMD Preload" , use_vmd_preload ) ;
116+ }
117+
118+ public InspectorConfig Clone ( )
119+ {
120+ return ( InspectorConfig ) MemberwiseClone ( ) ;
107121 }
108122 }
109123
110124 /// <summary>
111- /// PMDインポートのデフォルトコンフィグ
125+ /// PMDインポートのコンフィグ
112126 /// </summary>
113127 [ Serializable ]
114- public class DefaultPMDImportConfig : ConfigBase
128+ public class PMDImportConfig : ConfigBase
115129 {
116130 public PMDConverter . ShaderType shader_type = PMDConverter . ShaderType . MMDShader ;
117- public bool use_mecanim = false ;
131+ public PMXConverter . AnimationType animation_type = PMXConverter . AnimationType . LegacyAnimation ;
118132 public bool rigidFlag = true ;
119133 public bool use_ik = true ;
120134 public float scale = 0.085f ;
121- public bool is_pmx_base_import = false ;
135+ public bool is_pmx_base_import = true ;
122136
123- public DefaultPMDImportConfig ( )
137+ public override string GetTitle ( )
124138 {
125- this . title = "Default PMD Import Config" ;
139+ return "Default PMD Import Config" ;
126140 }
127141
128- public override void OnGUI ( )
142+ public override void OnGUIFunction ( )
129143 {
130- base . OnGUI ( ( ) =>
131- {
132- shader_type = ( PMDConverter . ShaderType ) EditorGUILayout . EnumPopup ( "Shader Type" , shader_type ) ;
133- rigidFlag = EditorGUILayout . Toggle ( "Rigidbody" , rigidFlag ) ;
134- use_mecanim = false ;
135- use_ik = EditorGUILayout . Toggle ( "Use IK" , use_ik ) ;
136- is_pmx_base_import = EditorGUILayout . Toggle ( "Use PMX Base Import" , is_pmx_base_import ) ;
144+ shader_type = ( PMDConverter . ShaderType ) EditorGUILayout . EnumPopup ( "Shader Type" , shader_type ) ;
145+ rigidFlag = EditorGUILayout . Toggle ( "Rigidbody" , rigidFlag ) ;
146+ animation_type = ( PMXConverter . AnimationType ) EditorGUILayout . EnumPopup ( "Animation Type" , animation_type ) ;
147+ use_ik = EditorGUILayout . Toggle ( "Use IK" , use_ik ) ;
148+ scale = EditorGUILayout . Slider ( "Scale" , scale , 0.001f , 1.0f ) ;
149+ EditorGUILayout . BeginHorizontal ( ) ;
150+ {
151+ EditorGUILayout . PrefixLabel ( " " ) ;
152+ if ( GUILayout . Button ( "Original" , EditorStyles . miniButtonLeft ) ) {
153+ scale = 0.085f ;
154+ }
155+ if ( GUILayout . Button ( "1.0" , EditorStyles . miniButtonRight ) ) {
156+ scale = 1.0f ;
137157 }
138- ) ;
158+ }
159+ EditorGUILayout . EndHorizontal ( ) ;
160+ is_pmx_base_import = EditorGUILayout . Toggle ( "Use PMX Base Import" , is_pmx_base_import ) ;
161+ }
162+
163+ public PMDImportConfig Clone ( )
164+ {
165+ return ( PMDImportConfig ) MemberwiseClone ( ) ;
139166 }
140167 }
141168
142169 /// <summary>
143- /// VMDインポートのデフォルトコンフィグ
170+ /// VMDインポートのコンフィグ
144171 /// </summary>
145172 [ Serializable ]
146- public class DefaultVMDImportConfig : ConfigBase
173+ public class VMDImportConfig : ConfigBase
147174 {
148- public bool createAnimationFile ;
149- public int interpolationQuality ;
175+ public bool createAnimationFile = false ;
176+ public int interpolationQuality = 1 ;
150177
151- public DefaultVMDImportConfig ( )
178+ public override string GetTitle ( )
152179 {
153- this . title = "Default VMD Import Config" ;
180+ return "Default VMD Import Config" ;
154181 }
155182
156- public override void OnGUI ( )
183+ public override void OnGUIFunction ( )
157184 {
158- base . OnGUI ( ( ) =>
159- {
160- createAnimationFile = EditorGUILayout . Toggle ( "Create Asset" , createAnimationFile ) ;
161- interpolationQuality = EditorGUILayout . IntSlider ( "Interpolation Quality" , interpolationQuality , 1 , 10 ) ;
162- }
163- ) ;
185+ createAnimationFile = EditorGUILayout . Toggle ( "Create Asset" , createAnimationFile ) ;
186+ interpolationQuality = EditorGUILayout . IntSlider ( "Interpolation Quality" , interpolationQuality , 1 , 10 ) ;
187+ }
188+
189+ public VMDImportConfig Clone ( )
190+ {
191+ return ( VMDImportConfig ) MemberwiseClone ( ) ;
164192 }
165193 }
166194
@@ -169,11 +197,6 @@ public override void OnGUI()
169197 /// </summary>
170198 public class ConfigBase
171199 {
172- /// <summary>
173- /// このコンフィグのタイトルを指定します
174- /// </summary>
175- protected string title = "" ;
176-
177200 /// <summary>
178201 /// 開け閉めの状態
179202 /// </summary>
@@ -182,19 +205,28 @@ public class ConfigBase
182205 /// <summary>
183206 /// GUI処理を行います
184207 /// </summary>
185- /// <param name="OnGUIFunction">引数・戻り値なしのラムダ式</param>
186- public void OnGUI ( Action OnGUIFunction )
208+ public void OnGUI ( )
187209 {
210+ var title = GetTitle ( ) ;
188211 fold = EditorGUILayout . Foldout ( fold , title ) ;
189- if ( fold )
212+ if ( fold ) {
190213 OnGUIFunction ( ) ;
214+ }
191215 EditorGUILayout . Space ( ) ;
192216 }
193217
218+ /// <summary>
219+ /// このコンフィグのタイトルを取得します
220+ /// </summary>
221+ public virtual string GetTitle ( )
222+ {
223+ return "" ;
224+ }
225+
194226 /// <summary>
195227 /// GUI処理を行います
196228 /// </summary>
197- public virtual void OnGUI ( )
229+ public virtual void OnGUIFunction ( )
198230 {
199231 }
200232 }
0 commit comments