コード例 #1
0
    private void PaintCleared(
        Vector3 worldPos,
        float radius,
        TerrainModifier.PaintType paintType,
        bool heightCheck,
        bool apply)
    {
        worldPos.x -= 0.5f;
        worldPos.z -= 0.5f;
        float num1 = worldPos.y - this.transform.position.y;
        int   x1;
        int   y1;

        this.WorldToVertex(worldPos, out x1, out y1);
        float   f    = radius / this.m_scale;
        int     num2 = Mathf.CeilToInt(f);
        Vector2 a    = new Vector2((float)x1, (float)y1);

        for (int y2 = y1 - num2; y2 <= y1 + num2; ++y2)
        {
            for (int x2 = x1 - num2; x2 <= x1 + num2; ++x2)
            {
                float num3 = Vector2.Distance(a, new Vector2((float)x2, (float)y2));
                if (x2 >= 0 && y2 >= 0 && (x2 < this.m_clearedMask.width && y2 < this.m_clearedMask.height) && (!heightCheck || (double)this.GetHeight(x2, y2) <= (double)num1))
                {
                    float t     = Mathf.Pow(1f - Mathf.Clamp01(num3 / f), 0.1f);
                    Color color = this.m_clearedMask.GetPixel(x2, y2);
                    switch (paintType)
                    {
                    case TerrainModifier.PaintType.Dirt:
                        color = Color.Lerp(color, Color.red, t);
                        break;

                    case TerrainModifier.PaintType.Cultivate:
                        color = Color.Lerp(color, Color.green, t);
                        break;

                    case TerrainModifier.PaintType.Paved:
                        color = Color.Lerp(color, Color.blue, t);
                        break;

                    case TerrainModifier.PaintType.Reset:
                        color = Color.Lerp(color, Color.black, t);
                        break;
                    }
                    this.m_clearedMask.SetPixel(x2, y2, color);
                }
            }
        }
        if (!apply)
        {
            return;
        }
        this.m_clearedMask.Apply();
    }
コード例 #2
0
ファイル: Heightmap.cs プロジェクト: ingvard/valheim-jserver
    // Token: 0x06000D9B RID: 3483 RVA: 0x000612F4 File Offset: 0x0005F4F4
    private void PaintCleared(Vector3 worldPos, float radius, TerrainModifier.PaintType paintType, bool heightCheck, bool apply)
    {
        worldPos.x -= 0.5f;
        worldPos.z -= 0.5f;
        float num = worldPos.y - base.transform.position.y;
        int   num2;
        int   num3;

        this.WorldToVertex(worldPos, out num2, out num3);
        float   num4 = radius / this.m_scale;
        int     num5 = Mathf.CeilToInt(num4);
        Vector2 a    = new Vector2((float)num2, (float)num3);

        for (int i = num3 - num5; i <= num3 + num5; i++)
        {
            for (int j = num2 - num5; j <= num2 + num5; j++)
            {
                float num6 = Vector2.Distance(a, new Vector2((float)j, (float)i));
                if (j >= 0 && i >= 0 && j < this.m_clearedMask.width && i < this.m_clearedMask.height && (!heightCheck || this.GetHeight(j, i) <= num))
                {
                    float num7 = 1f - Mathf.Clamp01(num6 / num4);
                    num7 = Mathf.Pow(num7, 0.1f);
                    Color color = this.m_clearedMask.GetPixel(j, i);
                    switch (paintType)
                    {
                    case TerrainModifier.PaintType.Dirt:
                        color = Color.Lerp(color, Color.red, num7);
                        break;

                    case TerrainModifier.PaintType.Cultivate:
                        color = Color.Lerp(color, Color.green, num7);
                        break;

                    case TerrainModifier.PaintType.Paved:
                        color = Color.Lerp(color, Color.blue, num7);
                        break;

                    case TerrainModifier.PaintType.Reset:
                        color = Color.Lerp(color, Color.black, num7);
                        break;
                    }
                    this.m_clearedMask.SetPixel(j, i, color);
                }
            }
        }
        if (apply)
        {
            this.m_clearedMask.Apply();
        }
    }