Ejemplo n.º 1
0
    public static bool isCollide(VInt3 origin, VInt3 end, out GraphHitInfo hit)
    {
        GraphNode startNode = AstarPath.active.GetNearest(origin).node;
        var       graph     = AstarData.GetGraph(startNode) as NavmeshBase;

        return(graph.Linecast(origin, end, startNode, out hit));
    }
    // Use this for initialization
    void Start()
    {
        //Debug.Log("---2---" + gameObject.isStatic);
        style = new GUIStyle()
        {
            fontSize  = 22,
            alignment = TextAnchor.MiddleCenter,
            normal    = new GUIStyleState()
            {
                textColor = Color.white
            }
        };
        //dynamicRoot = GameObject.Find("DynamicObstacles").transform;
        //seeker = GetComponent<Seeker>();

        /*wallRoot = GameObject.Find("Wall").transform;
         * playersRoot = GameObject.Find("Players").transform;
         * robotRoot = GameObject.Find("Robots").transform;*/
        pointRoot = GameObject.Find("Points").transform;
        ball      = GameObject.Find("Ball");


        //获取当前点所在的图形节点
        GraphNode  startNode = AstarPath.active.GetNearest((VInt3)pointRoot.GetChild(0).position).node;
        var        other     = startNode as TriangleMeshNode;
        GameObject go4       = Instantiate(ball);

        go4.transform.position = (Vector3)startNode.position;
        Debug.Log("--0--" + startNode.position);
        GraphHitInfo hit      = new GraphHitInfo();
        var          graph    = AstarData.GetGraph(startNode) as NavmeshBase;
        bool         canReach = graph.Linecast((VInt3)pointRoot.GetChild(0).position, (VInt3)pointRoot.GetChild(2).position, startNode, out hit);

        Debug.Log($"---hit point--{hit.point}--{canReach}");
        GameObject go5 = Instantiate(ball);

        go5.transform.position = (Vector3)hit.point;
        //seeker.StartPath((VInt3)pointRoot.GetChild(0).position, (VInt3)pointRoot.GetChild(2).position, OnPathComplete);
    }