当前位置: 首页>>代码示例>>C#>>正文


C# GridNode.GetIndex方法代码示例

本文整理汇总了C#中GridNode.GetIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GridNode.GetIndex方法的具体用法?C# GridNode.GetIndex怎么用?C# GridNode.GetIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GridNode的用法示例。


在下文中一共展示了GridNode.GetIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckConnection

        /** Returns if \a node is connected to it's neighbour in the specified direction.
          * This will also return true if #neighbours = NumNeighbours.Four, the direction is diagonal and one can move through one of the adjacent nodes
          * to the targeted node.
          */
        public bool CheckConnection(GridNode node, int dir)
        {
            if (neighbours == NumNeighbours.Eight) {
                return node.GetConnection (dir);
            } else {
                int dir1 = (dir-4-1) & 0x3;
                int dir2 = (dir-4+1) & 0x3;

                if (!node.GetConnection (dir1) || !node.GetConnection (dir2)) {
                    return false;
                } else {
                    GridNode n1 = nodes[node.GetIndex ()+neighbourOffsets[dir1]] as GridNode;
                    GridNode n2 = nodes[node.GetIndex ()+neighbourOffsets[dir2]] as GridNode;

                    if (!n1.walkable || !n2.walkable) {
                        return false;
                    }

                    if (!n2.GetConnection (dir1) || !n1.GetConnection (dir2)) {
                        return false;
                    }
                }
                return true;
            }
        }
开发者ID:sonygod,项目名称:ESPUnity,代码行数:29,代码来源:GridGenerator.cs

示例2: AddPortal

        public void AddPortal(GridNode n1, GridNode n2, List<Vector3> left, List<Vector3> right)
        {
            if (n1 == n2) {
                return;
            }

            int i1 = n1.GetIndex ();
            int i2 = n2.GetIndex ();
            int x1 = i1 % width;
            int x2 = i2 % width;
            int z1 = i1 / width;
            int z2 = i2 / width;

            Vector3 n1p = (Vector3)n1.position;
            Vector3 n2p = (Vector3)n2.position;

            int diffx = Mathf.Abs (x1-x2);
            int diffz = Mathf.Abs (z1-z2);

            if (diffx > 1 || diffz > 1) {
                //If the nodes are not adjacent to each other

                left.Add (n1p);
                right.Add (n1p);
                left.Add (n2p);
                right.Add (n2p);
            } else if ((diffx+diffz) <= 1){
                //If it is not a diagonal move

                Vector3 dir = n2p - n1p;
                dir = dir.normalized * nodeSize * 0.5F;
                Vector3 tangent = Vector3.Cross (dir, Vector3.up);
                tangent = tangent.normalized * nodeSize * 0.5F;

                left.Add (n1p + dir - tangent);
                right.Add (n1p + dir + tangent);
            } else {
                //Diagonal move

                Node t1 = nodes[z1 * width + x2];
                Node t2 = nodes[z2 * width + x1];
                Node target = null;

                if (t1.walkable) {
                    target = t1;
                } else if (t2.walkable) {
                    target = t2;
                }

                if (target == null) {
                    Vector3 avg = (n1p + n2p) * 0.5F;

                    left.Add (avg);
                    right.Add (avg);
                } else {
                    AddPortal (n1,(GridNode)target,left,right);
                    AddPortal ((GridNode)target,n2,left,right);
                }
            }
        }
开发者ID:sonygod,项目名称:ESPUnity,代码行数:60,代码来源:GridGenerator.cs

示例3: CalculateConnections

        /** Calculates the grid connections for a single node */
        public virtual void CalculateConnections(Node[] nodes, int x, int z, GridNode node)
        {
            //Reset all connections
            node.flags = node.flags & -256;

            //All connections are disabled if the node is not walkable
            if (!node.walkable) {
                return;
            }

            int index = node.GetIndex ();

            if (corners == null) {
                corners = new int[4];
            } else {
                for (int i = 0;i<4;i++) {
                    corners[i] = 0;
                }
            }

            for (int i=0, j = 3; i<4; j = i, i++) {

                int nx = x + neighbourXOffsets[i];
                int nz = z + neighbourZOffsets[i];

                if (nx < 0 || nz < 0 || nx >= width || nz >= depth) {
                    continue;
                }

                GridNode other = nodes[index+neighbourOffsets[i]] as GridNode;

                if (IsValidConnection (node, other)) {
                    node.SetConnectionRaw (i,1);

                    corners[i]++;
                    corners[j]++;
                }
            }

            if (neighbours == NumNeighbours.Eight) {
                if (cutCorners) {
                    for (int i=0; i<4; i++) {

                        if (corners[i] >= 1) {
                            int nx = x + neighbourXOffsets[i+4];
                            int nz = z + neighbourZOffsets[i+4];

                            if (nx < 0 || nz < 0 || nx >= width || nz >= depth) {
                                continue;
                            }

                            GridNode other = nodes[index+neighbourOffsets[i+4]] as GridNode;

                            if (IsValidConnection (node,other)) {
                                node.SetConnectionRaw (i+4,1);
                            }
                        }
                    }
                } else {
                    for (int i=0; i<4; i++) {

                        //We don't need to check if it is out of bounds because if both of the other neighbours are inside the bounds this one must be too
                        if (corners[i] == 2) {
                            GridNode other = nodes[index+neighbourOffsets[i+4]] as GridNode;

                            if (IsValidConnection (node,other)) {
                                node.SetConnectionRaw (i+4,1);
                            }
                        }
                    }
                }
            }
        }
开发者ID:sonygod,项目名称:ESPUnity,代码行数:74,代码来源:GridGenerator.cs


注:本文中的GridNode.GetIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。