Inheritance: GridGraph, IRaycastableGraph, IUpdatableGraph
        // Token: 0x06002509 RID: 9481 RVA: 0x0019CDFC File Offset: 0x0019AFFC
        public override bool GetPortal(GraphNode other, List <Vector3> left, List <Vector3> right, bool backwards)
        {
            if (backwards)
            {
                return(true);
            }
            LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            int             nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255 && other == nodes[nodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue])
                {
                    Vector3 a      = (Vector3)(this.position + other.position) * 0.5f;
                    Vector3 vector = Vector3.Cross(gridGraph.collision.up, (Vector3)(other.position - this.position));
                    vector.Normalize();
                    vector *= gridGraph.nodeSize * 0.5f;
                    left.Add(a - vector);
                    right.Add(a + vector);
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        public override void UpdateRecursiveG(Path path, PathNode pathNode, PathHandler handler)
        {
            handler.heap.Add(pathNode);
            base.UpdateG(path, pathNode);
            LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            int             nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255)
                {
                    LevelGridNode levelGridNode = nodes[nodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                    PathNode      pathNode2     = handler.GetPathNode(levelGridNode);
                    if (pathNode2 != null && pathNode2.parent == pathNode && pathNode2.pathID == handler.PathID)
                    {
                        levelGridNode.UpdateRecursiveG(path, pathNode2, handler);
                    }
                }
            }
            base.UpdateRecursiveG(path, pathNode, handler);
        }
示例#3
0
        public override bool GetPortal(GraphNode other, List <Vector3> left, List <Vector3> right, bool backwards)
        {
            if (backwards)
            {
                return(true);
            }
            LayerGridGraph gridGraph = GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            int             nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if ((connectionValue != 15) && (other == nodes[(nodeInGridIndex + neighbourOffsets[i]) + ((gridGraph.lastScannedWidth * gridGraph.lastScannedDepth) * connectionValue)]))
                {
                    Vector3 vector  = (Vector3)(((Vector3)(base.position + other.position)) * 0.5f);
                    Vector3 vector2 = Vector3.Cross(gridGraph.collision.up, (Vector3)(other.position - base.position));
                    vector2.Normalize();
                    vector2 = (Vector3)(vector2 * (gridGraph.nodeSize * 0.5f));
                    left.Add(vector - vector2);
                    right.Add(vector + vector2);
                    return(true);
                }
            }
            return(false);
        }
 // Token: 0x06002502 RID: 9474 RVA: 0x0019CBC4 File Offset: 0x0019ADC4
 public override GridNodeBase GetNeighbourAlongDirection(int direction)
 {
     if (this.GetConnection(direction))
     {
         LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);
         return(gridGraph.nodes[base.NodeInGridIndex + gridGraph.neighbourOffsets[direction] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * this.GetConnectionValue(direction)]);
     }
     return(null);
 }
示例#5
0
 public static void SetGridGraph(int graphIndex, LayerGridGraph graph)
 {
     if (_gridGraphs.Length <= graphIndex)
     {
         LayerGridGraph[] graphArray = new LayerGridGraph[graphIndex + 1];
         for (int i = 0; i < _gridGraphs.Length; i++)
         {
             graphArray[i] = _gridGraphs[i];
         }
         _gridGraphs = graphArray;
     }
     _gridGraphs[graphIndex] = graph;
 }
示例#6
0
 public static void SetGridGraph(int graphIndex, LayerGridGraph graph)
 {
     if (LevelGridNode._gridGraphs.Length <= graphIndex)
     {
         LayerGridGraph[] array = new LayerGridGraph[graphIndex + 1];
         for (int i = 0; i < LevelGridNode._gridGraphs.Length; i++)
         {
             array[i] = LevelGridNode._gridGraphs[i];
         }
         LevelGridNode._gridGraphs = array;
     }
     LevelGridNode._gridGraphs[graphIndex] = graph;
 }
