Exemple #1
0
 public void RemoveFieldViewer(IFOWFieldViewer viewer)
 {
     if (m_Viewer.Contains(viewer))
     {
         m_Viewer.Remove(viewer);
         viewer.Release();
     }
 }
Exemple #2
0
    /// <summary>
    /// 在一维数组中取索引:index = y+x*w //w为列数,x和y为水平竖直索引
    /// </summary>
    void BlurVisible(IFOWFieldViewer viewer)
    {
        //float maxValue = 0;
        //for (int i = 0; i < m_TextureSize; ++i)
        //{
        //    for (int j = 0; j < m_TextureSize; ++j)
        //    {
        //        int index = j + i * m_TextureSize;

        //        //int val = m_Buffer0[index].g;
        //        //val += m_Buffer0[j - 1 + i * m_TextureSize].g;
        //        //val += m_Buffer0[j + 1 + i * m_TextureSize].g;
        //        //val += m_Buffer0[j + (i - 1) * m_TextureSize].g;
        //        //val += m_Buffer0[j + (i + 1) * m_TextureSize].g;
        //        //val += m_Buffer0[j - 1 + (i - 1) * m_TextureSize].g;
        //        //val += m_Buffer0[j - 1 + (i + 1) * m_TextureSize].g;
        //        //val += m_Buffer0[j + 1 + (i - 1) * m_TextureSize].g;
        //        //val += m_Buffer0[j + 1 + (i + 1) * m_TextureSize].g;


        //        //maxValue = Mathf.Max(maxValue, j + i * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j - 1 + i * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j + 1 + i * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j + (i - 1) * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j + (i + 1) * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j - 1 + (i - 1) * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j - 1 + (i + 1) * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j + 1 + (i - 1) * m_TextureSize);
        //        //maxValue = Mathf.Max(maxValue, j + 1 + (i + 1) * m_TextureSize);

        //        maxValue = Mathf.Max(maxValue, i + j * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i - 1 + j * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i + 1 + j * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i + (j - 1) * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i + (j + 1) * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i - 1 + (j - 1) * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i - 1 + (j + 1) * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i + 1 + (j - 1) * m_TextureSize);
        //        maxValue = Mathf.Max(maxValue, i + 1 + (j + 1) * m_TextureSize);

        //        //m_Buffer0[index].a = (byte)(val / 9);
        //    }
        //}
        //Debug.LogError("blur 2@@@@@@@@ maxValue:" + maxValue);


        float   radius    = viewer.GetRadius() * m_TexSizeDivideWorldSize + radiusOffset; //纹理上的半径
        int     radiusSqr = Mathf.RoundToInt(radius * radius);
        Vector3 pos       = (viewer.GetPos() - m_Origin) * m_TexSizeDivideWorldSize;      //纹理上的坐标
        int     cx        = Mathf.RoundToInt(pos.x);
        int     cy        = Mathf.RoundToInt(pos.z);

        int maxIndex = m_Buffer0.Length - 1;

        for (int y = 0; y < m_TextureSize; ++y)
        {
            int yw  = y * m_TextureSize;
            int yw0 = (y - blurOffset);
            if (yw0 < 0)
            {
                yw0 = 0;
            }
            int yw1 = (y + blurOffset);
            if (yw1 == m_TextureSize)
            {
                yw1 = y;
            }

            yw0 *= m_TextureSize;
            yw1 *= m_TextureSize;

            for (int x = 0; x < m_TextureSize; ++x)
            {
                int xd   = x - cx;
                int yd   = y - cy;
                int dist = xd * xd + yd * yd;
                if (dist <= radiusSqr)
                {
                    int x0 = (x - blurOffset);
                    if (x0 < 0)
                    {
                        x0 = 0;
                    }
                    int x1 = (x + blurOffset);
                    if (x1 == m_TextureSize)
                    {
                        x1 = x;
                    }

                    int index = x + yw;
                    int val   = m_Buffer0[index].g;

                    val += m_Buffer0[Mathf.Clamp(x0 + yw, 0, maxIndex)].g;
                    val += m_Buffer0[Mathf.Clamp(x1 + yw, 0, maxIndex)].g;

                    val += m_Buffer0[Mathf.Clamp(x + yw0, 0, maxIndex)].g;
                    val += m_Buffer0[Mathf.Clamp(x0 + yw0, 0, maxIndex)].g;
                    val += m_Buffer0[Mathf.Clamp(x1 + yw0, 0, maxIndex)].g;

                    val += m_Buffer0[Mathf.Clamp(x + yw1, 0, maxIndex)].g;
                    val += m_Buffer0[Mathf.Clamp(x0 + yw1, 0, maxIndex)].g;
                    val += m_Buffer0[Mathf.Clamp(x1 + yw1, 0, maxIndex)].g;

                    m_Buffer0[index].a = (byte)(val / 9);
                    m_Buffer0[index].g = m_Buffer0[index].a;
                }
            }
        }
    }
