Ejemplo n.º 1
0
    public void CompletePreview(Vector3 mouse_down, Vector3 mouse_up, bool corner, bool snap)
    {
        ShowPreview(mouse_down, mouse_up, snap);

        GameObject new_straight_one = null;
        GameObject new_straight_two = null;
        GameObject new_corner       = null;

        // have to verify if it can be build first
        if (CanBuild(corner))
        {
            new_straight_one = road_straight_one_component.CreateRoad(roadParent);
            if (corner)
            {
                new_straight_two = road_straight_two_component.CreateRoad(roadParent);
                new_corner       = road_corner_component.CreateRoad(roadParent);
            }

            // update road, which updates connections, materials, etc.
            new_straight_one.GetComponent <RoadStraight>().UpdateRoad(GetStraightOneDirection(mouse_down, mouse_up));
            if (corner)
            {
                new_straight_two.GetComponent <RoadStraight>().UpdateRoad(GetStraightTwoDirection(mouse_down, mouse_up));
                new_corner.GetComponent <RoadCorner>().UpdateRoad();
            }
            placeRoad.Complete();
        }
    }
Ejemplo n.º 2
0
    /*
     *	Called by UpdateConnectionsStraightToStraight() when two straights need to be
     *	replaced by one, and the old roads deleted
     */
    void CreateTwoStraights(RoadStraight otherRoad)
    {
        Vector2 min_array = new Vector2(Mathf.Min(grid_position_min.x, otherRoad.grid_position_min.x),
                                        Mathf.Min(grid_position_min.y, otherRoad.grid_position_min.y));
        Vector2 max_array = new Vector2(Mathf.Max(grid_position_max.x, otherRoad.grid_position_max.x),
                                        Mathf.Max(grid_position_max.y, otherRoad.grid_position_max.y));

        GameObject new_go = GridBuilder.CreateRectangle(min_array, max_array, this.transform.localScale.y,
                                                        this.transform.parent, true);

        // create component, createRoad() and then update
        RoadStraight road_component = new_go.AddComponent <RoadStraight>();

        road_component.CreateRoad(this);

        /*
         * print(this.gameObject.name + "is creating two straights");
         * StartCoroutine(DelayedUpdateRoad(road_component, otherRoad));
         */

        road_component.UpdateRoad(this.trafficDirection);

        Object.Destroy(otherRoad.gameObject);
        Object.Destroy(this.gameObject);
    }