Beispiel #1
0
    // Use this for initialization
    override protected void Start()
    {
        // Base call
        base.Start();
        // Check parameters
        require(maxVelocity > 0.0f, "Max velocity must be greater than 0");

        // Change size
        transform.localScale = new Vector3(3.0f, 3.0f, 3.0f);

        // Create Visibility graph
        GraphState     graph;
        IState         start, goal;
        List <Polygon> polys = new List <Polygon>();

        GraphFactory.CreatePolyFromFile("Assets/_Data/" + obstacleFilename,
                                        out graph, out start, out goal, polys);

        // Generate and render all obstacles
        GameObject parent = new GameObject();

        parent.name = "Polygonal Obstacles";
        foreach (Polygon pol in polys)
        {
            GameObject go = pol.ToGameObject(material);
            go.transform.parent = parent.transform;
        }

        // Running the big guy and adding path to the list
        AStar          ast    = new AStar(graph, start, goal, AStar.HCont);
        List <Vector3> points = new List <Vector3>();

        foreach (IState s in ast.path)
        {
            points.Add(s.ToVector3());
        }

        // Generate path
        PathGenerator.Init(points);

        // Move to starting position
        transform.position = start.ToVector3();

        // Just to initialize and set color
        labelStyle = new GUIStyle();
        labelStyle.normal.textColor = Color.black;
        labelRect = new Rect(20, 20, 20, 20);
        strCost   = "Distance: " + ast.cost.ToString("0.00");
    }