private void OnEnable()
 {
     GizmoDummy.Init();
     SceneView.onSceneGUIDelegate += OnSceneGUI;
 }
    static void DrawGizmo(GizmoDummy dummy, GizmoType gizmoType)
    {
        var va = RecastNaviMesh.Instance.GetArea();

        #region Draw Voxel
        if (va != null && _debug_DrawVoxel == true)
        {
            Color c = Color.red; c.a = 0.7f;
            Gizmos.color = c;

            foreach (var ele in va.Voxels.Values)
            {
                if (ele._ex)
                {
                    continue;
                }
                if (!ele.IsTop)
                {
                    continue;
                }
                if (ele.FaceReverse)
                {
                    continue;
                }

                int count = 1;
                if (ele.IsSpan)
                {
                    for (Voxel vc = ele; ; ++count)
                    {
                        if (vc.IsBottom == true)
                        {
                            break;
                        }
                        vc = va.GetCell(vc.SpanNext);
                        if (vc == null)
                        {
                            break;
                        }
                    }
                }

                Vector3 tmp;
                if (!va.GetCellPosition(ele.Index, out tmp))
                {
                    continue;
                }

                tmp.y = tmp.y - (_cellHeight * count * 0.5f) + _cellHeight * 0.5f;
                Gizmos.DrawCube(tmp, new Vector3(_cellSize, _cellHeight * count, _cellSize));
            }
        }
        #endregion

        #region Draw Reverse Voxel
        if (va != null && _debug_DrawReverseVoxel == true)
        {
            Color c = Color.white; c.a = 0.7f;
            Gizmos.color = c;

            foreach (var ele in va.Voxels.Values)
            {
                if (ele._ex)
                {
                    continue;
                }
                if (!ele.IsTop)
                {
                    continue;
                }
                if (!ele.FaceReverse)
                {
                    continue;
                }

                int count = 1;
                if (ele.IsSpan)
                {
                    for (Voxel vc = ele; ; ++count)
                    {
                        if (vc.IsBottom == true)
                        {
                            break;
                        }
                        vc = va.GetCell(vc.SpanNext);
                        if (vc == null)
                        {
                            break;
                        }
                    }
                }

                Vector3 tmp;
                if (!va.GetCellPosition(ele.Index, out tmp))
                {
                    continue;
                }

                tmp.y = tmp.y - (_cellHeight * count * 0.5f) + _cellHeight * 0.5f;
                Gizmos.DrawCube(tmp, new Vector3(_cellSize, _cellHeight * count, _cellSize));
            }
        }
        #endregion

        #region Draw Distance
        if (va != null && _debug_DrawDistance == true)
        {
            foreach (var ele in RecastNaviMesh.Instance.GetWalkable())
            {
                Vector3 tmp;
                if (!va.GetCellPosition(ele.Index, out tmp))
                {
                    continue;
                }
                float colorFactor = 1f; // white
                if (ele.Distance != null)
                {
                    colorFactor = (float)ele.Distance.Value * (float)ele.Distance.Value / (float)RecastNaviMesh.Instance._maxDistance * 0.3f;
                }

                Color c = Color.white;
                c.r          = c.g = c.b = colorFactor;
                Gizmos.color = c;

                Gizmos.DrawCube(tmp, new Vector3(_cellSize, _cellHeight, _cellSize));
            }
        }
        #endregion

        #region Draw Walkable Cell
        if (va != null && _debug_DrawWalkable == true)
        {
            foreach (var ele in RecastNaviMesh.Instance.GetWalkable())
            {
                if (ele.Legde)
                {
                    continue;
                }

                Vector3 tmp;
                if (!va.GetCellPosition(ele.Index, out tmp))
                {
                    continue;
                }
                Gizmos.color = Color.green;

                Gizmos.DrawCube(tmp, new Vector3(_cellSize, _cellHeight, _cellSize));
            }
        }
        #endregion

        #region Draw First Ledge
        if (va != null && _debug_DrawFirstLedge == true)
        {
            Gizmos.color = Color.gray;
            foreach (var ele in RecastNaviMesh.Instance._firstLedge)
            {
                Vector3 tmp;
                if (!va.GetCellPosition(ele.Index, out tmp))
                {
                    continue;
                }
                Gizmos.DrawCube(tmp, new Vector3(_cellSize, _cellHeight, _cellSize));
            }
        }
        #endregion

        #region Draw Ledge
        if (va != null && _debug_DrawLedge == true)
        {
            Color c = Color.cyan; c.a = 0.7f;
            Gizmos.color = c;

            foreach (var ele in RecastNaviMesh.Instance.GetWalkable())
            {
                if (!ele.Legde)
                {
                    continue;
                }
                Vector3 tmp;
                if (!va.GetCellPosition(ele.Index, out tmp))
                {
                    continue;
                }

                Gizmos.DrawCube(tmp, new Vector3(_cellSize, _cellHeight, _cellSize));
            }
        }
        #endregion

        if (RecastNaviMesh.Instance._contours.Count != 0)
        {
            Gizmos.color = Color.magenta;
            Vector3 prev = Vector3.zero;
            foreach (var ele in RecastNaviMesh.Instance._contours)
            {
                bool bFirst = true;
                foreach (var v in ele)
                {
                    Gizmos.DrawCube(v, Vector3.one * 0.01f);
                    if (bFirst)
                    {
                        prev = v; bFirst = false; continue;
                    }
                    Gizmos.DrawLine(prev, v);
                    prev = v;
                }
            }
        }
    }
