Ejemplo n.º 1
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var currentWidth = 0f;

            var flagColorImpact = FlagColorImpact.GetFirstValue(payload.Data);

            var sections = SectionScope.GetEntries(payload.Data).ToList();

            var totalSize = (float)(from entry in SectionScope.GetEntries(payload.Data)
                                    select
                                    SectionMemorySize.GetValue(entry)).Aggregate((a, b) => a + b);

            ColorGradient sectionGradient = new ColorGradient(2 * sections.Count);

            foreach (var section in SectionScope.GetEntries(payload.Data))
            {
                var bandColor = Color.Lerp(
                    SectionColorMapping.GetSectionTypeColor(SectionType.GetValue(section)),
                    SectionColorMapping.GetSectionFlagColor(SectionFlag.GetValue(section)),
                    flagColorImpact);
                sectionGradient.AddColorKey(new GradientColorKey(
                                                bandColor,
                                                currentWidth));

                currentWidth += SectionMemorySize.GetValue(section);

                sectionGradient.AddColorKey(new GradientColorKey(
                                                bandColor,
                                                currentWidth));

                currentWidth += Epsilon * totalSize;
            }

            var textureWidth  = TextureWidth.GetFirstValue(payload.Data);
            var textureHeight = TextureHeight.GetFirstValue(payload.Data);

            sectionGradient.RescaleColorKeys(currentWidth);


            var resultTexture = new Texture2D(textureWidth, textureHeight);

            var outColors = new Color[textureWidth * textureHeight];

            for (int x = 0; x < textureWidth; x++)
            {
                var localColor = sectionGradient.Evaluate(x / (float)textureWidth);
                for (int y = 0; y < textureHeight; y++)
                {
                    outColors[x + textureWidth * y] = localColor;
                }
            }

            resultTexture.SetPixels(outColors);
            resultTexture.Apply();

            var quadMaterial = GameObject.Instantiate(MaterialFactory.GetDefaultMaterial());

            quadMaterial.mainTexture = resultTexture;

            MaterialTarget.SetValue(quadMaterial, payload.Data);

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }