Unity-jump-proj
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99cf1b3a0e275374e8089864ccbad5bb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Timeline.Samples.Tween.Editor",
|
||||
"references": [
|
||||
"GUID:f06555f75b070af458a003d92f9efb00",
|
||||
"GUID:02f771204943f4a40949438e873e3eff",
|
||||
"GUID:5aa8f7d60b800d541918c447feb05a5a"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75818fc8ec6b2c64793fde0cb60c9172
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,45 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Timeline;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace Timeline.Samples
|
||||
{
|
||||
// Editor used by the TimelineEditor to customize the view of TweenClip.
|
||||
[CustomTimelineEditor(typeof(TweenClip))]
|
||||
public class TweenClipEditor : ClipEditor
|
||||
{
|
||||
static GUIStyle s_StartTextStyle;
|
||||
static GUIStyle s_EndTextStyle;
|
||||
|
||||
static TweenClipEditor()
|
||||
{
|
||||
s_StartTextStyle = GUI.skin.label;
|
||||
s_EndTextStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleRight };
|
||||
}
|
||||
|
||||
// Called by the Timeline editor to draw the background of a TweenClip.
|
||||
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
|
||||
{
|
||||
TweenClip asset = clip.asset as TweenClip;
|
||||
|
||||
if (asset == null)
|
||||
return;
|
||||
|
||||
PlayableDirector director = TimelineEditor.inspectedDirector;
|
||||
|
||||
if (director == null)
|
||||
return;
|
||||
|
||||
Transform startLocation = director.GetReferenceValue(asset.startLocation.exposedName, out bool startFound) as Transform;
|
||||
Transform endLocation = director.GetReferenceValue(asset.endLocation.exposedName, out bool endFound) as Transform;
|
||||
|
||||
if (startFound && startLocation != null)
|
||||
EditorGUI.LabelField(region.position, startLocation.gameObject.name, s_StartTextStyle);
|
||||
|
||||
if (endFound && endLocation != null)
|
||||
EditorGUI.LabelField(region.position, endLocation.gameObject.name, s_EndTextStyle);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 516ce7ed748647adb925b7fe7ef3f62c
|
||||
timeCreated: 1598901529
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Timeline.Samples.Tween",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:f06555f75b070af458a003d92f9efb00",
|
||||
"GUID:ef63a73cb159aa04997399c27d4eb08a"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aa8f7d60b800d541918c447feb05a5a
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace Timeline.Samples
|
||||
{
|
||||
// Runtime representation of a Tween clip.
|
||||
public class TweenBehaviour : PlayableBehaviour
|
||||
{
|
||||
public Transform startLocation;
|
||||
public Transform endLocation;
|
||||
|
||||
public bool shouldTweenPosition;
|
||||
public bool shouldTweenRotation;
|
||||
|
||||
public AnimationCurve curve;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f0eb50896365654fb42c382b2474356
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace Timeline.Samples
|
||||
{
|
||||
// Represents the serialized data for a clip on the Tween track
|
||||
[Serializable]
|
||||
[DisplayName("Tween Clip")]
|
||||
public class TweenClip : PlayableAsset, ITimelineClipAsset, IPropertyPreview
|
||||
{
|
||||
public ExposedReference<Transform> startLocation;
|
||||
public ExposedReference<Transform> endLocation;
|
||||
|
||||
[Tooltip("Changes the position of the assigned object")]
|
||||
public bool shouldTweenPosition = true;
|
||||
|
||||
[Tooltip("Changes the rotation of the assigned object")]
|
||||
public bool shouldTweenRotation = true;
|
||||
|
||||
[Tooltip("Only keys in the [0,1] range will be used")]
|
||||
public AnimationCurve curve = AnimationCurve.EaseInOut(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
// Implementation of ITimelineClipAsset. This specifies the capabilities of this timeline clip inside the editor.
|
||||
public ClipCaps clipCaps
|
||||
{
|
||||
get { return ClipCaps.Blending; }
|
||||
}
|
||||
|
||||
// Creates the playable that represents the instance of this clip.
|
||||
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
|
||||
{
|
||||
// create a new TweenBehaviour
|
||||
ScriptPlayable<TweenBehaviour> playable = ScriptPlayable<TweenBehaviour>.Create(graph);
|
||||
TweenBehaviour tween = playable.GetBehaviour();
|
||||
|
||||
// set the behaviour's data
|
||||
tween.startLocation = startLocation.Resolve(graph.GetResolver());
|
||||
tween.endLocation = endLocation.Resolve(graph.GetResolver());
|
||||
tween.curve = curve;
|
||||
tween.shouldTweenPosition = shouldTweenPosition;
|
||||
tween.shouldTweenRotation = shouldTweenRotation;
|
||||
|
||||
return playable;
|
||||
}
|
||||
|
||||
// Defines which properties are changed by this playable. Those properties will be reverted in editmode
|
||||
// when Timeline's preview is turned off.
|
||||
public void GatherProperties(PlayableDirector director, IPropertyCollector driver)
|
||||
{
|
||||
const string kLocalPosition = "m_LocalPosition";
|
||||
const string kLocalRotation = "m_LocalRotation";
|
||||
|
||||
driver.AddFromName<Transform>(kLocalPosition + ".x");
|
||||
driver.AddFromName<Transform>(kLocalPosition + ".y");
|
||||
driver.AddFromName<Transform>(kLocalPosition + ".z");
|
||||
driver.AddFromName<Transform>(kLocalRotation + ".x");
|
||||
driver.AddFromName<Transform>(kLocalRotation + ".y");
|
||||
driver.AddFromName<Transform>(kLocalRotation + ".z");
|
||||
driver.AddFromName<Transform>(kLocalRotation + ".w");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4631aac3e8958e840855eeec9cd45ec5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,128 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
|
||||
namespace Timeline.Samples
|
||||
{
|
||||
// The runtime instance of a Tween track. It is responsible for blending and setting
|
||||
// the final data on the transform binding.
|
||||
public class TweenMixerBehaviour : PlayableBehaviour
|
||||
{
|
||||
static AnimationCurve s_DefaultCurve = AnimationCurve.Linear(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
bool m_ShouldInitializeTransform = true;
|
||||
Vector3 m_InitialPosition;
|
||||
Quaternion m_InitialRotation;
|
||||
|
||||
// Performs blend of position and rotation of all clips connected to a track mixer
|
||||
// The result is applied to the track binding's (playerData) transform.
|
||||
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
|
||||
{
|
||||
Transform trackBinding = playerData as Transform;
|
||||
|
||||
if (trackBinding == null)
|
||||
return;
|
||||
|
||||
// Get the initial position and rotation of the track binding, only when ProcessFrame is first called
|
||||
InitializeIfNecessary(trackBinding);
|
||||
|
||||
Vector3 accumPosition = Vector3.zero;
|
||||
Quaternion accumRotation = QuaternionUtils.zero;
|
||||
|
||||
float totalPositionWeight = 0.0f;
|
||||
float totalRotationWeight = 0.0f;
|
||||
|
||||
// Iterate on all mixer's inputs (ie each clip on the track)
|
||||
int inputCount = playable.GetInputCount();
|
||||
for (int i = 0; i < inputCount; i++)
|
||||
{
|
||||
float inputWeight = playable.GetInputWeight(i);
|
||||
if (inputWeight <= 0)
|
||||
continue;
|
||||
|
||||
Playable input = playable.GetInput(i);
|
||||
float normalizedInputTime = (float)(input.GetTime() / input.GetDuration());
|
||||
|
||||
// get the clip's behaviour and evaluate the progression along the curve
|
||||
TweenBehaviour tweenInput = GetTweenBehaviour(input);
|
||||
float tweenProgress = GetCurve(tweenInput).Evaluate(normalizedInputTime);
|
||||
|
||||
// calculate the position's progression along the curve according to the input's (clip) weight
|
||||
if (tweenInput.shouldTweenPosition)
|
||||
{
|
||||
totalPositionWeight += inputWeight;
|
||||
accumPosition += TweenPosition(tweenInput, tweenProgress, inputWeight);
|
||||
}
|
||||
|
||||
// calculate the rotation's progression along the curve according to the input's (clip) weight
|
||||
if (tweenInput.shouldTweenRotation)
|
||||
{
|
||||
totalRotationWeight += inputWeight;
|
||||
accumRotation = TweenRotation(tweenInput, accumRotation, tweenProgress, inputWeight);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the final position and rotation values in the track binding
|
||||
trackBinding.position = accumPosition + m_InitialPosition * (1.0f - totalPositionWeight);
|
||||
trackBinding.rotation = accumRotation.Blend(m_InitialRotation, 1.0f - totalRotationWeight);
|
||||
trackBinding.rotation.Normalize();
|
||||
}
|
||||
|
||||
void InitializeIfNecessary(Transform transform)
|
||||
{
|
||||
if (m_ShouldInitializeTransform)
|
||||
{
|
||||
m_InitialPosition = transform.position;
|
||||
m_InitialRotation = transform.rotation;
|
||||
m_ShouldInitializeTransform = false;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 TweenPosition(TweenBehaviour tweenInput, float progress, float weight)
|
||||
{
|
||||
Vector3 startPosition = m_InitialPosition;
|
||||
if (tweenInput.startLocation != null)
|
||||
{
|
||||
startPosition = tweenInput.startLocation.position;
|
||||
}
|
||||
|
||||
Vector3 endPosition = m_InitialPosition;
|
||||
if (tweenInput.endLocation != null)
|
||||
{
|
||||
endPosition = tweenInput.endLocation.position;
|
||||
}
|
||||
|
||||
return Vector3.Lerp(startPosition, endPosition, progress) * weight;
|
||||
}
|
||||
|
||||
Quaternion TweenRotation(TweenBehaviour tweenInput, Quaternion accumRotation, float progress, float weight)
|
||||
{
|
||||
Quaternion startRotation = m_InitialRotation;
|
||||
if (tweenInput.startLocation != null)
|
||||
{
|
||||
startRotation = tweenInput.startLocation.rotation;
|
||||
}
|
||||
|
||||
Quaternion endRotation = m_InitialRotation;
|
||||
if (tweenInput.endLocation != null)
|
||||
{
|
||||
endRotation = tweenInput.endLocation.rotation;
|
||||
}
|
||||
|
||||
Quaternion desiredRotation = Quaternion.Lerp(startRotation, endRotation, progress);
|
||||
return accumRotation.Blend(desiredRotation.NormalizeSafe(), weight);
|
||||
}
|
||||
|
||||
static TweenBehaviour GetTweenBehaviour(Playable playable)
|
||||
{
|
||||
ScriptPlayable<TweenBehaviour> tweenInput = (ScriptPlayable<TweenBehaviour>)playable;
|
||||
return tweenInput.GetBehaviour();
|
||||
}
|
||||
|
||||
static AnimationCurve GetCurve(TweenBehaviour tween)
|
||||
{
|
||||
if (tween == null || tween.curve == null)
|
||||
return s_DefaultCurve;
|
||||
return tween.curve;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 194be6b0be042ee47836baea94946cac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace Timeline.Samples
|
||||
{
|
||||
// A track that allows the user to do simple transform movements.
|
||||
// It demonstrates how to define a custom track mixer in order to support blending of clips.
|
||||
[TrackColor(1.0f, 0.0f, 0.0f)]
|
||||
[TrackBindingType(typeof(Transform))]
|
||||
[TrackClipType(typeof(TweenClip))]
|
||||
public class TweenTrack : TrackAsset
|
||||
{
|
||||
// Creates a runtime instance of the track, represented by a PlayableBehaviour.
|
||||
// The runtime instance performs mixing on the clips.
|
||||
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
|
||||
{
|
||||
return ScriptPlayable<TweenMixerBehaviour>.Create(graph, inputCount);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09378b61d40beb649987d80408ad99b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user