public IEnumerator TestAddInterpolation()
    {
        TimelineFloat timeFloat = new TimelineFloat();

        TimedFloat testVal1 = new TimedFloat(1, 1);
        TimedFloat testVal2 = new TimedFloat(2, 2);
        TimedFloat testVal3 = new TimedFloat(3, 3);
        TimedFloat testVal4 = new TimedFloat(4, 5);

        timeFloat.SetValue(testVal1);
        timeFloat.SetValue(testVal2);
        timeFloat.SetValue(testVal3);

        Assert.True(timeFloat.HasValue, "TimelineProperty without values");
        Assert.True(timeFloat.Value == testVal3.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.TimePoints == 2, "TimelineProperty with unexpected Value");

        timeFloat.SetValue(testVal4);

        Assert.True(timeFloat.HasValue, "TimelineProperty without values");
        Assert.True(timeFloat.Value == testVal4.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.TimePoints == 3, "TimelineProperty with unexpected Value");

        yield break;
    }
    public IEnumerator TestSetValue()
    {
        TimelineFloat timeFloat = new TimelineFloat();

        TimedFloat testVal1 = new TimedFloat(1, 1);
        TimedFloat testVal2 = new TimedFloat(2, 5);
        TimedFloat testVal3 = new TimedFloat(3, 10);
        TimedFloat testVal4 = new TimedFloat(1.5f, 5);

        timeFloat.SetValue(testVal1);
        Assert.True(timeFloat.Duration == 0.0f, "TimelineProperty with unexpected Duration");

        timeFloat.SetValue(testVal2);
        timeFloat.SetValue(testVal3);

        Assert.True(timeFloat.HasValue, "TimelineProperty without values");
        Assert.True(timeFloat.Value == testVal3.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.TimePoints == 3, "TimelineProperty with unexpected Value");
        Assert.False(timeFloat.HasValueBefore(0), "Unexpected HasValueBefore");
        Assert.False(timeFloat.HasValueBefore(-5), "Unexpected HasValueBefore");
        Assert.True(timeFloat.HasValueBefore(1.5f), "Unexpected HasValueBefore");
        Assert.True(timeFloat.HasValueBefore(100), "Unexpected HasValueBefore");

        timeFloat.SetValue(testVal4);

        Assert.True(timeFloat.HasValue, "TimelineProperty without values");
        Assert.True(timeFloat.Value == testVal4.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.TimePoints == 2, "TimelineProperty with unexpected Value");
        Assert.False(timeFloat.HasValueBefore(0), "Unexpected HasValueBefore");
        Assert.False(timeFloat.HasValueBefore(-5), "Unexpected HasValueBefore");
        Assert.True(timeFloat.HasValueBefore(1.5f), "Unexpected HasValueBefore");
        Assert.True(timeFloat.HasValueBefore(100), "Unexpected HasValueBefore");

        yield break;
    }
    private float QuickInterpolation(TimedFloat a, TimedFloat b, float Yc)
    {
        float Xa = a.Value;
        float Ya = a.Timestamp;
        float Xb = b.Value;
        float Yb = b.Timestamp;

        return(((Xb - Xa) / (Yb - Ya)) * (Yc - Ya) + Xa);
    }
Example #4
0
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/ public void Invoke(TimedFloat val)
/*AUTO SCRIPT*/ {
/*AUTO SCRIPT*/ if (debug)
            {
/*AUTO SCRIPT*/ Debug.Log($"{name} event invoked: {val}");
            }
/*AUTO SCRIPT*/ ahoyEvent.Invoke(name, val);
/*AUTO SCRIPT*/                 //important to do this incase a listener removes its self from the list
/*AUTO SCRIPT*/ unityEventListeners.ToArray().ForEach(l => l.Invoke(name, val));
/*AUTO SCRIPT*/ assetEventListeners.ToArray().ForEach(l => l.Invoke(val));
/*AUTO SCRIPT*/ }
Example #5
0
    private void OnStatsChange()
    {
        float elapsedTime = GameTime.Instance.ElapsedTime;

        float[] currentStatsArray = CurrentStatsArray();
        for (int i = ((int)StatsIndex.Start + 1); i < (int)StatsIndex.End; i++)
        {
            TimedFloat newVal = new TimedFloat(elapsedTime, currentStatsArray[i]);
            playerStats[i].SetValue(newVal);
        }
    }
    public IEnumerator TestInterpolatedValue()
    {
        TimelineFloat timeFloat = new TimelineFloat();
        TimedFloat    testVal1  = new TimedFloat(1, 5);
        TimedFloat    testVal2  = new TimedFloat(2, 5);
        TimedFloat    testVal3  = new TimedFloat(3, 25);
        TimedFloat    testVal4  = new TimedFloat(1.5f, 5);

        Assert.True(timeFloat.InterpolatedValueAt(1.0f) == default(float), "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.InterpolatedValueAt(0.0f) == default(float), "TimelineProperty with unexpected Value");

        timeFloat.SetValue(testVal1);

        Assert.True(timeFloat.InterpolatedValueAt(0.5f) == testVal1.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.InterpolatedValueAt(2.0f) == testVal1.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.InterpolatedValueAt(3.0f) == testVal1.Value, "TimelineProperty with unexpected Value");

        timeFloat.SetValue(testVal4);

        Assert.True(timeFloat.InterpolatedValueAt(0.5f) == testVal4.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.InterpolatedValueAt(2.0f) == testVal4.Value, "TimelineProperty with unexpected Value");
        Assert.True(timeFloat.InterpolatedValueAt(3.0f) == testVal4.Value, "TimelineProperty with unexpected Value");

        timeFloat.SetValue(testVal1);
        timeFloat.SetValue(testVal2);
        timeFloat.SetValue(testVal3);

        float interpolate0    = testVal4.Value;
        float interpolate05   = testVal4.Value;
        float interpolate175  = QuickInterpolation(testVal4, testVal2, 1.75f);
        float interpolate2    = testVal2.Value;
        float interpolate25   = QuickInterpolation(testVal3, testVal2, 2.5f);
        float interpolate3    = testVal3.Value;
        float interpolate4v1  = testVal3.Value;
        float interpolate4v2  = QuickInterpolation(testVal2, testVal3, 4.0f);
        float interpolateNeg2 = testVal4.Value;


        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(0.0f), interpolate0), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(0.5f), interpolate05), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(1.75f), interpolate175), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(2.0f), interpolate2), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(2.5f), interpolate25), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(3.0f), interpolate3), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(4.0f), interpolate4v1), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(4.0f, false), interpolate4v2), "TimelineProperty with unexpected Value");
        Assert.True(Mathf.Approximately(timeFloat.InterpolatedValueAt(-2.0f), interpolateNeg2), "TimelineProperty with unexpected Value");

        yield break;
    }
Example #7
0
/*AUTO SCRIPT*/
/*AUTO SCRIPT*/ public void Push(TimedFloat val)
/*AUTO SCRIPT*/ {
/*AUTO SCRIPT*/ array.Push(val);
/*AUTO SCRIPT*/ Invoke();
/*AUTO SCRIPT*/ }
/*AUTO SCRIPT*/ public void Log(TimedFloat val)
        {
/*AUTO SCRIPT*/ Debug.Log($"{prefix}: {val}");
/*AUTO SCRIPT*/ }
Example #9
0
 ///<exclude/>
 public bool Equals(TimedFloat other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other._Tm.Equals(_Tm) && other._Data.Equals(_Data);
 }