Beispiel #1
0
 private void PopulateFunction(
     TextMeshProUGUI functionTypeField,
     TextMeshProUGUI periodField,
     TextMeshProUGUI deltaPeriodField,
     TextMeshProUGUI intensityField,
     TextMeshProUGUI deltaIntensityField,
     Weland.Light.Function welandStateFunction)
 {
     functionTypeField.text   = welandStateFunction.LightingFunction.ToString();
     periodField.text         = welandStateFunction.Period.ToString();
     deltaPeriodField.text    = welandStateFunction.DeltaPeriod.ToString();
     intensityField.text      = welandStateFunction.Intensity.ToString();
     deltaIntensityField.text = welandStateFunction.DeltaIntensity.ToString();
 }
Beispiel #2
0
        private async Task RunIntensityPhaseFunction(CancellationToken cancellationToken, Weland.Light.Function lightingFunction)
        {
            var functionPhaseOffset = 0f;

            if (remainingPhaseOffset > 0)
            {
                remainingPhaseOffset -= (short)(lightingFunction.Period);

                if (remainingPhaseOffset > 0)
                {
                    // There's still offset time remaining, so continue to the next State
                    return;
                }
                else
                {
                    // Note: This adds any remaining offset, which will be <= 0,
                    //       because Phase is intended to be a "backwards" shift through time
                    functionPhaseOffset = (float)(lightingFunction.Period + remainingPhaseOffset) / 30f;
                }
            }

            functionPhaseOffset += remainingPhaseTime;

            // Note: Clamps the randomized phase to no less than 1 tick
            //       to ensure all phases run for at least 1 tick.
            var duration = Mathf.Max(1, ((int)lightingFunction.Period + Random.Range(-lightingFunction.DeltaPeriod, lightingFunction.DeltaPeriod))) / 30f;

            switch (lightingFunction.LightingFunction)
            {
            case LightingFunction.Constant:
                await ConstantIntensityPhaseFunction(cancellationToken, duration, functionPhaseOffset, (float)lightingFunction.Intensity);

                return;

            case LightingFunction.Linear:
                await LinearIntensityPhaseFunction(cancellationToken, duration, functionPhaseOffset, (float)lightingFunction.Intensity, (float)lightingFunction.DeltaIntensity);

                return;

            case LightingFunction.Smooth:
                await SmoothIntensityPhaseFunction(cancellationToken, duration, functionPhaseOffset, (float)lightingFunction.Intensity, (float)lightingFunction.DeltaIntensity);

                return;

            case LightingFunction.Flicker:
                await FlickerIntensityPhaseFunction(cancellationToken, duration, functionPhaseOffset, (float)lightingFunction.Intensity, (float)lightingFunction.DeltaIntensity);

                return;

            default:
                throw new System.NotImplementedException($"Lighting Function: {lightingFunction.LightingFunction}");
            }
        }