Cell[] cellPool; //shortcut to cell pool

        public GraphDeserializer(SerializedGraph serializedGraph, NavmeshLayerDeserializer deserializer)
        {
            this.serializedGraph = serializedGraph;
            this.deserializer    = deserializer;
            targetGraph          = new Graph();

            //nodes = new Node[this.serializedGraph.serializedNodes.Count];
            //edges = new EdgeGraph[this.serializedGraph.serializedEdges.Count];

            cellPool = deserializer.cellPool;
        }
Beispiel #2
0
        Cell[] cellPool; //shortcut to cell pool

        public GraphDeserializer(SerializedGraph serializedGraph, NavmeshLayerDeserializer deserializer, AgentProperties properties)
        {
            this.serializedGraph = serializedGraph;
            this.deserializer    = deserializer;
            targetGraph          = new Graph(serializedGraph.chunkData, properties);

            //nodes = new Node[this.serializedGraph.serializedNodes.Count];
            //edges = new EdgeGraph[this.serializedGraph.serializedEdges.Count];

            cellPool = deserializer.cellPool;
        }
        public SerializedGraph Serialize()
        {
            SerializedGraph serializedGraph = new SerializedGraph();

            serializedGraph.posX = graph.chunk.x;
            serializedGraph.posZ = graph.chunk.z;
            serializedGraph.minY = graph.chunk.min;
            serializedGraph.maxY = graph.chunk.max;

            List <SerializedCell>  serializedCells  = new List <SerializedCell>();
            List <SerializedCover> serializedCovers = new List <SerializedCover>();

            foreach (var cell in graph.cells)
            {
                serializedCells.Add(new SerializedCell(ns, this, cell));
            }

            foreach (var cover in graph.covers)
            {
                serializedCovers.Add(new SerializedCover(ns, cover));
            }

            serializedGraph.serializedCells  = serializedCells;
            serializedGraph.serializedCovers = serializedCovers;

            //battlegrid
            if (graph.battleGrid != null)
            {
                serializedGraph.battleGrid = new SerializedBattleGrid(ns, graph.battleGrid);
            }
            else
            {
                serializedGraph.battleGrid = null;
            }

            //cell map
            var cellMap = graph.getCellMap;

            if (cellMap != null)
            {
                List <SerializableVector3Int> serializedCellMap = new List <SerializableVector3Int>();

                for (int x = 0; x < cellMap.Length; x++)
                {
                    for (int z = 0; z < cellMap[x].Length; z++)
                    {
                        for (int id = 0; id < cellMap[x][z].Count; id++)
                        {
                            serializedCellMap.Add(new SerializableVector3Int(x, z, ns.GetCellID(cellMap[x][z][id])));
                        }
                    }
                }


                //Debug.Log("write cell map");
                serializedGraph.cellMapData = serializedCellMap;
                //Debug.Log(serializedGraph.cellMapData == null);
            }
            else
            {
                Debug.Log("cell map null");
                serializedGraph.cellMapData = null;
            }

            //contour dictionary
            if (graph.getContour != null)
            {
                List <SerializedContourData> contour = new List <SerializedContourData>();
                foreach (var pair in graph.getContour)
                {
                    contour.Add(new SerializedContourData(pair.Key.a, pair.Key.b, ns.GetCellID(pair.Value)));
                }
                serializedGraph.contour = contour;
            }
            else
            {
                serializedGraph.contour = null;
            }

            //border
            List <SerializedBorderData> serializedBorder = new List <SerializedBorderData>();

            for (int i = 0; i < 4; i++)
            {
                var curSide = graph.GetBorderEdges((Directions)i);
                foreach (var pair in curSide)
                {
                    serializedBorder.Add(new SerializedBorderData(pair.Key.a, pair.Key.b, ns.GetCellID(pair.Value), i));
                }
            }
            serializedGraph.borderData = serializedBorder;

            //foreach (var cell in serializedCells) {
            //    Debug.Log(cell.ToString());
            //}
            return(serializedGraph);
        }