コード例 #1
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            var newGradient = new ColorGradient(2);

            newGradient.ColorKeys[0] = new GradientColorKey(StartColor.GetFirstValue(mutable), 0);
            newGradient.ColorKeys[1] = new GradientColorKey(EndColor.GetFirstValue(mutable), 1);

            GradientTarget.SetValue(newGradient, mutable);

            return(mutable);
        }
コード例 #2
0
        public override void StartKinetic(VisualPayload payload, Func <float, float> translateTime)
        {
            var startColor = StartColor.GetFirstValue(payload.Data);
            var endColor   = EndColor.GetFirstValue(payload.Data);

            var transitionTimeInverse = 1f / TransitionTime.GetFirstValue(payload.Data);
            var startTime             = Time.time;


            var colorSatellite =
                payload.VisualData.Bound.gameObject.AddComponent <BoundMovementSatellite>();

            var newPayload = new VisualPayload(payload.Data, new VisualDescription(payload.VisualData.Bound));

            var materialsList =
                payload.VisualData.Bound.GetComponentsInChildren <Renderer>().Select(rend => rend.material).ToList();

            colorSatellite.MovementFunc = (trans) =>
            {
                float proportion = (Time.time - startTime) * transitionTimeInverse;

                if (proportion >= 1f)
                {
                    foreach (var mat in materialsList)
                    {
                        mat.color = endColor;
                    }

                    colorSatellite.Cleanup();
                    return;
                }

                proportion = translateTime(proportion);

                var toColor = Color.Lerp(startColor, endColor, proportion);

                foreach (var mat in materialsList)
                {
                    mat.color = toColor;
                }
            };

            colorSatellite.CleanupFunc = (trans) =>
            {
                JobManager.Instance.StartJob(
                    Finished.Transmit(newPayload), jobName: "Kinetic Finished", startImmediately: true,
                    maxExecutionsPerFrame: 1);
            };

            // execute first step immediately to set initial position
            colorSatellite.MovementFunc(colorSatellite.transform);
        }