Ejemplo n.º 1
0
        public void Initialize(Vector2 position, Vector2 windowSize, float chunkWorldSize)
        {
            m_renderWindow = new SlidingWindow(position, windowSize, Vector2.zero, Vector2.one * chunkWorldSize);

            m_rect       = m_renderWindow.GetWindow();
            m_windowSize = m_rect.size;

            m_chunks = new VoxelChunk[m_windowSize.x * m_windowSize.y];
            m_dirty  = new bool[m_chunks.Length];

            for (int y = 0; y < m_windowSize.y; y++)
            {
                for (int x = 0; x < m_windowSize.x; x++)
                {
                    int cx = m_rect.origin.x + x;
                    int cy = m_rect.origin.y + y;

                    VoxelChunk chunk = VoxelChunk.Create(transform, string.Format("[{0},{1}]", cx, cy), m_settings, m_chunkSize + 1, m_chunkSize + 1);

                    float chunkX = cx * m_settings.voxelSize * m_chunkSize;
                    float chunkY = cy * m_settings.voxelSize * m_chunkSize;

                    chunk.nextPosition = new Vector3(chunkX, chunkY);

                    m_chunks[y * m_windowSize.x + x] = chunk;
                }
            }
        }
Ejemplo n.º 2
0
        private void OnDrawGizmosSelected()
        {
            SlidingWindow window = m_renderWindow;

            if (window == null)
            {
                window = new SlidingWindow(Vector2.zero, m_renderSize, Vector2.zero, Vector2.one * m_settings.voxelSize * m_chunkSize);
            }
            IntRect rect = window.GetWindow();

            for (int j = 0; j < rect.size.y && j < 100; j++)
            {
                for (int i = 0; i < rect.size.x && i < 100; i++)
                {
                    int chunkX = rect.origin.x + i;
                    int chunkY = rect.origin.y + j;

                    Vector2 a = new Vector2(chunkX * m_settings.voxelSize * m_chunkSize, chunkY * m_settings.voxelSize * m_chunkSize);
                    Vector2 b = a + Vector2.one * m_settings.voxelSize * m_chunkSize;

                    DrawRect(a, b, Color.yellow);

                    string debug = string.Format("Chunk[{0},{1}]\n({2}->{3})", chunkX, chunkY, a, b);
                    DrawString(debug, a + (b - a) / 2.0f, Color.yellow);
                }
            }

            DrawRect(window.position, window.position + window.size, Color.red);
            DrawString("Window", window.position, Color.red);
        }