Created
November 14, 2016 08:12
-
-
Save tsubaki/3ebcc4e684c12dc2e511e9900c901f86 to your computer and use it in GitHub Desktop.
AnimationClipの最後の座標・回転を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
using UnityEditor; | |
using System.Linq; | |
using UnityEngine.Assertions; | |
[CreateAssetMenu] | |
public class GetClipInfomation : ScriptableObject { | |
// 検証するAnimationClip | |
[Header("IN")] | |
[SerializeField] AnimationClip clip = null; | |
// 結果を格納 | |
[Header("RESULT")] | |
[SerializeField] Vector3 position; | |
[SerializeField] Quaternion rotation; | |
[ContextMenu("Do")] | |
void Do() | |
{ | |
// AnimationClipよりカーブ一覧を取得 | |
// カーブに格納されているプロパティ名がわからないならば、bridge.propertyNameで確認 | |
var bridges = AnimationUtility.GetCurveBindings (clip); | |
// foreach( var bridge in bridges){ | |
// Debug.Log (bridge.propertyName); | |
// } | |
// 指定座標の最初と最後を取得 | |
// 回転はlocalEulerAnglesRaw もしくは 他のパラメータ名(bridges.propertyNameで確認) | |
// 移動も回転もしていないならエラーになる(要例外処理) | |
var localPositionXCurve = AnimationUtility.GetEditorCurve (clip, bridges.First (c => c.path == string.Empty && c.propertyName.StartsWith ("m_LocalPosition.x"))); | |
var localPositionYCurve = AnimationUtility.GetEditorCurve (clip, bridges.First (c => c.path == string.Empty && c.propertyName.StartsWith ("m_LocalPosition.y"))); | |
var localPositionZCurve = AnimationUtility.GetEditorCurve (clip, bridges.First (c => c.path == string.Empty && c.propertyName.StartsWith ("m_LocalPosition.z"))); | |
var localRotationXCurve = AnimationUtility.GetEditorCurve (clip, bridges.First (c => c.path == string.Empty && c.propertyName.StartsWith ("localEulerAnglesRaw.x"))); | |
var localRotationYCurve = AnimationUtility.GetEditorCurve (clip, bridges.First (c => c.path == string.Empty && c.propertyName.StartsWith ("localEulerAnglesRaw.y"))); | |
var localRotationZCurve = AnimationUtility.GetEditorCurve (clip, bridges.First (c => c.path == string.Empty && c.propertyName.StartsWith ("localEulerAnglesRaw.z"))); | |
// 座標と回転の移動値を取得 | |
position= new Vector3 ( | |
localPositionXCurve.length != 0 ? localPositionXCurve.keys [localPositionXCurve.length - 1].value - localPositionXCurve [0].value : 0, | |
localPositionYCurve.length != 0 ? localPositionYCurve.keys [localPositionYCurve.length - 1].value - localPositionYCurve [0].value : 0, | |
localPositionZCurve.length != 0 ? localPositionZCurve.keys [localPositionZCurve.length - 1].value - localPositionZCurve [0].value : 0); | |
rotation = Quaternion.Euler ( | |
localRotationXCurve.length != 0 ? localRotationXCurve.keys [localRotationXCurve.length - 1].value - localRotationXCurve [0].value : 0, | |
localRotationYCurve.length != 0 ? localRotationYCurve.keys [localRotationYCurve.length - 1].value - localRotationYCurve [0].value : 0, | |
localRotationZCurve.length != 0 ? localRotationZCurve.keys [localRotationZCurve.length - 1].value - localRotationZCurve [0].value : 0); | |
} | |
} |
Author
tsubaki
commented
Nov 14, 2016
- Assets/Create/GetClipInfomationよりClip登録用のアセットを取得
- INに調べたいAnimationClipを登録
- ギア(Reset等がある)マークより「Do」を選択
- 移動距離と回転がResultに表示される
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment