Skip to content

Commit 51b3bcd

Browse files
authored
fix: errors caused by GetActivePlayableAsset(), and PlayableMixer behavior fixes (#58)
* Fix so that GetActivePlayableAsset() does not cause errors when the trackMixer is not created yet StreamingImageSequencePlayableMixer updates: * Make ProcessFrame() work event though the track is not bound to any object * Calculate loadStartOffsetTime based on each clip's image count, instead of depending only on the first timelineClip in the track. Others: * test: change the timing to call GetActivePlayableAsset() * Fix variable naming * Remove unnecessary using * Update package version to 0.1.2-preview
1 parent 7150fef commit 51b3bcd

File tree

6 files changed

+51
-56
lines changed

6 files changed

+51
-56
lines changed

Runtime/PlayableAssets/BasePlayableMixer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void ProcessFrame(Playable playable, FrameData info, object play
2727
return;
2828
}
2929

30-
GetActiveTimelineClipInto(out TimelineClip clip, out T activePlayableAsset);
30+
GetActiveTimelineClipInto(m_clips, m_playableDirector.time, out TimelineClip clip, out T activePlayableAsset);
3131
if (null == clip)
3232
return;
3333

@@ -38,10 +38,10 @@ public override void ProcessFrame(Playable playable, FrameData info, object play
3838

3939
//----------------------------------------------------------------------------------------------------------------------
4040

41-
public void GetActiveTimelineClipInto( out TimelineClip outClip, out T outAsset) {
41+
public static void GetActiveTimelineClipInto( IEnumerable<TimelineClip> clips, double directorTime,
42+
out TimelineClip outClip, out T outAsset) {
4243

43-
double directorTime = m_playableDirector.time;
44-
foreach (TimelineClip clip in m_clips) {
44+
foreach (TimelineClip clip in clips) {
4545
T asset = clip.asset as T;
4646
if (null == asset)
4747
continue;
@@ -67,6 +67,9 @@ internal void Init(GameObject go, PlayableDirector director, IEnumerable<Timelin
6767
InitInternalV(go);
6868
}
6969

70+
//----------------------------------------------------------------------------------------------------------------------
71+
internal double GetDirectorTime() { return m_playableDirector.time; }
72+
7073
//----------------------------------------------------------------------------------------------------------------------
7174

7275
protected abstract void InitInternalV(GameObject boundGameObject);

Runtime/PlayableAssets/StreamingImageSequence/StreamingImageSequencePlayableMixer.cs

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System;
4-
using System.IO;
5-
using UnityEngine;
63
using UnityEngine.Playables;
7-
using System.Text.RegularExpressions;
8-
using UnityEngine.Assertions;
9-
using System.Threading;
10-
using System.Runtime.InteropServices;
114
using UnityEngine.UI;
125
using UnityEngine.Timeline;
136
#if UNITY_EDITOR
@@ -29,7 +22,6 @@ public StreamingImageSequencePlayableMixer() {
2922
m_gameView = EditorWindow.GetWindow(type,false,null,false);
3023

3124
#endif
32-
m_loadStartOffsetTime = -1.0;
3325
}
3426

3527

@@ -74,21 +66,17 @@ public override void ProcessFrame(Playable playable, FrameData info, object play
7466
return; // it doesn't work as mixer.
7567
}
7668

77-
if (m_nextInadvanceLoadingFrameArray == null) {
78-
m_nextInadvanceLoadingFrameArray = new int[inputCount];
69+
if (m_nextInAdvanceLoadingFrameArray == null) {
70+
m_nextInAdvanceLoadingFrameArray = new int[inputCount];
7971
for ( int ii = 0;ii< inputCount;ii++)
8072
{
81-
m_nextInadvanceLoadingFrameArray[ii] = 0;
73+
m_nextInAdvanceLoadingFrameArray[ii] = 0;
8274
}
8375
}
8476

85-
GameObject go = GetBoundGameObject();
86-
87-
if (null == go)
88-
return;
89-
9077
double directorTime = GetPlayableDirector().time;
9178

79+
bool activeTimelineClipFound = false;
9280
int i = 0;
9381
foreach (TimelineClip clip in GetClips()) {
9482

@@ -100,30 +88,31 @@ public override void ProcessFrame(Playable playable, FrameData info, object play
10088
if (null == imagePaths)
10189
continue;
10290

103-
int count = imagePaths.Count;
104-
double clipDuration = clip.duration;
10591
double startTime = clip.start;
10692
double endTime = clip.end;
10793

108-
if ( m_loadStartOffsetTime < 0.0) {
109-
m_loadStartOffsetTime = 1.0f + count * 0.1f;
110-
111-
}
94+
double loadStartOffsetTime = 1.0f + imagePaths.Count * 0.1f;
11295

11396
//Load clips that might still be inactive, in advance
114-
if ( directorTime>= startTime - m_loadStartOffsetTime && directorTime < endTime) {
97+
if ( directorTime>= startTime - loadStartOffsetTime && directorTime < endTime) {
11598
ProcessInAdvanceLoading(directorTime, clip, i );
11699
}
117100

118-
if (directorTime >= startTime && directorTime < endTime) {
119-
101+
if (!activeTimelineClipFound && directorTime >= startTime && directorTime < endTime) {
120102
ProcessActiveClipV(asset, directorTime, clip);
121-
go.SetActive(true);
103+
activeTimelineClipFound = true;
122104
}
123105

124106
++i;
125107
}
126108

109+
//Show game object
110+
GameObject go = GetBoundGameObject();
111+
if (activeTimelineClipFound && null != go) {
112+
go.SetActive(true);
113+
}
114+
115+
127116
}
128117

129118
#endregion
@@ -137,21 +126,20 @@ private void ProcessInAdvanceLoading(double time, TimelineClip clip, int index)
137126

138127
int count = asset.GetImagePaths().Count;
139128

140-
if (m_nextInadvanceLoadingFrameArray[index] < count)
129+
if (m_nextInAdvanceLoadingFrameArray[index] < count)
141130
{
142131
for (int check = 0; check < 4; check++)
143132
{
144133

145-
if (m_nextInadvanceLoadingFrameArray[index] >= 0 && m_nextInadvanceLoadingFrameArray[index] <= count)
134+
if (m_nextInAdvanceLoadingFrameArray[index] >= 0 && m_nextInAdvanceLoadingFrameArray[index] <= count)
146135
{
147-
if (!asset.IsLoadRequested(m_nextInadvanceLoadingFrameArray[index]))
136+
if (!asset.IsLoadRequested(m_nextInAdvanceLoadingFrameArray[index]))
148137
{
149-
ReadResult result = new ReadResult();
150-
asset.LoadRequest(m_nextInadvanceLoadingFrameArray[index], false, out result);
138+
asset.LoadRequest(m_nextInAdvanceLoadingFrameArray[index], false, out _);
151139
}
152140
}
153-
m_nextInadvanceLoadingFrameArray[index]++;
154-
if (m_nextInadvanceLoadingFrameArray[index] >= count)
141+
m_nextInAdvanceLoadingFrameArray[index]++;
142+
if (m_nextInAdvanceLoadingFrameArray[index] >= count)
155143
{
156144
break;
157145
}
@@ -183,7 +171,6 @@ protected override void ProcessActiveClipV(StreamingImageSequencePlayableAsset a
183171
//----------------------------------------------------------------------------------------------------------------------
184172

185173
void Reset() {
186-
m_loadStartOffsetTime = -1.0;
187174
m_spriteRenderer = null;
188175
m_image = null;
189176
m_meshRenderer = null;
@@ -238,15 +225,13 @@ void UpdateRendererTexture(StreamingImageSequencePlayableAsset asset) {
238225
private MeshRenderer m_meshRenderer = null;
239226
private Image m_image = null;
240227

241-
internal TrackAsset m_track;
242-
private double m_loadStartOffsetTime;
243228
#if UNITY_EDITOR
244-
EditorWindow m_gameView;
229+
readonly EditorWindow m_gameView;
245230
#endif
246-
private int[] m_nextInadvanceLoadingFrameArray;
231+
private int[] m_nextInAdvanceLoadingFrameArray;
247232

248233
}
249234

250235

251236

252-
}
237+
} //end namespace

Runtime/PlayableAssets/StreamingImageSequence/StreamingImageSequenceTrack.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ protected override Playable CreatePlayable(PlayableGraph graph, GameObject go, T
3737
/// <inheritdoc/>
3838
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount) {
3939
var mixer = ScriptPlayable<StreamingImageSequencePlayableMixer>.Create(graph, inputCount);
40-
var director = go.GetComponent<PlayableDirector>();
40+
PlayableDirector director = go.GetComponent<PlayableDirector>();
41+
m_trackMixer = mixer.GetBehaviour();
42+
4143
if (director != null) {
4244
var boundGo = director.GetGenericBinding(this);
4345
StreamingImageSequenceNativeRenderer nativeRenderer = boundGo as StreamingImageSequenceNativeRenderer;
44-
StreamingImageSequencePlayableMixer bh = mixer.GetBehaviour();
45-
bh.m_track = this;
46-
bh.Init(null == nativeRenderer ? null : nativeRenderer.gameObject, director, GetClips());
46+
m_trackMixer.Init(null == nativeRenderer ? null : nativeRenderer.gameObject, director, GetClips());
4747
}
48-
49-
m_trackMixer = mixer.GetBehaviour();
5048
return mixer;
5149
}
5250

@@ -59,7 +57,10 @@ public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, in
5957
/// PlayableAsset.
6058
/// </returns>
6159
public StreamingImageSequencePlayableAsset GetActivePlayableAsset() {
62-
m_trackMixer.GetActiveTimelineClipInto(out TimelineClip clip, out StreamingImageSequencePlayableAsset asset);
60+
double time = (null != m_trackMixer ) ? m_trackMixer.GetDirectorTime() : 0;
61+
StreamingImageSequencePlayableMixer.GetActiveTimelineClipInto(m_Clips, time,
62+
out TimelineClip clip, out StreamingImageSequencePlayableAsset asset
63+
);
6364
return asset;
6465
}
6566

StreamingImageSequence~/Packages/com.unity.streaming-image-sequence/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [0.1.2-preview] - 2020-04-14
4+
* fix: errors caused by StreamingImageSequenceTrack::GetActivePlayableAsset() when TimelineWindow is not in focus
5+
* fix: keep processing StreamingImageSequencePlayableAsset even if there is no bound GameObject in the track, as the output texture is still required
6+
37
## [0.1.1-preview] - 2020-04-10
48
* api: open StreamingImageSequenceTrack to public
59
* api: open StreamingImageSequencePlayableAsset::GetTexture() to public

StreamingImageSequence~/Packages/com.unity.streaming-image-sequence/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"displayName": "Streaming Image Sequence",
33
"name": "com.unity.streaming-image-sequence",
44
"unity": "2019.2",
5-
"version": "0.1.1-preview",
5+
"version": "0.1.2-preview",
66
"dependencies": {
77
"com.unity.timeline": "1.2.14"
88
},

Tests/Editor/StreamingImageSequencePlayableAssetTest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ internal class StreamingImageSequencePlayableAssetTest {
1818
public IEnumerator CreatePlayableAsset() {
1919
PlayableDirector director = NewSceneWithDirector();
2020
StreamingImageSequencePlayableAsset sisAsset = CreateTestTimelineAssets(director);
21+
22+
//Test the track immediately
23+
StreamingImageSequenceTrack track = sisAsset.GetTimelineClip().parentTrack as StreamingImageSequenceTrack;
24+
Assert.IsNotNull(track);
25+
Assert.IsNotNull(track.GetActivePlayableAsset());
26+
2127
yield return null;
2228

2329
IList<string> imagePaths = sisAsset.GetImagePaths();
@@ -26,10 +32,6 @@ public IEnumerator CreatePlayableAsset() {
2632
Assert.IsTrue(sisAsset.HasImages());
2733

2834

29-
//Test the track
30-
StreamingImageSequenceTrack track = sisAsset.GetTimelineClip().parentTrack as StreamingImageSequenceTrack;
31-
Assert.IsNotNull(track);
32-
Assert.IsNotNull(track.GetActivePlayableAsset());
3335

3436
//Test that there should be no active PlayableAsset at the time above what exists in the track.
3537
TimelineClip clip = sisAsset.GetTimelineClip();

0 commit comments

Comments
 (0)