Example #1
0
        public ControlContext(NavmeshBuild build, BuildTaskProcessor manager)
        {
            if (!build || manager == null)
                throw new System.ArgumentNullException();

            mTaskProcessor = manager;

            mBuild = build;
            mSelection = new TileSelection(build);
        }
Example #2
0
        public void OnRenderObject(NavmeshBuild build, TileSelection selection)
        {
            if (!build)
                return;

            TileSetDefinition tdef = build.TileSetDefinition;

            if (!mShow || !mEnabled || build != selection.Build || tdef == null)
                return;

            Color color = ControlUtil.SelectionColor;

            DebugDraw.SimpleMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            GL.Color(color);

            if (selection.Validate())
            {
                Vector3 bmin;
                Vector3 bmax;
                Vector3 trash;

                TileZone zone = selection.Zone;

                tdef.GetTileBounds(zone.xmin, zone.zmin, true, out bmin, out trash);
                tdef.GetTileBounds(zone.xmax, zone.zmax, true, out trash, out bmax);

                DebugDraw.AppendBounds(bmin, bmax);

                if (mIncludeRootTile)
                {
                    GL.Color(new Color(0.93f, 0.58f, 0.11f)); // Orange

                    tdef.GetTileBounds(selection.SelectedX, selection.SelectedZ, true
                        , out bmin, out bmax);

                    DebugDraw.AppendBounds(bmin, bmax);
                }
            }
            else
            {
                Vector3 bmax = tdef.BoundsMin;
                float tileSize = build.Config.TileWorldSize;
                bmax.x += tileSize * tdef.Width;
                bmax.y = tdef.BoundsMax.y;
                bmax.z += tileSize * tdef.Depth;

                DebugDraw.AppendBounds(tdef.BoundsMin, bmax);
            }

            GL.End();
        }
        public DebugViewContext(NavmeshBuild build, TileSelection selection) 
        {
            if (!build || selection == null)
                throw new System.ArgumentNullException();

            mSelectionView = new SelectionDebugView();
            mSelectionView.Enabled = true;
            mSelectionView.Show = true;
            mSelectionView.IncludeRootTile = true;

            mBuild = build;
            mSelection = selection;
        }
Example #4
0
        private void HandleWorkingNavmesh(TileSelection selection)
        {
            NavmeshBuild build = selection.Build;
            TileBuildData tdata = build.BuildData;

            if (mDebugObject == null)
            {
                Navmesh navmesh = null;

                if (tdata.BakeableCount() == 0)
                    // Nothing to display.
                    return;

                bool success = true;

                TileSetDefinition tdef = build.TileSetDefinition;

                NavmeshParams nconfig;
                NavmeshTileData[] tiles;

                if (tdef == null)
                {
                    tiles = new NavmeshTileData[1] { tdata.GetTileData(0, 0) };
                    nconfig = NavUtil.DeriveConfig(tiles[0]);
                }
                else
                {
                    TileZone zone;

                    if (selection.HasSelection)
                        zone = selection.Zone;
                    else
                        zone = new TileZone(0, 0, tdef.Width - 1, tdef.Depth - 1);

                    success = tdata.GetMeshBuildData(tdef.BoundsMin, tdef.TileWorldSize, zone
                        , out nconfig, out tiles);
                }

                NavStatus status = NavStatus.Sucess;

                if (success)
                {
                    status = Navmesh.Create(nconfig, out navmesh);

                    if ((status & NavStatus.Failure) == 0)
                    {
                        foreach (NavmeshTileData tile in tiles)
                        {
                            uint trash;
                            status = navmesh.AddTile(tile, Navmesh.NullTile, out trash);

                            if ((status & NavStatus.Sucess) == 0)
                            {
                                navmesh = null;
                                break;
                            }
                        }
                    }
                }

                if ((status & NavStatus.Sucess) == 0)
                {
                    Show = MeshDebugOption.None;  // Use property.
                    Debug.LogError("Mesh Debug View: Error creating working navigation mesh: "
                            + status + ". Disabled display.", build);
                }
                else
                    mDebugObject = navmesh;
            }

            if (mDebugObject != null)
            {
                Navmesh nm = (Navmesh)mDebugObject;
                NavDebug.Draw(nm, NavmeshSceneDraw.Instance.ColorByArea);
            }

        }
Example #5
0
        public void OnRenderObject(NavmeshBuild build, TileSelection selection)
        {
            if (!build)
                return;

            TileBuildData tdata = build.BuildData;

            if (!mEnabled
                || mShow == MeshDebugOption.None
                || tdata == null  // This restriction is appropriate.
                || build != selection.Build)  // Important error check.
            {
                return;
            }

            INavmeshData target = build.BuildTarget;

            if (target != null && target.HasNavmesh && NavmeshSceneDraw.Instance.IsShown(target))
                // Don't overdraw the target mesh's display.  It has priority.
                return;

            if (tdata.Version != mLastVersion)
            {
                // Build data has changed.  Clear debug object.
                mLastVersion = tdata.Version;
                mDebugObject = null;
            }

            int tx = 0;
            int tz = 0;
            int size = 0;

            if (tdata.IsTiled)
            {
                tx = selection.SelectedX;
                tz = selection.SelectedZ;
                size = selection.ZoneSize;
            }

            if (mLastX != tx || mLastZ != tz || mLastSize != size)
            {
                // Change in selection.  Clear debug object.
                mLastX = tx;
                mLastZ = tz;
                mLastSize = size;
                mDebugObject = null;
                // Debug.Log("Clear debug on selection change.");
            }

            if (mShow == MeshDebugOption.WorkingMesh)
            {
                HandleWorkingNavmesh(selection);
                return;
            }
            else if (tdata.IsTiled && !selection.Validate())
            {
                // The mesh is tiled with no valid selection.
                // Can't display any of the other meshes.
                mLastX = -1;
                mLastZ = -1;
                mLastSize = -1;
                return;
            }

            // Can only display a single tile for all other display options.
            // Choose the tile to display.

            switch (mShow)
            {
                case MeshDebugOption.PolyMesh:

                    HandlePolyMesh(build, tx, tz);
                    break;

                case MeshDebugOption.Detailmesh:

                    HandleDetailMesh(build, tx, tz);
                    break;

                case MeshDebugOption.InputGeometry:

                    if (build.TileSetDefinition != null)
                        HandleInputGeom(build, tx, tz);
                    break;
            }
        }