1
- using UnityEngine ;
1
+ using UnityEngine ;
2
2
using UnityEditor ;
3
3
using System ;
4
4
using System . Collections . Generic ;
@@ -13,29 +13,35 @@ namespace MMD
13
13
[ Serializable ]
14
14
public class Config : ScriptableObject
15
15
{
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 ;
19
20
20
- private List < ConfigBase > update_list ;
21
+ private List < ConfigBase > update_list = null ;
21
22
public void OnEnable ( )
22
23
{
23
- // Inspectorで編集をさせない
24
- hideFlags = HideFlags . NotEditable ;
25
- if ( pmd_config == null )
24
+ if ( inspector_config == null )
26
25
{
27
- // ここで初期化処理を書く
28
- pmd_config = new DefaultPMDImportConfig ( ) ;
29
- vmd_config = new DefaultVMDImportConfig ( ) ;
30
26
inspector_config = new InspectorConfig ( ) ;
31
27
}
28
+ if ( pmd_config == null )
29
+ {
30
+ pmd_config = new PMDImportConfig ( ) ;
31
+ }
32
+ if ( vmd_config == null )
33
+ {
34
+ vmd_config = new VMDImportConfig ( ) ;
35
+ }
32
36
if ( update_list == null )
33
37
{
34
38
update_list = new List < ConfigBase > ( ) ;
35
39
update_list . Add ( inspector_config ) ;
36
40
update_list . Add ( pmd_config ) ;
37
41
update_list . Add ( vmd_config ) ;
38
42
}
43
+
44
+ hideFlags = HideFlags . None ; //以前の書き換え不可assetが残っているかもしれないので明示的に書き換え可能を設定
39
45
}
40
46
41
47
/// <summary>
@@ -48,6 +54,11 @@ public void OnGUI()
48
54
{
49
55
item . OnGUI ( ) ;
50
56
} ) ;
57
+
58
+ //変更確認
59
+ if ( GUI . changed ) {
60
+ EditorUtility . SetDirty ( config_ ) ;
61
+ }
51
62
}
52
63
53
64
/// <summary>
@@ -67,18 +78,20 @@ public static string GetConfigPath()
67
78
/// <returns>読み込んで生成したConfigオブジェクト</returns>
68
79
public static Config LoadAndCreate ( )
69
80
{
70
- var path = Config . GetConfigPath ( ) ;
71
- var config = ( Config ) AssetDatabase . LoadAssetAtPath ( path , typeof ( Config ) ) ;
72
-
73
- //// なかったら作成する
74
- if ( config == null )
81
+ if ( config_ == null )
75
82
{
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
+ }
79
93
}
80
- Debug . Log ( config ) ;
81
- return config ;
94
+ return config_ ;
82
95
}
83
96
}
84
97
@@ -88,79 +101,94 @@ public static Config LoadAndCreate()
88
101
[ Serializable ]
89
102
public class InspectorConfig : ConfigBase
90
103
{
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 ;
93
106
94
- public InspectorConfig ( )
107
+ public override string GetTitle ( )
95
108
{
96
- this . title = "Inspector Config" ;
109
+ return "Inspector Config" ;
97
110
}
98
111
99
- public override void OnGUI ( )
112
+ public override void OnGUIFunction ( )
100
113
{
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 ( ) ;
107
121
}
108
122
}
109
123
110
124
/// <summary>
111
- /// PMDインポートのデフォルトコンフィグ
125
+ /// PMDインポートのコンフィグ
112
126
/// </summary>
113
127
[ Serializable ]
114
- public class DefaultPMDImportConfig : ConfigBase
128
+ public class PMDImportConfig : ConfigBase
115
129
{
116
130
public PMDConverter . ShaderType shader_type = PMDConverter . ShaderType . MMDShader ;
117
- public bool use_mecanim = false ;
131
+ public PMXConverter . AnimationType animation_type = PMXConverter . AnimationType . LegacyAnimation ;
118
132
public bool rigidFlag = true ;
119
133
public bool use_ik = true ;
120
134
public float scale = 0.085f ;
121
- public bool is_pmx_base_import = false ;
135
+ public bool is_pmx_base_import = true ;
122
136
123
- public DefaultPMDImportConfig ( )
137
+ public override string GetTitle ( )
124
138
{
125
- this . title = "Default PMD Import Config" ;
139
+ return "Default PMD Import Config" ;
126
140
}
127
141
128
- public override void OnGUI ( )
142
+ public override void OnGUIFunction ( )
129
143
{
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 ;
137
157
}
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 ( ) ;
139
166
}
140
167
}
141
168
142
169
/// <summary>
143
- /// VMDインポートのデフォルトコンフィグ
170
+ /// VMDインポートのコンフィグ
144
171
/// </summary>
145
172
[ Serializable ]
146
- public class DefaultVMDImportConfig : ConfigBase
173
+ public class VMDImportConfig : ConfigBase
147
174
{
148
- public bool createAnimationFile ;
149
- public int interpolationQuality ;
175
+ public bool createAnimationFile = false ;
176
+ public int interpolationQuality = 1 ;
150
177
151
- public DefaultVMDImportConfig ( )
178
+ public override string GetTitle ( )
152
179
{
153
- this . title = "Default VMD Import Config" ;
180
+ return "Default VMD Import Config" ;
154
181
}
155
182
156
- public override void OnGUI ( )
183
+ public override void OnGUIFunction ( )
157
184
{
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 ( ) ;
164
192
}
165
193
}
166
194
@@ -169,11 +197,6 @@ public override void OnGUI()
169
197
/// </summary>
170
198
public class ConfigBase
171
199
{
172
- /// <summary>
173
- /// このコンフィグのタイトルを指定します
174
- /// </summary>
175
- protected string title = "" ;
176
-
177
200
/// <summary>
178
201
/// 開け閉めの状態
179
202
/// </summary>
@@ -182,19 +205,28 @@ public class ConfigBase
182
205
/// <summary>
183
206
/// GUI処理を行います
184
207
/// </summary>
185
- /// <param name="OnGUIFunction">引数・戻り値なしのラムダ式</param>
186
- public void OnGUI ( Action OnGUIFunction )
208
+ public void OnGUI ( )
187
209
{
210
+ var title = GetTitle ( ) ;
188
211
fold = EditorGUILayout . Foldout ( fold , title ) ;
189
- if ( fold )
212
+ if ( fold ) {
190
213
OnGUIFunction ( ) ;
214
+ }
191
215
EditorGUILayout . Space ( ) ;
192
216
}
193
217
218
+ /// <summary>
219
+ /// このコンフィグのタイトルを取得します
220
+ /// </summary>
221
+ public virtual string GetTitle ( )
222
+ {
223
+ return "" ;
224
+ }
225
+
194
226
/// <summary>
195
227
/// GUI処理を行います
196
228
/// </summary>
197
- public virtual void OnGUI ( )
229
+ public virtual void OnGUIFunction ( )
198
230
{
199
231
}
200
232
}
0 commit comments