示例#7
0
 public static void SetGridGraph(int graphIndex, LayerGridGraph graph)
 {
     if (LevelGridNode._gridGraphs.Length <= graphIndex)
     {
         LayerGridGraph[] array = new LayerGridGraph[graphIndex + 1];
         for (int i = 0; i < LevelGridNode._gridGraphs.Length; i++)
         {
             array[i] = LevelGridNode._gridGraphs[i];
         }
         LevelGridNode._gridGraphs = array;
     }
     LevelGridNode._gridGraphs[graphIndex] = graph;
 }
示例#8
0
        public override void Open(Path path, PathNode pathNode, PathHandler handler)
        {
            LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            uint[]          neighbourCosts   = gridGraph.neighbourCosts;
            LevelGridNode[] nodes            = gridGraph.nodes;
            int             nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255)
                {
                    GraphNode graphNode = nodes[nodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                    if (path.CanTraverse(graphNode))
                    {
                        PathNode pathNode2 = handler.GetPathNode(graphNode);
                        if (pathNode2.pathID != handler.PathID)
                        {
                            pathNode2.parent = pathNode;
                            pathNode2.pathID = handler.PathID;
                            pathNode2.cost   = neighbourCosts[i];
                            pathNode2.H      = path.CalculateHScore(graphNode);
                            graphNode.UpdateG(path, pathNode2);
                            handler.heap.Add(pathNode2);
                        }
                        else
                        {
                            uint num = neighbourCosts[i];
                            if (pathNode.G + num + path.GetTraversalCost(graphNode) < pathNode2.G)
                            {
                                pathNode2.cost   = num;
                                pathNode2.parent = pathNode;
                                graphNode.UpdateRecursiveG(path, pathNode2, handler);
                            }
                            else if (pathNode2.G + num + path.GetTraversalCost(this) < pathNode.G)
                            {
                                pathNode.parent = pathNode2;
                                pathNode.cost   = num;
                                this.UpdateRecursiveG(path, pathNode, handler);
                            }
                        }
                    }
                }
            }
            base.Open(path, pathNode, handler);
        }
示例#9
0
        public override void GetConnections(GraphNodeDelegate del)
        {
            int            num       = this.NodeInGridIndex;
            LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255)
                {
                    LevelGridNode levelGridNode = nodes[num + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                    if (levelGridNode != null)
                    {
                        del(levelGridNode);
                    }
                }
            }
        }
        // Token: 0x06002505 RID: 9477 RVA: 0x0019CD10 File Offset: 0x0019AF10
        public override void FloodFill(Stack <GraphNode> stack, uint region)
        {
            int            nodeInGridIndex = base.NodeInGridIndex;
            LayerGridGraph gridGraph       = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255)
                {
                    LevelGridNode levelGridNode = nodes[nodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                    if (levelGridNode != null && levelGridNode.Area != region)
                    {
                        levelGridNode.Area = region;
                        stack.Push(levelGridNode);
                    }
                }
            }
        }
示例#11
0
        public override void FloodFill(Stack <GraphNode> stack, uint region)
        {
            int            nodeInGridIndex = base.NodeInGridIndex;
            LayerGridGraph gridGraph       = GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 15)
                {
                    LevelGridNode t = nodes[(nodeInGridIndex + neighbourOffsets[i]) + ((gridGraph.lastScannedWidth * gridGraph.lastScannedDepth) * connectionValue)];
                    if ((t != null) && (t.Area != region))
                    {
                        t.Area = region;
                        stack.Push(t);
                    }
                }
            }
        }
