public SerializedNormalConnection(NavmeshLayserSerializer ns, GraphSerializer gs, CellContentGenericConnection connection)
 {
     interconnection = connection.interconnection;
     fromCell        = ns.GetCellID(connection.from);
     connectedCell   = ns.GetCellID(connection.connection);
     data            = connection.cellData;
     intersection    = connection.intersection;
     costFrom        = connection.costFrom;
     costTo          = connection.costTo;
 }
Exemple #2
0
        public SerializedCell(NavmeshLayserSerializer ns, GraphSerializer gs, Cell cell)
        {
            id    = ns.GetCellID(cell);
            layer = cell.layer;

            isAdvancedAreaCell = cell.advancedAreaCell;
            if (cell.advancedAreaCell)
            {
                AreaAdvanced aa = cell.area as AreaAdvanced;
                area = ns.GetGameObjectID(aa.container.gameObject);
            }
            else
            {
                area = cell.area.id;
            }

            passability = (int)cell.passability;
            center      = cell.centerVector3;

            data          = new List <CellContentData>(cell.data);
            originalEdges = new List <CellContentData>(cell.originalEdges);

            foreach (var connection in cell.connections)
            {
                if (connection is CellContentGenericConnection)
                {
                    serializedNormalConnections.Add(new SerializedNormalConnection(ns, gs, connection as CellContentGenericConnection));
                }

                if (connection is CellContentPointedConnection)
                {
                    serializedJumpConnections.Add(new SerializedJumpConnection(ns, connection as CellContentPointedConnection));
                }
            }
        }
 public SerializedJumpConnection(NavmeshLayserSerializer ns, CellContentPointedConnection connection)
 {
     interconnection    = connection.interconnection;
     connectedCell      = ns.GetCellID(connection.connection);
     enterPoint         = connection.enterPoint;
     lowerStandingPoint = connection.lowerStandingPoint;
     exitPoint          = connection.exitPoint;
     axis      = connection.axis;
     jumpState = (int)connection.jumpState;
 }
        public SerializedCover(NavmeshLayserSerializer ns, Cover cover)
        {
            coverType = cover.coverType;
            left      = cover.left;
            right     = cover.right;
            normal    = cover.normalV3;

            foreach (var p in cover.coverPoints)
            {
                coverPoints.Add(new SerializedCoverPoint(p, ns.GetCellID(p.cell)));
            }
        }
        public SerializedCell(NavmeshLayserSerializer ns, GraphSerializer gs, Cell cell)
        {
            id          = ns.GetCellID(cell);
            layer       = cell.layer;
            area        = cell.area.id;
            passability = (int)cell.passability;
            center      = cell.centerV3;

            data          = new List <CellContentData>(cell.data);
            originalEdges = new List <CellContentData>(cell.originalEdges);

            foreach (var connection in cell.connections)
            {
                if (connection is CellContentGenericConnection)
                {
                    serializedNormalConnections.Add(new SerializedNormalConnection(ns, gs, connection as CellContentGenericConnection));
                }

                if (connection is CellContentPointedConnection)
                {
                    serializedJumpConnections.Add(new SerializedJumpConnection(ns, connection as CellContentPointedConnection));
                }
            }
        }
        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);
        }