Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 7cb1b88

Browse files
committed
2018.2 compatibility and safety measures
1 parent e7faf73 commit 7cb1b88

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

PostProcessing/Runtime/ParameterOverride.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ public T GetValue<T>()
1515
return ((ParameterOverride<T>)this).value;
1616
}
1717

18+
// This is used in case you need to access fields/properties that can't be accessed in the
19+
// constructor of a ScriptableObject (ParameterOverride are generally declared and inited in
20+
// a PostProcessEffectSettings which is a ScriptableObject). This will be called right
21+
// after the settings object has been constructed, thus allowing previously "forbidden"
22+
// fields/properties.
23+
protected internal virtual void OnEnable()
24+
{
25+
}
26+
27+
// Here for consistency reasons (cf. OnEnable)
28+
protected internal virtual void OnDisable()
29+
{
30+
}
31+
1832
internal abstract void SetValue(ParameterOverride parameter);
1933
}
2034

@@ -166,9 +180,22 @@ public override void Interp(Vector4 from, Vector4 to, float t)
166180
[Serializable]
167181
public sealed class SplineParameter : ParameterOverride<Spline>
168182
{
183+
protected internal override void OnEnable()
184+
{
185+
if (value != null)
186+
value.Cache(int.MinValue);
187+
}
188+
169189
public override void Interp(Spline from, Spline to, float t)
170190
{
171191
int frameCount = Time.renderedFrameCount;
192+
193+
if (from == null || to == null)
194+
{
195+
base.Interp(from, to, t);
196+
return;
197+
}
198+
172199
from.Cache(frameCount);
173200
to.Cache(frameCount);
174201

PostProcessing/Runtime/PostProcessEffectSettings.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ void OnEnable()
2828
.Select(t => (ParameterOverride)t.GetValue(this))
2929
.ToList()
3030
.AsReadOnly();
31+
32+
foreach (var parameter in parameters)
33+
parameter.OnEnable();
34+
}
35+
36+
void OnDisable()
37+
{
38+
if (parameters == null)
39+
return;
40+
41+
foreach (var parameter in parameters)
42+
parameter.OnDisable();
3143
}
3244

3345
public void SetAllOverridesTo(bool state, bool excludeEnabled = true)

PostProcessing/Runtime/Utils/Spline.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using UnityEngine.Assertions;
23

34
namespace UnityEngine.Rendering.PostProcessing
45
{
@@ -31,15 +32,15 @@ public sealed class Spline
3132

3233
public Spline(AnimationCurve curve, float zeroValue, bool loop, Vector2 bounds)
3334
{
35+
Assert.IsNotNull(curve);
3436
this.curve = curve;
3537
m_ZeroValue = zeroValue;
3638
m_Loop = loop;
3739
m_Range = bounds.magnitude;
3840
cachedData = new float[k_Precision];
39-
Cache(0, true);
4041
}
4142

42-
public void Cache(int frame, bool skipFrameCountTest = false)
43+
public void Cache(int frame)
4344
{
4445
// Only cache once per frame
4546
if (frame == frameCount)
@@ -64,8 +65,7 @@ public void Cache(int frame, bool skipFrameCountTest = false)
6465
for (int i = 0; i < k_Precision; i++)
6566
cachedData[i] = Evaluate((float)i * k_Step);
6667

67-
if (!skipFrameCountTest)
68-
frameCount = Time.renderedFrameCount;
68+
frameCount = Time.renderedFrameCount;
6969
}
7070

7171
public float Evaluate(float t)

0 commit comments

Comments
 (0)