示例#3
0
 private void OnEnable()
 {
     GizmoDummy.Init();
     SceneView.onSceneGUIDelegate += OnSceneGUI;
     _enableWindow = true;
 }
示例#4
0
    static void DrawGizmo(GizmoDummy dummy, GizmoType gizmoType)
    {
        if (!_enableWindow)
        {
            return;
        }
        Gizmos.color = Color.cyan;

        switch (_boundType)
        {
        case BoundType.Box2D:
            _box.DrawGizmo();
            break;

        case BoundType.AABox3D:
            _aaBox.DrawGizmo();
            break;

        case BoundType.Cube:
            _cube.DrawGizmo();
            break;

        case BoundType.Circle:
            _circle.DrawGizmo();
            break;

        case BoundType.Capsule:
            _capsule.DrawGizmo();
            break;

        case BoundType.Sector:
            _sector.DrawGizmo();
            break;
        }

        Gizmos.color = _lineColor;
        switch (_testMode)
        {
        case TestMode.Line2D:
            Gizmos.DrawLine(_prevClickedPos, _currentClickedPos);
            break;

        case TestMode.Ray2D:
            Gizmos.DrawRay(_currentClickedPos, (_prevClickedPos - _currentClickedPos) * 100);
            break;

        case TestMode.Box2D:
            _testBox.DrawGizmo();
            break;

        case TestMode.LerpBox2D:
            Gizmos.DrawLine(_prevClickedPos, _currentClickedPos);
            _testBox.DrawGizmo();
            break;

        case TestMode.AABox3D:
            _testAABox.DrawGizmo();
            break;

        case TestMode.Triangle:
            _testTriangle.DrawGizmo();
            break;

        case TestMode.Sector2D:
            _testSector.DrawGizmo();
            break;

        case TestMode.Circle2D:
            _testCircle.DrawGizmo();
            break;
        }

        if (_boundType == BoundType.Circle && _testMode == TestMode.Sector2D)
        {
            Vector2 lineR, lineL;
            ZKit.Math.Geometry.Collision2D.GetExTangentOnCircle(_circle.position2D, _circle.radius, _testSector.position2D, out lineR, out lineL);
            Gizmos.color = Color.red;
            Gizmos.DrawLine(_testSector.position, new Vector3(lineR.x, _circle.position.y, lineR.y));
            Gizmos.color = Color.green;
            Gizmos.DrawLine(_testSector.position, new Vector3(lineL.x, _circle.position.y, lineL.y));
        }
        if (_boundType == BoundType.Sector && _testMode == TestMode.Circle2D)
        {
            Vector2 lineR, lineL;
            ZKit.Math.Geometry.Collision2D.GetExTangentOnCircle(_testCircle.position2D, _testCircle.radius, _sector.position2D, out lineR, out lineL);
            Gizmos.color = Color.red;
            Gizmos.DrawLine(_sector.position, new Vector3(lineR.x, _testCircle.position.y, lineR.y));
            Gizmos.color = Color.green;
            Gizmos.DrawLine(_sector.position, new Vector3(lineL.x, _testCircle.position.y, lineL.y));
        }
    }
示例#5
0
 private void OnEnable()
 {
     GizmoDummy.Init();
     SceneView.onSceneGUIDelegate += OnSceneGUI;
     _cells = new PackCellData();
 }
