0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DazStudioの人型モデルの服装をUnity上で操作する

Last updated at Posted at 2022-11-25

概要

DazStudioの人型モデルGenesis8が着ている服をUnity上で操作します。

環境

Unity:2021.3.9
DazStudio:4.21
IDE:Rider
UniTask:2.3.3

DazStudioでの操作-Unityにエクスポートするまで

DazToUnityのインストール

https://www.daz3d.com/daz-to-unity-bridge
無料
要ユーザー登録

Unityへエクスポートする

適当に服を着せたGenesis8をエクスポートします。
上部ツールバーのFile→Send To→ Daz to Unityを選択します。
ウィンドウが表示されるので、下の画像になるように設定します。
UnityAssets Folderは対応するUnityプロジェクトのパスにします。

image.png

AcceptButtonを押すとエクスポートが始まります。
下のGIFアニメはエクスポートが成功したときの様子です。
DazExportSuccess.gif

Unity上での操作

フォルダのPrefabをシーンに持っていく

エクスポート後ピンク色のオブジェクトが生成されますが、削除します。
image.png

Asset/Daz3D/ExportName/**_baseファイルをシーンに持っていきます。
image.png

スクリプト作成

服の切り替えをするGUIを作成します。
Unitaskを使ってボタンの制御をします。

コード

OutfitChangePresenter.cs
using UnityEngine;
using UnityEngine.UI;
using System.Threading;
using Cysharp.Threading.Tasks;

public class OutfitChangePresenter : MonoBehaviour
{
    [Header("TankTops")] 
    [SerializeField] private Button _tankTopButton;
    [SerializeField] private GameObject _blackShirt;
    [SerializeField] private GameObject _blackPants;
    
    [Header("skirt and dress")]
    [SerializeField] private Button _skirtButton;
    [SerializeField] private GameObject _skirt;
    [SerializeField] private GameObject _dress;

    void Start()
    {
        var token = this.GetCancellationTokenOnDestroy();

        WaitForTankTopButton(token).Forget();
        WaitForSkirtButton(token).Forget();
    }


    private async UniTaskVoid WaitForTankTopButton(CancellationToken token)
    {
        while (true)
        {
            using var handler = _tankTopButton.onClick.GetAsyncEventHandler(CancellationToken.None);
            await _tankTopButton.OnClickAsync();
            allOff();
            _blackPants.SetActive(true);
            _blackShirt.SetActive(true);    
        }
    }

    private async UniTaskVoid WaitForSkirtButton(CancellationToken token)
    {
        while (true)
        {
            using var handler = _skirtButton.onClick.GetAsyncEventHandler(CancellationToken.None);
            await _skirtButton.OnClickAsync();
            allOff();
            _dress.SetActive(true);
            _skirt.SetActive(true);
        }
    }
    private void allOff()
    {
        _blackShirt.SetActive(false);
        _blackPants.SetActive(false);
        _dress.SetActive(false);
        _skirt.SetActive(false);
    }
}

インスペクター上の変数

image.png

完成

DazUnityOutput.gif

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?