예제 #1
0
        void DoDrawGizmos()
        {
            Vector3 savedPos = transform.position;

            transform.position += (Vector3)(Vector2.Scale(Camera.current.transform.position, (Vector2.one - m_parallaxFactor))); //apply parallax
            Rect rBound = new Rect(MapBounds.min, MapBounds.size);

            HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 1, 1, 0.5f));

            if (ShowGrid)
            {
                Plane tilemapPlane     = new Plane(this.transform.forward, this.transform.position);
                float distCamToTilemap = 0f;
                Ray   rayCamToPlane    = new Ray(Camera.current.transform.position, Camera.current.transform.forward);
                tilemapPlane.Raycast(rayCamToPlane, out distCamToTilemap);
                if (HandleUtility.GetHandleSize(rayCamToPlane.GetPoint(distCamToTilemap)) <= 3f)
                {
                    // draw tile cells
                    Gizmos.color = EditorGlobalSettings.TilemapGridColor;

                    // Horizontal lines
                    for (float i = 1; i < GridWidth; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.min.y)),
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.max.y))
                            );
                    }

                    // Vertical lines
                    for (float i = 1; i < GridHeight; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x, MapBounds.min.y + i * CellSize.y, 0)),
                            this.transform.TransformPoint(new Vector3(MapBounds.max.x, MapBounds.min.y + i * CellSize.y, 0))
                            );
                    }
                }
                Gizmos.color = Color.white;
            }

            //Draw Chunk Colliders
            var valueIter = m_dicChunkCache.Values.GetEnumerator();

            while (valueIter.MoveNext())
            {
                TilemapChunk chunk = valueIter.Current;
                if (chunk)
                {
                    string[] asChunkCoords = chunk.name.Split(new char[] { '_' }, System.StringSplitOptions.RemoveEmptyEntries);
                    int      chunkX        = int.Parse(asChunkCoords[0]);
                    int      chunkY        = int.Parse(asChunkCoords[1]);
                    rBound = new Rect(chunkX * k_chunkSize * CellSize.x, chunkY * k_chunkSize * CellSize.y, k_chunkSize * CellSize.x, k_chunkSize * CellSize.y);
                    HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 0, 0, 0.2f));
                    chunk.DrawColliders();
                }
            }
            //
            transform.position = savedPos; // restore position
        }
예제 #2
0
        void DoDrawGizmos()
        {
            Rect rBound = new Rect(MapBounds.min, MapBounds.size);

            HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 1, 1, 0.5f));

            if (ShowGrid)
            {
                Plane tilemapPlane     = new Plane(this.transform.forward, this.transform.position);
                float distCamToTilemap = 0f;
                Ray   rayCamToPlane    = new Ray(Camera.current.transform.position, Camera.current.transform.forward);
                tilemapPlane.Raycast(rayCamToPlane, out distCamToTilemap);
                if (HandleUtility.GetHandleSize(rayCamToPlane.GetPoint(distCamToTilemap)) <= 3f)
                {
                    // draw tile cells
                    Gizmos.color = new Color(1f, 1f, 1f, .2f);

                    // Horizontal lines
                    for (float i = 1; i < GridWidth; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.min.y)),
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x + i * CellSize.x, MapBounds.max.y))
                            );
                    }

                    // Vertical lines
                    for (float i = 1; i < GridHeight; i++)
                    {
                        Gizmos.DrawLine(
                            this.transform.TransformPoint(new Vector3(MapBounds.min.x, MapBounds.min.y + i * CellSize.y, 0)),
                            this.transform.TransformPoint(new Vector3(MapBounds.max.x, MapBounds.min.y + i * CellSize.y, 0))
                            );
                    }
                }
            }

            //Draw Chunk Colliders
            for (int i = 0; i < transform.childCount; ++i)
            {
                TilemapChunk chunk = transform.GetChild(i).GetComponent <TilemapChunk>();
                if (chunk != null)
                {
                    string[] asChunkCoords = chunk.name.Split(new char[] { '_' }, System.StringSplitOptions.RemoveEmptyEntries);
                    int      chunkX        = int.Parse(asChunkCoords[0]);
                    int      chunkY        = int.Parse(asChunkCoords[1]);
                    rBound = new Rect(chunkX * k_chunkSize * CellSize.x, chunkY * k_chunkSize * CellSize.y, k_chunkSize * CellSize.x, k_chunkSize * CellSize.y);
                    HandlesEx.DrawRectWithOutline(transform, rBound, new Color(0, 0, 0, 0), new Color(1, 0, 0, 0.2f));
                    chunk.DrawColliders();
                }
            }
            //
        }