示例#12
0
        public override void GetConnections(Action <GraphNode> action)
        {
            LayerGridGraph gridGraph = LevelGridNode.GetGridGraph(base.GraphIndex);

            int[]           neighbourOffsets = gridGraph.neighbourOffsets;
            LevelGridNode[] nodes            = gridGraph.nodes;
            int             nodeInGridIndex  = base.NodeInGridIndex;

            for (int i = 0; i < 4; i++)
            {
                int connectionValue = this.GetConnectionValue(i);
                if (connectionValue != 255)
                {
                    LevelGridNode levelGridNode = nodes[nodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                    if (levelGridNode != null)
                    {
                        action(levelGridNode);
                    }
                }
            }
            base.GetConnections(action);
        }
 // Token: 0x06002503 RID: 9475 RVA: 0x0019CC14 File Offset: 0x0019AE14
 public override void ClearConnections(bool alsoReverse)
 {
     if (alsoReverse)
     {
         LayerGridGraph  gridGraph        = LevelGridNode.GetGridGraph(base.GraphIndex);
         int[]           neighbourOffsets = gridGraph.neighbourOffsets;
         LevelGridNode[] nodes            = gridGraph.nodes;
         for (int i = 0; i < 4; i++)
         {
             int connectionValue = this.GetConnectionValue(i);
             if (connectionValue != 255)
             {
                 LevelGridNode levelGridNode = nodes[base.NodeInGridIndex + neighbourOffsets[i] + gridGraph.lastScannedWidth * gridGraph.lastScannedDepth * connectionValue];
                 if (levelGridNode != null)
                 {
                     levelGridNode.SetConnectionValue((i + 2) % 4, 255);
                 }
             }
         }
     }
     this.ResetAllGridConnections();
 }
        public override void OnInspectorGUI(NavGraph target)
        {
            LayerGridGraph graph = target as LayerGridGraph;

            graph.mergeSpanRange  = EditorGUILayout.FloatField("Merge Span Range", graph.mergeSpanRange);
            graph.characterHeight = EditorGUILayout.FloatField("Character Height", graph.characterHeight);
            graph.maxClimb        = Mathf.Clamp(EditorGUILayout.FloatField("Max climb", graph.maxClimb), 0, graph.characterHeight);

            graph.neighbours = NumNeighbours.Four;
            textureVisible   = false;
            base.OnInspectorGUI(target);

            if (graph.neighbours != NumNeighbours.Four)
            {
                Debug.Log("Note: Only 4 neighbours per grid node is allowed in this graph type");
            }

            if (graph.collision.thickRaycast)
            {
                HelpBox("Note: Thick raycast cannot be used with this graph type");
            }
        }
        public static int SetGridGraph(LayerGridGraph graph)
        {
            if (gridGraphs == null) {
                gridGraphs = new LayerGridGraph[1];
            } else {

                for (int i=0;i<gridGraphs.Length;i++) {
                    if (gridGraphs[i] == graph) {
                        return i;
                    }
                }

                if (gridGraphs.Length+1 >= 256) {
                    Debug.LogError ("Too many grid graphs have been created, 256 is the maximum allowed number. If you get this error, please inform me (arongranberg.com) as I will have to code up some cleanup function for this if it turns out to be called often");
                    return 0;
                }

                LayerGridGraph[] tmp = new LayerGridGraph[gridGraphs.Length+1];
                for (int i=0;i<gridGraphs.Length;i++) {
                    tmp[i] = gridGraphs[i];
                }
                gridGraphs = tmp;
            }

            gridGraphs[gridGraphs.Length-1] = graph;
            return gridGraphs.Length-1;
        }
		public static void SetGridGraph (int graphIndex, LayerGridGraph graph) {
			if (_gridGraphs.Length <= graphIndex) {
				var gg = new LayerGridGraph[graphIndex+1];
				for (int i=0;i<_gridGraphs.Length;i++) gg[i] = _gridGraphs[i];
				_gridGraphs = gg;
			}

			_gridGraphs[graphIndex] = graph;
		}
        public static void RemoveGridGraph(LayerGridGraph graph)
        {
            if (gridGraphs == null) {
                return;
            }

            for (int i=0;i<gridGraphs.Length;i++) {
                if (gridGraphs[i] == graph) {

                    if (gridGraphs.Length == 1) {
                        gridGraphs = null;
                        return;
                    }

                    for (int j=i+1;j<gridGraphs.Length;j++) {
                        LayerGridGraph gg = gridGraphs[j];

                        if (gg.nodes != null) {
                            for (int n=0;n<gg.nodes.Length;n++) {
                                ((LevelGridNode)gg.nodes[n]).SetGridIndex (j-1);
                            }
                        }
                    }

                    LayerGridGraph[] tmp = new LayerGridGraph[gridGraphs.Length-1];
                    for (int j=0;j<i;j++) {
                        tmp[j] = gridGraphs[j];
                    }
                    for (int j=i+1;j<gridGraphs.Length;j++) {
                        tmp[j-1] = gridGraphs[j];
                    }
                    return;
                }
            }
        }
示例#18
0
        // Token: 0x06002430 RID: 9264 RVA: 0x00196841 File Offset: 0x00194A41
        private IEnumerator UpdateGraphCoroutine()
        {
            Vector3 vector = this.PointToGraphSpace(this.target.position) - this.PointToGraphSpace(this.graph.center);

            vector.x = Mathf.Round(vector.x);
            vector.z = Mathf.Round(vector.z);
            vector.y = 0f;
            if (vector == Vector3.zero)
            {
                yield break;
            }
            Int2 offset = new Int2(-Mathf.RoundToInt(vector.x), -Mathf.RoundToInt(vector.z));

            this.graph.center += this.graph.transform.TransformVector(vector);
            this.graph.UpdateTransform();
            int            width          = this.graph.width;
            int            depth          = this.graph.depth;
            int            layers         = this.graph.LayerCount;
            LayerGridGraph layerGridGraph = this.graph as LayerGridGraph;

            GridNodeBase[] nodes;
            if (layerGridGraph != null)
            {
                GridNodeBase[] nodes2 = layerGridGraph.nodes;
                nodes = nodes2;
            }
            else
            {
                GridNodeBase[] nodes2 = this.graph.nodes;
                nodes = nodes2;
            }
            if (this.buffer == null || this.buffer.Length != width * depth)
            {
                this.buffer = new GridNodeBase[width * depth];
            }
            if (Mathf.Abs(offset.x) <= width && Mathf.Abs(offset.y) <= depth)
            {
                IntRect recalculateRect = new IntRect(0, 0, offset.x, offset.y);
                if (recalculateRect.xmin > recalculateRect.xmax)
                {
                    int xmax = recalculateRect.xmax;
                    recalculateRect.xmax = width + recalculateRect.xmin;
                    recalculateRect.xmin = width + xmax;
                }
                if (recalculateRect.ymin > recalculateRect.ymax)
                {
                    int ymax = recalculateRect.ymax;
                    recalculateRect.ymax = depth + recalculateRect.ymin;
                    recalculateRect.ymin = depth + ymax;
                }
                IntRect connectionRect = recalculateRect.Expand(1);
                connectionRect = IntRect.Intersection(connectionRect, new IntRect(0, 0, width, depth));
                int num7;
                for (int i = 0; i < layers; i = num7 + 1)
                {
                    int layerOffset = i * width * depth;
                    for (int j = 0; j < depth; j++)
                    {
                        int num  = j * width;
                        int num2 = (j + offset.y + depth) % depth * width;
                        for (int k = 0; k < width; k++)
                        {
                            this.buffer[num2 + (k + offset.x + width) % width] = nodes[layerOffset + num + k];
                        }
                    }
                    yield return(null);

                    for (int l = 0; l < depth; l++)
                    {
                        int num3 = l * width;
                        for (int m = 0; m < width; m++)
                        {
                            int          num4         = num3 + m;
                            GridNodeBase gridNodeBase = this.buffer[num4];
                            if (gridNodeBase != null)
                            {
                                gridNodeBase.NodeInGridIndex = num4;
                            }
                            nodes[layerOffset + num4] = gridNodeBase;
                        }
                        int num5;
                        int num6;
                        if (l >= recalculateRect.ymin && l < recalculateRect.ymax)
                        {
                            num5 = 0;
                            num6 = depth;
                        }
                        else
                        {
                            num5 = recalculateRect.xmin;
                            num6 = recalculateRect.xmax;
                        }
                        for (int n = num5; n < num6; n++)
                        {
                            GridNodeBase gridNodeBase2 = this.buffer[num3 + n];
                            if (gridNodeBase2 != null)
                            {
                                gridNodeBase2.ClearConnections(false);
                            }
                        }
                    }
                    yield return(null);

                    num7 = i;
                }
                int yieldEvery = 1000;
                int num8       = Mathf.Max(Mathf.Abs(offset.x), Mathf.Abs(offset.y)) * Mathf.Max(width, depth);
                yieldEvery = Mathf.Max(yieldEvery, num8 / 10);
                int counter = 0;
                for (int i = 0; i < depth; i = num7 + 1)
                {
                    int num9;
                    int num10;
                    if (i >= recalculateRect.ymin && i < recalculateRect.ymax)
                    {
                        num9  = 0;
                        num10 = width;
                    }
                    else
                    {
                        num9  = recalculateRect.xmin;
                        num10 = recalculateRect.xmax;
                    }
                    for (int num11 = num9; num11 < num10; num11++)
                    {
                        this.graph.RecalculateCell(num11, i, false, false);
                    }
                    counter += num10 - num9;
                    if (counter > yieldEvery)
                    {
                        counter = 0;
                        yield return(null);
                    }
                    num7 = i;
                }
                for (int i = 0; i < depth; i = num7 + 1)
                {
                    int num12;
                    int num13;
                    if (i >= connectionRect.ymin && i < connectionRect.ymax)
                    {
                        num12 = 0;
                        num13 = width;
                    }
                    else
                    {
                        num12 = connectionRect.xmin;
                        num13 = connectionRect.xmax;
                    }
                    for (int num14 = num12; num14 < num13; num14++)
                    {
                        this.graph.CalculateConnections(num14, i);
                    }
                    counter += num13 - num12;
                    if (counter > yieldEvery)
                    {
                        counter = 0;
                        yield return(null);
                    }
                    num7 = i;
                }
                yield return(null);

                for (int num15 = 0; num15 < depth; num15++)
                {
                    for (int num16 = 0; num16 < width; num16++)
                    {
                        if (num16 == 0 || num15 == 0 || num16 == width - 1 || num15 == depth - 1)
                        {
                            this.graph.CalculateConnections(num16, num15);
                        }
                    }
                }
                if (!this.floodFill)
                {
                    this.graph.GetNodes(delegate(GraphNode node)
                    {
                        node.Area = 1u;
                    });
                }
            }
            else
            {
                int counter    = Mathf.Max(depth * width / 20, 1000);
                int yieldEvery = 0;
                int num7;
                for (int i = 0; i < depth; i = num7 + 1)
                {
                    for (int num17 = 0; num17 < width; num17++)
                    {
                        this.graph.RecalculateCell(num17, i, true, true);
                    }
                    yieldEvery += width;
                    if (yieldEvery > counter)
                    {
                        yieldEvery = 0;
                        yield return(null);
                    }
                    num7 = i;
                }
                for (int i = 0; i < depth; i = num7 + 1)
                {
                    for (int num18 = 0; num18 < width; num18++)
                    {
                        this.graph.CalculateConnections(num18, i);
                    }
                    yieldEvery += width;
                    if (yieldEvery > counter)
                    {
                        yieldEvery = 0;
                        yield return(null);
                    }
                    num7 = i;
                }
            }
            yield break;
        }