Skip to content

Commit

Permalink
Implement export as .json (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitimeago committed Aug 31, 2024
1 parent 01ec52e commit 5b202ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public override void OnInspectorGUI()
if (GUILayout.Button(L.Tr("MappingsEditor:ShareMenuLabel")))
{
var menu = new GenericMenu();
menu.AddItem(new GUIContent(L.Tr("MappingsEditor:ShareAsUnitypackage")), false, () => ExportPackage(data));
menu.AddItem(new GUIContent(L.Tr("MappingsEditor:ShareAsUnitypackage")), false, () => ExportAsPackage(data));
menu.AddItem(new GUIContent(L.Tr("MappingsEditor:ExportAsJson")), false, () => ExportAsJson(data, SafeFilename(avatar.name)));
menu.ShowAsContext();
}
GUI.enabled = true;
Expand All @@ -161,14 +162,39 @@ public override void OnInspectorGUI()
}
}

private void ExportPackage(BlendShapeMappings mappingsComponent)
private string SafeFilename(string name)
{
foreach (char c in Path.GetInvalidFileNameChars())
{
name = name.Replace(c, '_');
}
return name;
}

private void ExportAsJson(BlendShapeMappings mappingsComponent, string defaultName)
{
string jsonPath = EditorUtility.SaveFilePanel(
L.Tr("SaveFilePanel:SaveJson"),
"",
defaultName,
"json");
if (string.IsNullOrEmpty(jsonPath))
{
return;
}

string json = JsonUtility.ToJson(mappingsComponent, prettyPrint: true);

File.WriteAllText(jsonPath, json);
}

private void ExportAsPackage(BlendShapeMappings mappingsComponent)
{
string packagePath = EditorUtility.SaveFilePanel(
L.Tr("SaveFilePanel:SaveUnitypackage"),
"",
"",
"unitypackage");

if (string.IsNullOrEmpty(packagePath))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ msgstr "More..."
msgid "MappingsEditor:ShareAsUnitypackage"
msgstr "Share as .unitypackage..."

msgid "MappingsEditor:ExportAsJson"
msgstr "Export as .json..."

msgid "MappingsEditor:ShowStoredData"
msgstr "Show stored data"

Expand Down Expand Up @@ -152,6 +155,9 @@ msgstr "OK"
msgid "SaveFilePanel:SaveUnitypackage"
msgstr "Save .unitypackage"

msgid "SaveFilePanel:SaveJson"
msgstr "Save .json"

msgid "WriteDefaultsComponentEditor:ForceAvatarWriteDefaultsOn"
msgstr "Force all FX Write Defaults ON"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ msgstr "その他..."
msgid "MappingsEditor:ShareAsUnitypackage"
msgstr ".unitypackageで共有する..."

msgid "MappingsEditor:ExportAsJson"
msgstr ".jsonでエクスポートする..."

msgid "MappingsEditor:ShowStoredData"
msgstr "保存データを表示"

Expand Down

0 comments on commit 5b202ef

Please sign in to comment.