Skip to content

Commit

Permalink
Merge pull request #29 from ayutaz/develop
Browse files Browse the repository at this point in the history
v1.0
  • Loading branch information
ayutaz authored Apr 2, 2023
2 parents fc6a019 + 4c8908f commit e77a60f
Show file tree
Hide file tree
Showing 24 changed files with 417 additions and 167 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
unityVersion:
- 2021.3.16f1
targetPlatform:
- StandaloneWindows64
- WebGL
timeout-minutes: 15
steps:
- name: Checkout
Expand All @@ -45,11 +45,15 @@ jobs:
buildMethod: ${{ env.BUILD_METHOD }}
unityVersion: ${{ matrix.unityVersion }}
targetPlatform: ${{ matrix.targetPlatform }}
buildPath: src/Unity

- name: Release
uses: softprops/action-gh-release@v1
with:
draft: true
generate_release_notes: true
name: ${{ github.event.pull_request.body }}
tag_name: ${{ github.event.pull_request.title }}
prerelease: false
prerelease: false
files: |
build/${{ env.FILE_NAME }}.unitypackage
File renamed without changes.
62 changes: 62 additions & 0 deletions Assets/Editor/PackageExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

public static class PackageExporter
{
private const string RootDirectory = "Assets/KoeiromapUnity/Scripts";
private const string FileName = "KoeiromapUnity";

/// <summary>
/// パッケージの書き出し(エディタ上でのテスト用)
/// メニュー 「Tools > Export Unitypackage Test」をクリックで実行
/// </summary>
[MenuItem("Tools/Export Unitypackage Test")]
public static void ExportTestOnEditor()
{
var exportPath = EditorUtility.SaveFilePanel
(
"保存先を選択",
Application.dataPath,
$"{FileName}.unitypackage",
"unitypackage"
);

CreatePackage(RootDirectory, exportPath);
}

/// <summary>
/// パッケージの書き出し
/// GitHub Actionsから呼ばれる
/// </summary>
public static void Export()
{
CreatePackage(RootDirectory, $"build/{FileName}.unitypackage");
}

private static void CreatePackage(string rootDirectory, string exportPath)
{
SafeCreateDirectory(exportPath);
var assetsPaths = GetAllAssetsAtPath(rootDirectory);
AssetDatabase.ExportPackage(assetsPaths, exportPath, ExportPackageOptions.Default);
Debug.Log(
$"Export complete: {Path.GetFullPath(exportPath)}\nExport below files:\n{string.Join("\n", assetsPaths)}");
}

private static DirectoryInfo SafeCreateDirectory(string path)
{
var diParent = Directory.GetParent(path);
if (diParent == null || Directory.Exists(diParent.FullName)) return null;
return Directory.CreateDirectory(diParent.FullName);
}

private static string[] GetAllAssetsAtPath(string root)
{
return Directory.GetFiles(root, "*", SearchOption.AllDirectories)
.Where(x => !string.IsNullOrEmpty(x))
.Where(x => !x.EndsWith(".meta"))
.Where(x => x != ".DS_Store")
.ToArray();
}
}
File renamed without changes.
65 changes: 0 additions & 65 deletions Assets/KoeiromapUnity/Editor/PackageExporter.cs

This file was deleted.

25 changes: 21 additions & 4 deletions Assets/KoeiromapUnity/Sample/Sample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO;
using System.Threading;
using KoeiromapUnity.Scripts;
using KoeiromapUnity.Core;
using KoeiromapUnity.Util;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -9,7 +11,6 @@ namespace KoeiromapUnity.Sample
[RequireComponent(typeof(AudioSource))]
public class Sample : MonoBehaviour
{
private AudioSource _audioSource;
[SerializeField] private TMP_InputField inputText;
[SerializeField] private Slider xValueSlider;
[SerializeField] private TMP_InputField xValueInputValue;
Expand All @@ -18,6 +19,9 @@ public class Sample : MonoBehaviour
[SerializeField] private TMP_Dropdown talkStyleDropdown;
[SerializeField] private TMP_InputField seed;
[SerializeField] private Button playVoiceButton;
[SerializeField] private Button saveVoiceButton;
private AudioSource _audioSource;
private string _audioStringData;
private CancellationTokenSource _cancellationTokenSource;

private void Awake()
Expand Down Expand Up @@ -55,11 +59,24 @@ private void Start()
style = talkStyleDropdown.options[talkStyleDropdown.value].text,
seed = seed.text?.Length > 0 ? seed.text : Random.Range(-99999, 99999).ToString()
};
var option = new Option($"{Application.dataPath}/voice");
var voice = await KoeiromapExtensions.GetVoice(voiceParam, _cancellationTokenSource.Token, option);
var voice = await Koeiromap.GetVoice(voiceParam, _cancellationTokenSource.Token);
_audioSource.clip = voice.audioClip;
_audioStringData = voice.audioBase64;
_audioSource.Play();

saveVoiceButton.interactable = true;
});

#if UNITY_STANDALONE
var folderPath = Path.Combine(Application.persistentDataPath, "yousan", "koeiromap-unity");
var token = _cancellationTokenSource.Token;
saveVoiceButton.onClick.AddListener(() =>
{
AudioFile.Save(_audioStringData, folderPath, "test.wav", token);
});
#elif UNITY_WEBGL
saveVoiceButton.gameObject.SetActive(false);
#endif
}

private void OnDestroy()
Expand Down
Loading

0 comments on commit e77a60f

Please sign in to comment.