Пример #1
0
    public virtual GameObject CreateRoad(Transform parent)
    {
        // instantiate new gameObject and then position and parent it
        GameObject new_go = (GameObject)Instantiate(this.gameObject);

        new_go.transform.position = this.transform.position;
        new_go.SetActive(true);
        new_go.transform.parent = parent;

        BoxCollider boxCollider = new_go.GetComponent <BoxCollider>();

        boxCollider.size = new Vector3(0.999f, 5f, 0.999f);

        // setup position and keep box collider enabled
        SetupPositionAndSize(true);

        //don't forget to set layer
        new_go.layer = InterfaceController.LAYER_ROAD;

        // reflect changes in grid
        Road new_road = new_go.GetComponent <Road>();

        new_road.SetupPositionAndSize();
        GridHelper.BuildGridObject(new_road);

        return(new_go);
    }
Пример #2
0
    public virtual Building CreateBuilding()
    {
        // instantiate new gameObject and then position and parent it
        GameObject new_go = (GameObject)Instantiate(this.gameObject);

        new_go.transform.position = this.transform.position;
        new_go.SetActive(true);

        //don't forget to set layer
        new_go.layer          = InterfaceController.LAYER_BUILDING;
        this.gameObject.layer = InterfaceController.LAYER_BUILDING;

        // reflect changes in grid
        Building new_building = new_go.GetComponent <Building>();

        new_building.SetupPositionAndSize();
        GridHelper.BuildGridObject(new_building);

        // Add to area building
        AreaBuilding area_building = GridHelper.GetGridCell(grid_position_min.x, grid_position_min.y).GetAreaBuilding();

        area_building.AddBuilding(new_go.GetComponent <Building>());

        return(new_building);
    }
Пример #3
0
    public virtual GridObject CreateGridObject()
    {
        // instantiate new gameObject and then position and parent it
        GameObject new_go = (GameObject)Instantiate(this.gameObject);

        new_go.transform.position = this.transform.position;
        new_go.SetActive(true);

        // reflect changes in grid
        GridObject new_grid_object = new_go.GetComponent <GridObject>();

        new_grid_object.SetupPositionAndSize();
        GridHelper.BuildGridObject(new_grid_object);

        this.gameObject.GetComponent <BoxCollider> ().enabled = true;

        return(new_grid_object);
    }
Пример #4
0
    public virtual GameObject CreateRoad(Road oldRoad)
    {
        //don't forget to set layer
        this.gameObject.layer = InterfaceController.LAYER_ROAD;

        // set old properties
        nameType     = oldRoad.GetType();
        roadMaterial = oldRoad.roadMaterial;

        // reflect changes in grid
        SetupPositionAndSize();
        size -= Vector2.one;
        grid_position_max -= Vector2.one;
        GridHelper.BuildGridObject(this, true);

        /*print("min array = " + array_position_min);
         * print("max array = " + array_position_max);
         * print("size = " + size);*/

        return(this.gameObject);
    }
    public AreaBuilding CreateAreaBuilding(GridCell minGridCell, GridCell maxGridCell, Vector2 size, int type)
    {
        // setup for selection object
        Vector3 oldPosition = selection_object.transform.position;

        SetupPositionAndSize(minGridCell.gridPosition, size);
        selection_object.transform.position = UpdateSelectionObject(minGridCell, maxGridCell, size);

        // instantiate new gameObject and then position and parent it
        GameObject new_go = (GameObject)Instantiate(selection_object);

        new_go.transform.position = selection_object.transform.position;
        new_go.transform.position = new Vector3(selection_object.transform.position.x,
                                                selection_object.transform.position.y - 0.05f,
                                                selection_object.transform.position.z);
        new_go.transform.parent = areaBuildingContainer;
        new_go.GetComponent <Renderer>().material = areaBuildingMaterial;

        //don't forget to set layer
        new_go.layer = InterfaceController.LAYER_AREA_BUILDING;

        // add components, and add collider
        AreaBuilding new_area = new_go.AddComponent <AreaBuilding> ();

        new_go.AddComponent <BoxCollider> ();
        new_go.GetComponent <BoxCollider> ().size = new Vector3(0.99f, 0.99f, 0.99f);         // otherwise it's counts as outside and size ends up at +1 because of Setup
        new_area.Setup(type, buildingFactory);

        // reflect changes in grid
        GridHelper.BuildGridObject(new_area);

        // and finally add to airport list
        airport.AddAreaBuilding(new_area);

        // reset position
        selection_object.transform.position = oldPosition;

        return(new_area);
    }