예제 #1
0
    // GameObject cube;

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            RaycastHit hit;
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 150f, mask))
            {
                Vector3 p = new Vector3(hit.point.x, vlr.points[vlr.points.Count - 1].y, hit.point.z);
                vlr.points[vlr.points.Count - 1] = p;
                //cube.transform.position = p;
            }
            vlr.RedrawLines();
        }
    }
예제 #2
0
    public IEnumerator TestPathfinding()
    {
        nodes = FindObjectsOfType <Node>();

        for (int i = 0; i < nodes.Length; i++)
        {
            for (int j = 0; j < nodes.Length; j++)
            {
                if (!nodes[i].isRoom || !nodes[j].isRoom)
                {
                    continue;
                }
                if (i == j)
                {
                    continue;
                }
                yield return(new WaitForSeconds(timeInterval));

                List <Vector3> path;
                PathFinder.singleton.FindPath(nodes[i], nodes[j], out path);
                if (path == null)
                {
                    Debug.LogWarning(nodes[i].nodeKey + " and " + nodes[j].nodeKey + " has problems");
                    UnityEditor.EditorApplication.isPaused = true;
                }
                if (path.Count == 1)
                {
                    Debug.LogWarning(nodes[i].nodeKey + " and " + nodes[j].nodeKey + " has no path");
                    UnityEditor.EditorApplication.isPaused = true;
                }



                vlr.points = path;
                RectangleCreator.singleton.DrawRects(vlr.points[0], vlr.points[vlr.points.Count - 1]);
                vlr.RedrawLines();
            }
        }
        Debug.Log("Test ended");
    }
예제 #3
0
    public void FindPathFromInputFields()
    {
        if (nodesDict == null)
        {
            Debug.LogError("nodeDict is null !!!");
            return;
        }

        Node old_start_node = startNode;
        Node old_end_node   = endNode;


        string nodeKey = from_InputField.text;


        nodeKey = GetOriginKey(nodeKey);

        nodeKey = nodeKey.Replace("WC ", string.Empty);

        if (nodesDict.ContainsKey(nodeKey))
        {
            startNode = nodesDict[nodeKey];
        }
        else
        {
            startNode = null;
        }


        nodeKey = destination_InputField.text;

        nodeKey = nodeKey.Replace("WC ", string.Empty);

        nodeKey = GetOriginKey(nodeKey);
        if (nodesDict.ContainsKey(nodeKey))
        {
            endNode = nodesDict[nodeKey];
        }
        else
        {
            endNode = null;
        }

        if (startNode != null && endNode != null)
        {
            FindPath(startNode, endNode, out path);

            vlr.points = path;

            vlr.RedrawLines(current_length);
            RectangleCreator.singleton.DrawRects(startNode.worldPos, endNode.worldPos);
        }
        else
        {
            FloorRouteLabel.SetFloorRouteText(0, 0);
            vlr.Hide();
            RectangleCreator.singleton.Hide();
        }

        SelectionManager2.singleton.CheckNode_visibility(old_start_node);
        SelectionManager2.singleton.CheckNode_visibility(old_end_node);


        SelectionManager2.singleton.CheckNode_visibility(startNode);
        SelectionManager2.singleton.CheckNode_visibility(endNode);

        SelectionManager2.singleton.SetFloor(SelectionManager2.singleton.currentFloor);
    }