예제 #1
0
        public static SceneDefinition Create(Scene.NavMesh mesh, NavZone zone, NavZoneDef navZoneDef)
        {
            var filePath = string.Format("{0}{1}.json", SCENES_PATH, mesh.SceneSnoId);

            if (USE_DISK_CACHE)
            {
                if (File.Exists(filePath))
                {
                    var fileContent = File.ReadAllText(filePath);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        var savedScene = JsonSerializer.Deserialize <SceneDefinition>(fileContent);
                        if (savedScene != null)
                        {
                            return(savedScene);
                        }
                    }
                }
            }
            var sceneDefinition = new SceneDefinition {
                SceneSNO = mesh.SceneSnoId
            };

            #region NavCells
            var cachedNavCells = new List <NavCellDefinition>();
            var sceneNavCells  = navZoneDef.NavCells.ToList();

            if (sceneNavCells.Count > 0)
            {
                cachedNavCells.AddRange(sceneNavCells.Select(NavCellDefinition.Create));
            }
            sceneDefinition.NavCellDefinitions = cachedNavCells;
            #endregion


            if (USE_DISK_CACHE)
            {
                var serializedScene = JsonSerializer.Serialize(sceneDefinition);
                File.WriteAllText(filePath, serializedScene);
            }
            Logger.Warn("[GridProvider] Added SceneDefinition {0} (Dimensions: {1}, NavCells: {2})", sceneDefinition.SceneSNO, zone.ZoneMax - zone.ZoneMin, sceneDefinition.NavCellDefinitions.Count);
            return(sceneDefinition);
        }
예제 #2
0
        private void CreateGrid(Scene.NavMesh mesh)
        {
            if (GridCreated)
            {
                return;
            }

            Cells = new List <WorldSceneCell>();

            foreach (var navCell in mesh.Zone.NavZoneDef.NavCells)
            {
                Cells.Add(new WorldSceneCell(navCell, Min));
            }
            if (SubScene != null)
            {
                foreach (var navCell in SubScene.Cells)
                {
                    Cells.Add(navCell);
                }
                if (SubScene.SubScene != null)
                {
                    foreach (var navCell in SubScene.SubScene.Cells)
                    {
                        Cells.Add(navCell);
                    }
                }
            }

            var navBoxSize      = ExplorationData.ExplorationNodeBoxSize;
            var searchBeginning = navBoxSize / 2;

            for (var x = Min.X + searchBeginning; x <= Max.X; x = x + navBoxSize)
            {
                for (var y = Min.Y + searchBeginning; y <= Max.Y; y = y + navBoxSize)
                {
                    var navNode = new ExplorationNode(new Vector2(x, y), _boxSize, _boxTolerance, this);
                    Nodes.Add(navNode);
                }
            }

            GridCreated     = true;
            GridCreatedTime = DateTime.UtcNow;
        }
예제 #3
0
        public static GridScene Create(Scene scene, Scene.NavMesh mesh, NavZone zone)
        {
            var gridScene = new GridScene();

            gridScene.SceneSNO        = mesh.SceneSnoId;
            gridScene.WorldId         = mesh.WorldId;
            gridScene.LevelAreaSNO    = mesh.LevelAreaSnoId;
            gridScene.Name            = scene.Name;
            gridScene.NameHash        = GridProvider.GetSceneNameHash(mesh, zone);
            gridScene.Min             = zone.ZoneMin;
            gridScene.Max             = zone.ZoneMax;
            gridScene.Center          = (gridScene.Max + gridScene.Min) / 2;
            gridScene.SceneDefinition = GridProvider.SceneDefinitions[mesh.SceneSnoId];
            gridScene.BaseHeight      = mesh.BaseHeight;

            //#region GridNodes

            var         gridNodes       = new List <GridNode>();
            var         sceneDimensions = zone.ZoneMax - zone.ZoneMin;
            const float searchBeginning = GridProvider.GridNodeBoxSize / 2;

            for (var x = searchBeginning; x <= sceneDimensions.X; x = x + GridProvider.GridNodeBoxSize)
            {
                for (var y = searchBeginning; y <= sceneDimensions.Y; y = y + GridProvider.GridNodeBoxSize)
                {
                    var cell = gridScene.SceneDefinition.NavCellDefinitions.FirstOrDefault(c => c.IsInCell(x, y));
                    if (cell != null)
                    {
                        var gridNode = GridNode.Create(new Vector2(x, y), gridScene, cell);
                        gridNodes.Add(gridNode);
                    }
                }
            }
            gridScene.GridNodes = gridNodes;
            //#endregion

            return(gridScene);
        }
예제 #4
0
 public static string GetSceneNameHash(Scene.NavMesh mesh, NavZone navZone)
 {
     return(string.Format("{0}-{1}-{2}-{3}-{4}", mesh.SceneSnoId, mesh.WorldId, mesh.LevelAreaSnoId, navZone.ZoneMin, navZone.ZoneMax));
 }