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,17 +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- return config ;
94+ return config_ ;
8195 }
8296 }
8397
@@ -87,79 +101,94 @@ public static Config LoadAndCreate()
87101 [ Serializable ]
88102 public class InspectorConfig : ConfigBase
89103 {
90- public bool use_pmd_preload = false ;
91- public bool use_vmd_preload = false ;
104+ public bool use_pmd_preload = true ;
105+ public bool use_vmd_preload = true ;
92106
93- public InspectorConfig ( )
107+ public override string GetTitle ( )
94108 {
95- this . title = "Inspector Config" ;
109+ return "Inspector Config" ;
96110 }
97111
98- public override void OnGUI ( )
112+ public override void OnGUIFunction ( )
99113 {
100- base . OnGUI ( ( ) =>
101- {
102- use_pmd_preload = EditorGUILayout . Toggle ( "Use PMD Preload" , use_pmd_preload ) ;
103- use_vmd_preload = EditorGUILayout . Toggle ( "Use VMD Preload" , use_vmd_preload ) ;
104- }
105- ) ;
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 ( ) ;
106121 }
107122 }
108123
109124 /// <summary>
110- /// PMDインポートのデフォルトコンフィグ
125+ /// PMDインポートのコンフィグ
111126 /// </summary>
112127 [ Serializable ]
113- public class DefaultPMDImportConfig : ConfigBase
128+ public class PMDImportConfig : ConfigBase
114129 {
115130 public PMDConverter . ShaderType shader_type = PMDConverter . ShaderType . MMDShader ;
116131 public PMXConverter . AnimationType animation_type = PMXConverter . AnimationType . LegacyAnimation ;
117132 public bool rigidFlag = true ;
118133 public bool use_ik = true ;
119134 public float scale = 0.085f ;
120- public bool is_pmx_base_import = false ;
135+ public bool is_pmx_base_import = true ;
121136
122- public DefaultPMDImportConfig ( )
137+ public override string GetTitle ( )
123138 {
124- this . title = "Default PMD Import Config" ;
139+ return "Default PMD Import Config" ;
125140 }
126141
127- public override void OnGUI ( )
142+ public override void OnGUIFunction ( )
128143 {
129- base . OnGUI ( ( ) =>
130- {
131- shader_type = ( PMDConverter . ShaderType ) EditorGUILayout . EnumPopup ( "Shader Type" , shader_type ) ;
132- rigidFlag = EditorGUILayout . Toggle ( "Rigidbody" , rigidFlag ) ;
133- animation_type = ( PMXConverter . AnimationType ) EditorGUILayout . EnumPopup ( "Animation Type" , animation_type ) ;
134- use_ik = EditorGUILayout . Toggle ( "Use IK" , use_ik ) ;
135- 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 ;
136157 }
137- ) ;
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 ( ) ;
138166 }
139167 }
140168
141169 /// <summary>
142- /// VMDインポートのデフォルトコンフィグ
170+ /// VMDインポートのコンフィグ
143171 /// </summary>
144172 [ Serializable ]
145- public class DefaultVMDImportConfig : ConfigBase
173+ public class VMDImportConfig : ConfigBase
146174 {
147- public bool createAnimationFile ;
148- public int interpolationQuality ;
175+ public bool createAnimationFile = false ;
176+ public int interpolationQuality = 1 ;
149177
150- public DefaultVMDImportConfig ( )
178+ public override string GetTitle ( )
151179 {
152- this . title = "Default VMD Import Config" ;
180+ return "Default VMD Import Config" ;
153181 }
154182
155- public override void OnGUI ( )
183+ public override void OnGUIFunction ( )
156184 {
157- base . OnGUI ( ( ) =>
158- {
159- createAnimationFile = EditorGUILayout . Toggle ( "Create Asset" , createAnimationFile ) ;
160- interpolationQuality = EditorGUILayout . IntSlider ( "Interpolation Quality" , interpolationQuality , 1 , 10 ) ;
161- }
162- ) ;
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 ( ) ;
163192 }
164193 }
165194
@@ -168,11 +197,6 @@ public override void OnGUI()
168197 /// </summary>
169198 public class ConfigBase
170199 {
171- /// <summary>
172- /// このコンフィグのタイトルを指定します
173- /// </summary>
174- protected string title = "" ;
175-
176200 /// <summary>
177201 /// 開け閉めの状態
178202 /// </summary>
@@ -181,19 +205,28 @@ public class ConfigBase
181205 /// <summary>
182206 /// GUI処理を行います
183207 /// </summary>
184- /// <param name="OnGUIFunction">引数・戻り値なしのラムダ式</param>
185- public void OnGUI ( Action OnGUIFunction )
208+ public void OnGUI ( )
186209 {
210+ var title = GetTitle ( ) ;
187211 fold = EditorGUILayout . Foldout ( fold , title ) ;
188- if ( fold )
212+ if ( fold ) {
189213 OnGUIFunction ( ) ;
214+ }
190215 EditorGUILayout . Space ( ) ;
191216 }
192217
218+ /// <summary>
219+ /// このコンフィグのタイトルを取得します
220+ /// </summary>
221+ public virtual string GetTitle ( )
222+ {
223+ return "" ;
224+ }
225+
193226 /// <summary>
194227 /// GUI処理を行います
195228 /// </summary>
196- public virtual void OnGUI ( )
229+ public virtual void OnGUIFunction ( )
197230 {
198231 }
199232 }
0 commit comments