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


C# GraphNode.GetIndex方法代码示例

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


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

示例1: AddNode

    public void AddNode(Vector3 neighborPoint, ref GraphNode currentNode, ref Queue<GraphNode> q )
    {
        RaycastHit hitInfo;
        Vector3 rayDirection = Vector3.zero;
        #if USE_XZ
        rayDirection = new Vector3(0, -1, 0);
        #else
        rayDirection = new Vector3(0, 0, 1);
        #endif //USE_XZ
        int layerMask = 1 << 8;
        layerMask = ~layerMask;
        if ( Physics.Raycast(neighborPoint, rayDirection, out hitInfo, Mathf.Infinity, layerMask) )
        {
            if (hitInfo.transform.tag == "Ground")
            {
                GraphNode newNode = new GraphNode(mNumOfNodes, hitInfo.point); // make a new node for this point
                GraphEdge newEdge = new GraphEdge(currentNode.GetIndex(), newNode.GetIndex()); // creat a new edge

                int index = 0;
                bool nodeFound = false;
                while ( !nodeFound && index <= mNumOfNodes )
                {
                    //Debug.Log (index + " out of " + NavigationGraph.Length + " thinks there's only" + mNumOfNodes);
                    nodeFound = ( NavigationGraph[index] == hitInfo.point );

                    ++index;
                }

                if ( !nodeFound ) // if we have not found this node before, add it
                {
                    Nodes.Add(newNode);
                    NavigationGraph[mNumOfNodes] = hitInfo.point;
                    ++mNumOfNodes;

                    q.Enqueue(newNode);
                }
                else
                {
                    newEdge.SetToIndex(index-1);
                }

                // If the raycast hit then we will always want to add the edge, since we want edges
                // in both directions and there won't ever be duplicates.

                // check if there is a clear path to add an edge
                Vector3 heightOffset = Vector3.zero;
        #if USE_XZ
                heightOffset = new Vector3(0, 0.5f, 0);
        #else
                heightOffset = new Vector3(0, 0, -0.5f);
        #endif // USE_XZ
                if ( !Physics.Linecast(currentNode.GetPosition() + heightOffset, newNode.GetPosition() + heightOffset, out hitInfo, layerMask) )
                {
                    Edges.Add(newEdge);
                    currentNode.AddEdge(newEdge);
                }
            }
        }
    }
开发者ID:jordanajlouni,项目名称:ProjectAccountingSoftware-1,代码行数:59,代码来源:NavGraphConstructor.cs


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