Skip to content

Commit

Permalink
job animation
Browse files Browse the repository at this point in the history
  • Loading branch information
huailiang committed Jul 8, 2020
1 parent e403e3c commit 35f229a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
16 changes: 10 additions & 6 deletions Assets/timeline/Runtime/XTimeline.cs
Expand Up @@ -92,15 +92,17 @@ public float Duration

public XTimeline(TimelineConfig conf, PlayMode mode)
{
Initial(conf, mode, false);
blending = false;
Initial(conf, mode);
}

public XTimeline(string path, PlayMode mode)
{
blending = false;
ReadConf(path);
if (config != null)
{
Initial(config, mode, false);
Initial(config, mode);
}
}

Expand All @@ -117,13 +119,12 @@ private void ReadConf(string path)
}
}

private void Initial(TimelineConfig conf, PlayMode mode, bool blend)
private void Initial(TimelineConfig conf, PlayMode mode)
{
_time = 0;
blending = blend;
playMode = mode;
config = conf;
if (blend == false)
if (!blending)
{
if (blendMixPlayable.IsValid())
{
Expand Down Expand Up @@ -170,6 +171,7 @@ private void Build()

public AnimationPlayableOutput blendPlayableOutput { get; set; }
public AnimationScriptPlayable blendMixPlayable { get; set; }
public MixerJob mixJob { get; set; }


// Only skill mode worked
Expand All @@ -181,6 +183,7 @@ public void BlendTo(string path)
{
blendPlayableOutput = track.playableOutput;
blendMixPlayable = track.mixPlayable;
mixJob = track.mixJob;
var clip = track.GetPlayingPlayable(out var tick) as XAnimationClip;
if (clip != null)
{
Expand All @@ -191,6 +194,7 @@ public void BlendTo(string path)
data.start = 0.01f;
}
}
blending = true;
Dispose(true);
ReadConf(path);
if (config != null)
Expand All @@ -211,7 +215,7 @@ public void BlendTo(string path)
}
config.tracks[config.skillHostTrack].clips = nc;
}
Initial(config, PlayMode.Skill, true);
Initial(config, PlayMode.Skill);
}
SetPlaying(true);
}
Expand Down
9 changes: 8 additions & 1 deletion Assets/timeline/Runtime/clips/XAnimationClip.cs
Expand Up @@ -55,7 +55,14 @@ protected override void OnUpdate(float tick, bool mix)

protected override void OnDestroy()
{
if (playable.IsValid()) playable.Destroy();
if (playable.IsValid())
{
playable.Destroy();
if(track.mixPlayable.IsValid())
{
track.mixPlayable.SetInputCount(0);
}
}
AnimClipData anData = data as AnimClipData;
XResources.DestroySharedAsset(anData.anim);
base.OnDestroy();
Expand Down
7 changes: 7 additions & 0 deletions Assets/timeline/Runtime/tracks/MixerJob.cs
Expand Up @@ -107,5 +107,12 @@ private void ProcessAnimation(AnimationStream stream, AnimationStream input)
handle.SetLocalRotation(stream, rotA);
}
}

public void Dispose()
{
clipA = -1;
clipB = -1;
handles.Dispose();
}
}
}
34 changes: 14 additions & 20 deletions Assets/timeline/Runtime/tracks/XAnimationTrack.cs
Expand Up @@ -17,7 +17,7 @@ public class XAnimationTrack : XBindTrack
{
public AnimationPlayableOutput playableOutput;
public AnimationScriptPlayable mixPlayable;
private MixerJob mixJob;
public MixerJob mixJob;
private int idx;
private float tmp;

Expand All @@ -31,9 +31,7 @@ public override bool cloneable
get { return false; }
}

public XAnimationTrack(XTimeline tl, BindTrackData data) : base(tl, data)
{
}
public XAnimationTrack(XTimeline tl, BindTrackData data) : base(tl, data) { }

protected override IClip BuildClip(ClipData data)
{
Expand All @@ -58,7 +56,7 @@ public override XTrack Clone()
}


public AnimationClipPlayable playA, playB;
private AnimationClipPlayable mixA, mixB;

protected override void OnMixer(float time, IMixClip mix)
{
Expand All @@ -70,26 +68,25 @@ protected override void OnMixer(float time, IMixClip mix)
XAnimationClip clipB = (XAnimationClip)mix.blendB;
if (clipA && clipB)
{
playA = clipA.playable;
playB = clipB.playable;
mixA = clipA.playable;
mixB = clipB.playable;
}
}
mix.connect = true;
float weight = (time - mix.start) / mix.duration;
if (playA.IsValid() && playB.IsValid())
if (mixA.IsValid() && mixB.IsValid())
{
mixJob.weight = weight;
mixPlayable.SetJobData(mixJob);
}
else
{
string tip = "playable invalid while animating mix ";
Debug.LogError(tip + playA.IsValid() + " " + playB.IsValid());
Debug.LogError(tip + mixA.IsValid() + " " + mixB.IsValid());
}
}
}

NativeArray<TransformStreamHandle> m_Handles;


public override void OnBind()
{
Expand All @@ -103,19 +100,19 @@ public override void OnBind()
{
playableOutput = timeline.blendPlayableOutput;
mixPlayable = timeline.blendMixPlayable;
mixJob = timeline.mixJob;
}
else
{
m_Handles = new NativeArray<TransformStreamHandle>(numTransforms, Allocator.Persistent,
var handles = new NativeArray<TransformStreamHandle>(numTransforms, Allocator.Persistent,
NativeArrayOptions.UninitializedMemory);
for (var i = 0; i < numTransforms; ++i)
{
m_Handles[i] = amtor.BindStreamTransform(transforms[i + 1]);
handles[i] = amtor.BindStreamTransform(transforms[i + 1]);
}

mixJob = new MixerJob()
{
handles = m_Handles,
handles = handles,
weight = 1.0f
};

Expand All @@ -142,10 +139,7 @@ public override void Process(float time, float prev)
mixPlayable.SetJobData(mixJob);
}
}

public void OnBind(GameObject bindObj)
{
}


public override void Dispose()
{
Expand All @@ -159,7 +153,7 @@ public override void Dispose()
{
XTimeline.graph.DestroyOutput(playableOutput);
}
m_Handles.Dispose();
mixJob.Dispose();
}
base.Dispose();
}
Expand Down

0 comments on commit 35f229a

Please sign in to comment.