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


C# GridNode.SetConnectionRaw方法代码示例

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


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

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