Skip to content

Commit de6d097

Browse files
committed
Merge pull request #37 from mmd-for-unity-proj/2.1b
2.1b
2 parents d944c94 + 0f09d30 commit de6d097

38 files changed

+3403
-2068
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*.csproj
77
*.unityproj
88
*.sln
9+
*.asset

Editor/Config/Config.asset

4 Bytes
Binary file not shown.

Editor/Config/Config.cs

+101-69
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using UnityEngine;
1+
using UnityEngine;
22
using UnityEditor;
33
using System;
44
using 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
}

Editor/Config/ConfigWindow.cs

+3-22
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ namespace MMD
55
{
66
public class ConfigWindow : EditorWindow
77
{
8-
private static Config config;
9-
private static string path;
8+
private Config config;
109

11-
[MenuItem("Plugins/MMD Loader/Config")]
10+
[MenuItem("MMD for Unity/Config")]
1211
public static void Init()
1312
{
1413
GetWindow<ConfigWindow>("MFU Config");
@@ -18,36 +17,18 @@ public static void Init()
1817
// フォーカスが外れて戻ってきたときや再度開かれたときなど
1918
void OnEnable()
2019
{
21-
// オブジェクトを「Hierarchy」に表示しない。また、アセットの中にあれば、プロジェクトビューに表示しない
22-
// オブジェクトがシーンに保存されない。また、新しいシーンを読んでも、オブジェクトが破棄されない
23-
hideFlags = HideFlags.HideAndDontSave;
24-
2520
if (config == null)
2621
{
2722
// 読み込む
2823
config = MMD.Config.LoadAndCreate();
29-
30-
// なかったら作成する
31-
if (config == null)
32-
{
33-
path = MMD.Config.GetConfigPath();
34-
config = CreateInstance<Config>();
35-
AssetDatabase.CreateAsset(config, path);
36-
EditorUtility.SetDirty(config);
37-
}
3824
}
3925
}
4026

4127
// ウィンドウの描画処理
4228
void OnGUI()
4329
{
44-
// たいとる
45-
EditorGUILayout.LabelField("MMD for Unity Configuration");
46-
EditorGUILayout.Space();
47-
4830
// あとは任せる
4931
config.OnGUI();
50-
5132
}
5233
}
53-
}
34+
}

Editor/ExpressionManagerEditor.cs

+4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public override void OnInspectorGUI()
7171
if (child.localPosition.z != value) {
7272
//変更が掛かったなら
7373
//Undo登録
74+
#if !UNITY_4_2 //4.3以降
75+
Undo.RecordObject(child, "Expression Change");
76+
#else
7477
Undo.RegisterUndo(child, "Expression Change");
78+
#endif
7579
//Z位置更新
7680
Vector3 position = child.localPosition;
7781
position.z = value;

0 commit comments

Comments
 (0)