Exemple #3
0
 public void AddFieldViewer(IFOWFieldViewer viewer)
 {
     this.m_Viewer.Add(viewer);
 }
Exemple #4
0
    void CalCurVisible(IFOWFieldViewer viewer)
    {
        if (!viewer.IsValid())
        {
            return;
        }

        ////纹理点 = 世界点 * 纹理宽/世界宽
        //Vector3 texPos = (viewer.GetPos() - m_Origin) * m_TexSizeDivideWorldSize;
        //texPos = new Vector3(Mathf.Clamp(texPos.x, 0, m_TextureSize), 0, Mathf.Clamp(texPos.z, 0, m_TextureSize));

        //float texRadius = viewer.GetRadius() * m_TexSizeDivideWorldSize + radiusOffset;
        //texRadius = Mathf.Clamp(texRadius, 0, m_TextureSize);

        ////只处理视野体可视半径范围内的坐标
        ////RoundToInt返回四舍五入到最接近的整数的f
        //int minX = Mathf.RoundToInt(texPos.x - texRadius);
        //int maxX = Mathf.RoundToInt(texPos.x + texRadius);
        //int minY = Mathf.RoundToInt(texPos.z - texRadius);
        //int maxY = Mathf.RoundToInt(texPos.z + texRadius);
        //minX = Mathf.Clamp(minX, 0, m_TextureSize);
        //minY = Mathf.Clamp(minY, 0, m_TextureSize);
        //maxX = Mathf.Clamp(maxX, 0, m_TextureSize);
        //maxY = Mathf.Clamp(maxY, 0, m_TextureSize);

        //float distSqrt = 0f;
        //float radiusSqrt = texRadius * texRadius;

        //for (int i = minX; i < maxX; ++i)
        //{
        //    for (int j = minY; j < maxY; ++j)
        //    {
        //        distSqrt = (i - texPos.x) * (i - texPos.x) + (j - texPos.y) * (j - texPos.y);
        //        if (distSqrt <= radiusSqrt)
        //        {
        //            //if (curCount < maxCount)
        //            //{
        //            //    curCount++;
        //            //    UnityThread.PostAction(delegate
        //            //    {
        //            //        Debug.LogError($"可视:{i} {j} {i + j * m_TextureSize} {(i - 1) * m_TextureSize + (j - 1)} {i * m_TextureSize + j}");
        //            //    });
        //            //}
        //            //m_Buffer0[(i - 1) * m_TextureSize + (j - 1)].g = 255;
        //            //m_Buffer0[i * m_TextureSize + j].g = 255;
        //            m_Buffer0[i + j * m_TextureSize].g = 255;
        //        }
        //    }
        //}

        //相对于战争迷雾的位置
        Vector3 pos    = (viewer.GetPos() - m_Origin) * m_TexSizeDivideWorldSize;      //纹理上的坐标
        float   radius = viewer.GetRadius() * m_TexSizeDivideWorldSize + radiusOffset; //纹理上的半径

        // Coordinates we'll be dealing with
        //我们将要处理的坐标
        //RoundToInt返回四舍五入到最接近的整数的f
        int xmin = Mathf.RoundToInt(pos.x - radius);
        int ymin = Mathf.RoundToInt(pos.z - radius);
        int xmax = Mathf.RoundToInt(pos.x + radius);
        int ymax = Mathf.RoundToInt(pos.z + radius);

        int cx = Mathf.RoundToInt(pos.x);
        int cy = Mathf.RoundToInt(pos.z);

        cx = Mathf.Clamp(cx, 0, m_TextureSize - 1);
        cy = Mathf.Clamp(cy, 0, m_TextureSize - 1);

        int radiusSqr = Mathf.RoundToInt(radius * radius);

        for (int y = ymin; y < ymax; ++y)
        {
            if (y > -1 && y < m_TextureSize)
            {
                int yw = y * m_TextureSize;

                for (int x = xmin; x < xmax; ++x)
                {
                    if (x > -1 && x < m_TextureSize)
                    {
                        int xd   = x - cx;
                        int yd   = y - cy;
                        int dist = xd * xd + yd * yd;

                        // Reveal this pixel
                        if (dist <= radiusSqr)
                        {
                            m_Buffer0[x + yw].g = 255;
                        }
                    }
                }
            }
        }
    }