Пример #1
0
    /// <summary>
    /// Set overlay to display perototype with name "name".
    /// </summary>
    /// <param name="name">Name of overlay prototype.</param>
    public void SetOverlay(string name)
    {
        if (name == "None")
        {
            meshRenderer.enabled = false;
            currentOverlay       = name;
            HideGUITooltip();
            return;
        }
        else if (overlays.ContainsKey(name))
        {
            meshRenderer.enabled = true;
            currentOverlay       = name;
            OverlayDescriptor descr  = overlays[name];
            object            handle = script.Globals[descr.luaFunctionName];
            if (handle == null)
            {
                Debug.ULogErrorChannel("OverlayMap", string.Format("Couldn't find a function named '{0}' in '{1}'", descr.luaFunctionName));
                return;
            }

            valueAt = (x, y) =>
            {
                if (WorldController.Instance == null)
                {
                    return(0);
                }

                Tile tile = WorldController.Instance.GetTileAtWorldCoord(new Vector3(x, y, 0));
                return((int)script.Call(handle, new object[] { tile, World.Current }).ToScalar().CastToNumber());
            };

            ColorMapSG = descr.colorMap;
            Bake();
            ShowGUITooltip();
        }
        else
        {
            Debug.ULogWarningChannel("OverlayMap", string.Format("Overlay with name {0} not found in prototypes", name));
        }
    }
Пример #2
0
    /// <summary>
    /// Returns an array of color, using the preset colormap with the name "name".
    /// Sets the alpha channel to alpha and uses "size" colors.
    /// </summary>
    /// <param name="colorMap">Name of colormap.</param>
    /// <param name="size">Number of colors to use.</param>
    /// <param name="alpha">Alpha channel of color.</param>
    /// <returns></returns>
    public static Color32[] ColorMap(
        OverlayDescriptor.ColorMap colorMap,
        int size   = 256,
        byte alpha = 128)
    {
        Color32[]           cm = new Color32[size];
        Func <int, Color32> map;

        switch (colorMap)
        {
        default:
        case OverlayDescriptor.ColorMap.Jet:
            map = (int v) =>
            {
                Color32 c = new Color32(255, 255, 255, alpha);
                if (v == 64)
                {
                    c.r = 0;
                    c.g = 255;
                }
                else if (v == 128)
                {
                    c.r = 0;
                    c.b = 255;
                }
                else if (v == 192)
                {
                    c.g = 255;
                    c.b = 0;
                }
                else if (v < 64)
                {
                    c.r = 0;
                    c.g = (byte)(4 * v);
                }
                else if (v < 128)
                {
                    c.r = 0;
                    c.b = (byte)(256 + (4 * (64 - v)));
                }
                else if (v < 192)
                {
                    c.r = (byte)(4 * (v - 128));
                    c.b = 0;
                }
                else
                {
                    c.g = (byte)(256 + (4 * (192 - v)));
                    c.b = 0;
                }

                return(c);
            };
            break;

        case OverlayDescriptor.ColorMap.Random:
            GenerateRandomColors(size);
            map = (int v) =>
            {
                return(randomColors[v]);
            };
            break;
        }

        for (int i = 0; i < size; i++)
        {
            cm[i] = map(i);
        }

        return(cm);
    }