Skip to content

Commit

Permalink
feat: AnimationSampleを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
pspkurara committed Sep 8, 2020
1 parent 74768b2 commit 36469f0
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Packages/uGUI-Skinner/Editor/SkinContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static class SkinContent
public static readonly GUIContent Enabled = new GUIContent("Enabled");
public static readonly GUIContent LocalRotation = new GUIContent("Local Rotation");
public static readonly GUIContent LocalScale = new GUIContent("Local Scale");
public static readonly GUIContent RootGameObject = new GUIContent("Root Game Object");
public static readonly GUIContent AnimationClip = new GUIContent("Animation Clip");
public static readonly GUIContent SampleTime = new GUIContent("Sample Time");

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using UnityEngine;
using UnityEditor;

namespace Pspkurara.UI.Skinner
{

[SkinPartsInspector(typeof(AnimationSample))]
public sealed class AnimationSampleInspector : ISkinPartsInspector
{
public void CleanupFields(EditorSkinPartsPropertry property)
{
SkinnerEditorUtility.CleanArray(property.objectReferenceValues, AnimationSample.ObjectLength);
SkinnerEditorUtility.CleanObject<GameObject>(property.objectReferenceValues, AnimationSample.GameObjectIndex);
SkinnerEditorUtility.CleanObject<AnimationClip>(property.objectReferenceValues, AnimationSample.AnimationClipIndex);
SkinnerEditorUtility.CleanArray(property.boolValues);
SkinnerEditorUtility.CleanArray(property.colorValues);
SkinnerEditorUtility.CleanArray(property.floatValues, AnimationSample.FloatLength);
SkinnerEditorUtility.CleanArray(property.intValues);
SkinnerEditorUtility.CleanArray(property.vector4Values);
}

public void DrawInspector(EditorSkinPartsPropertry property)
{
SkinnerEditorUtility.ResetArray(property.objectReferenceValues, AnimationSample.ObjectLength);
SkinnerEditorUtility.ResetArray(property.floatValues, AnimationSample.FloatLength);
var gameObjectProperty = property.objectReferenceValues.GetArrayElementAtIndex(AnimationSample.GameObjectIndex);
var animationClipProperty = property.objectReferenceValues.GetArrayElementAtIndex(AnimationSample.AnimationClipIndex);
var timeProperty = property.floatValues.GetArrayElementAtIndex(AnimationSample.TimeIndex);
gameObjectProperty.objectReferenceValue = EditorGUILayout.ObjectField(SkinContent.RootGameObject, gameObjectProperty.objectReferenceValue, typeof(GameObject), true);
animationClipProperty.objectReferenceValue = EditorGUILayout.ObjectField(SkinContent.AnimationClip, animationClipProperty.objectReferenceValue, typeof(AnimationClip), false);
if (!animationClipProperty.hasMultipleDifferentValues && animationClipProperty.objectReferenceValue is AnimationClip)
{
var clip = animationClipProperty.objectReferenceValue as AnimationClip;
EditorGUILayout.Slider(timeProperty, 0, clip.length, SkinContent.SampleTime);
}
else
{
bool showMixedValue = EditorGUI.showMixedValue;
if (timeProperty.hasMultipleDifferentValues)
{
EditorGUI.showMixedValue = true;
}
timeProperty.floatValue = EditorGUILayout.FloatField(SkinContent.SampleTime, timeProperty.floatValue);
EditorGUI.showMixedValue = showMixedValue;
}
}

}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions Packages/uGUI-Skinner/Runtime/SkinParts/AnimationSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using UnityEngine;

namespace Pspkurara.UI.Skinner
{

[SkinParts(SkinPartsType.AnimationSample, typeof(AnimationSample), typeof(Logic))]
public static class AnimationSample
{

public const int GameObjectIndex = 0;
public const int AnimationClipIndex = 1;
public const int TimeIndex = 0;
public const int ObjectLength = AnimationClipIndex + 1;
public const int FloatLength = TimeIndex + 1;

/// <summary>
/// 適応ロジック
/// </summary>
internal sealed class Logic : ISkinLogic
{

private GameObject rootGameObject = null;
private AnimationClip animationClip = null;
private float activeTime;

/// <summary>
/// 値をオブジェクトに反映させる
/// </summary>
/// <param name="property">プロパティ</param>
public void SetValues(SkinPartsPropertry property)
{
//値がないなら何もしない
if (property.objectReferenceValues.Count < ObjectLength) return;
if (!rootGameObject)
{
rootGameObject = property.objectReferenceValues[GameObjectIndex] as GameObject;
//空か型違いのため処理終了
if (!rootGameObject) return;
}
if (!animationClip)
{
animationClip = property.objectReferenceValues[AnimationClipIndex] as AnimationClip;
//空か型違いのため処理終了
if (!animationClip) return;
}
//値がないなら何もしない
if (property.floatValues.Count < FloatLength) return;
activeTime = property.floatValues[TimeIndex];
animationClip.SampleAnimation(rootGameObject, activeTime);
}

}

/// <summary>
/// 対象のスキンパーツを生成
/// </summary>
/// <param name="rootGameObject">ルートとなるGameObject</param>
/// <param name="animationClip">アニメーションクリップ</param>
/// <param name="time">クリップをサンプルする時間</param>
/// <returns>生成したスキンパーツ</returns>
public static SkinParts CreateSkinParts(GameObject rootGameObject, AnimationClip animationClip, float time)
{
var parts = new SkinParts();
SkinnerUtility.ResetObjectReference(parts.property.objectReferenceValues, ObjectLength);
SkinnerUtility.ResetFloat(parts.property.floatValues, FloatLength);
parts.property.objectReferenceValues[GameObjectIndex] = rootGameObject;
parts.property.objectReferenceValues[AnimationClipIndex] = animationClip;
parts.property.floatValues[TimeIndex] = time;
return parts;
}

}

}
11 changes: 11 additions & 0 deletions Packages/uGUI-Skinner/Runtime/SkinParts/AnimationSample.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Packages/uGUI-Skinner/Runtime/SkinPartsType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public enum SkinPartsType

TransformRotation = 12,
TransformScale = 13,

AnimationSample = 20,
}

}

0 comments on commit 36469f0

Please sign in to comment.