示例#6
0
    static void DrawGizmo(GizmoDummy dummy, GizmoType gizmoType)
    {
        if (_cells == null || _cells.IsEmpty)
        {
            return;
        }

        #region Draw Cell Grid
        if (_showGrid)
        {
            for (int y = 0; y < _cells.CountY; ++y)
            {
                for (int x = 0; x < _cells.CountX; ++x)
                {
                    Gizmos.color = Color.white;
                    if (_cells[y, x].Type != CellType.Normal)
                    {
                        continue;
                    }
                    CellData currentCell = _cells[y, x];
                    // right
                    if (_cells.IsExist(x + 1, y))
                    {
                        CellData nextCell = _cells[y, x + 1];
                        if (nextCell.Type == CellType.Normal)
                        {
                            if (UnityEngine.Mathf.Abs(currentCell.Height - nextCell.Height) < _cells.HeightLimit)
                            {
                                Vector3 from = _cells.GetPosVec3(new Point(x, y), currentCell.Height + _gridGap);
                                Vector3 to   = _cells.GetPosVec3(new Point(x + 1, y), nextCell.Height + _gridGap);
                                Gizmos.DrawLine(from, to);
                            }
                        }
                    }
                    // up
                    if (_cells.IsExist(x, y + 1))
                    {
                        CellData nextCell = _cells[y + 1, x];
                        if (nextCell.Type == CellType.Normal)
                        {
                            if (UnityEngine.Mathf.Abs(currentCell.Height - nextCell.Height) < _cells.HeightLimit)
                            {
                                Vector3 from = _cells.GetPosVec3(new Point(x, y), currentCell.Height + _gridGap);
                                Vector3 to   = _cells.GetPosVec3(new Point(x, y + 1), nextCell.Height + _gridGap);
                                Gizmos.DrawLine(from, to);
                            }
                        }
                    }
                    Gizmos.color = Color.cyan;
                    // 퍼포먼스를 위해 가까운것만 그리자.
                    if (Vector3.Distance(_cells.GetPosVec3(currentCell.Index, currentCell.Height), SceneView.lastActiveSceneView.camera.transform.position) < _viewDistance)
                    {
                        // right up
                        if (_cells.IsExist(x + 1, y + 1))
                        {
                            CellData nextCell = _cells[y + 1, x + 1];
                            if (nextCell.Type == CellType.Normal)
                            {
                                if (UnityEngine.Mathf.Abs(currentCell.Height - nextCell.Height) < _cells.HeightLimit)
                                {
                                    Vector3 from = _cells.GetPosVec3(new Point(x, y), currentCell.Height + _gridGap);
                                    Vector3 to   = _cells.GetPosVec3(new Point(x + 1, y + 1), nextCell.Height + _gridGap);
                                    Gizmos.DrawLine(from, to);
                                }
                            }
                        }
                        // left up
                        if (_cells.IsExist(x - 1, y + 1))
                        {
                            CellData nextCell = _cells[y + 1, x - 1];
                            if (nextCell.Type == CellType.Normal)
                            {
                                if (UnityEngine.Mathf.Abs(currentCell.Height - nextCell.Height) < _cells.HeightLimit)
                                {
                                    Vector3 from = _cells.GetPosVec3(new Point(x, y), currentCell.Height + _gridGap);
                                    Vector3 to   = _cells.GetPosVec3(new Point(x - 1, y + 1), nextCell.Height + _gridGap);
                                    Gizmos.DrawLine(from, to);
                                }
                            }
                        }
                    }
                }
            }
        }
        #endregion

        #region Draw TestHero
        if (_testMode)
        {
            Gizmos.color = Color.blue;
            Vector3 pos = _testAsHero; pos.y += 1f + _gridGap;
            Gizmos.DrawWireCube(pos, new Vector3(1f, 2f, 1f));
            Gizmos.DrawWireCube(pos, new Vector3(0.7f, 1.8f, 0.7f));
            Color c = Color.yellow; c.a = 0.5f;
            Gizmos.color = c;
            Gizmos.DrawCube(pos, new Vector3(1f, 2f, 1f));
            c.a          = 1.0f;
            Gizmos.color = c;
            Gizmos.DrawCube(pos, new Vector3(0.7f, 1.8f, 0.7f));

            //Gizmos.color = Color.blue;
            //pos = _testJpsHero; pos.y += 1f + _gridGap;
            //Gizmos.DrawWireCube(pos, new Vector3(1f, 2f, 1f));
            //Gizmos.DrawWireCube(pos, new Vector3(0.7f, 1.8f, 0.7f));
            //c = Color.red; c.a = 0.5f;
            //Gizmos.color = c;
            //Gizmos.DrawCube(pos, new Vector3(1f, 2f, 1f));
            //c.a = 1.0f;
            //Gizmos.color = c;
            //Gizmos.DrawCube(pos, new Vector3(0.7f, 1.8f, 0.7f));
        }
        #endregion
    }