以下の内容はhttps://indie-du.com/entry/2021/08/16/181205より取得しました。


Unity : シーン編集中にAnimator付き3Dモデルにポーズをとらせる

シーン内にオブジェクトを配置している際、人物モデルのAnimatorに設定してあるアニメーションのポーズをとらせたかったのに方法がわからなかったので、
スクリプトで強引に解決した。

下のようなかんじで、レイヤーが二つあるAnimatorを適用した人物モデルの場合。

f:id:sugar_affordance:20210816180923p:plain f:id:sugar_affordance:20210816180611p:plain

以下のスクリプトをAnimatorをもったモデルに適用。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[System.Serializable]
struct PoseAnimatorSetting {
    public string LayerName;
    public string StateName;
}

public class ApplyAnimatorPoseInScene : MonoBehaviour
{
#if UNITY_EDITOR
    [SerializeField]
    List<PoseAnimatorSetting> PoseAnimatorSettingList;

    [SerializeField]
    public float poseTimeInClip;

    private void OnValidate()
    {
        var animator = GetComponent<Animator>();
        foreach(var p in PoseAnimatorSettingList)
        {
            animator.PlayInFixedTime(p.StateName, animator.GetLayerIndex(p.LayerName), poseTimeInClip);
        }
        animator.Update(poseTimeInClip);
    }

#endif
}

インスペクタでポーズをとらせるアニメーションを設定する。

f:id:sugar_affordance:20210816180710p:plain

シーン編集中に自動でポーズとってくれるようになる。

f:id:sugar_affordance:20210816180826p:plain

そもエディタにこういう機能あるかも。しらん。




以上の内容はhttps://indie-du.com/entry/2021/08/16/181205より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14