예제 #1
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);
    }
예제 #2
0
 /*
  *	Give an override option when replacing one road with another
  */
 public void BuildGridObject(GridObject grid_object, bool ignoreBuildings)
 {
     if (!CanBuildGridObject(grid_object) && !ignoreBuildings)
         Debug.Log ("CRITICAL ERROR - should not be getting to this point");
     else if (grid_object is AreaBuilding)
         areaBuilding = (AreaBuilding) grid_object;
     else if (grid_object is Building)
         building = (Building) grid_object;
     else if (grid_object is GridObject) // for example road
         gridObject = grid_object;
     else
         Debug.Log ("Object not recognized");
 }
예제 #3
0
    public void Load(string filename)
    {
        airportName = ES2.Load <string>(filename + "?tag=airportName");
        int areaBuildingListSize = ES2.Load <int>(filename + "?tag=areaBuildingListSize");

        string area_building_tag = filename + "?tag=areaBuilding";

        for (int i = 0; i < areaBuildingListSize; i++)
        {
            Vector2 minGridPos = ES2.Load <Vector2>(area_building_tag + i + "grid_position_min");
            Vector2 maxGridPos = ES2.Load <Vector2>(area_building_tag + i + "grid_position_max");
            Vector2 size       = ES2.Load <Vector2>(area_building_tag + i + "grid_size");

            AreaBuilding new_area_building = areaBuildingFactory.CreateAreaBuilding(GridHelper.GetGridCell(minGridPos),
                                                                                    GridHelper.GetGridCell(minGridPos),
                                                                                    size, 0);
            new_area_building.Load(filename, "?tag=areaBuilding" + i);
        }
    }
    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);
    }
예제 #5
0
 /*
  *	Give an override option when replacing one road with another
  */
 public void BuildGridObject(GridObject grid_object, bool ignoreBuildings)
 {
     if (!CanBuildGridObject(grid_object) && !ignoreBuildings)
     {
         Debug.Log("CRITICAL ERROR - should not be getting to this point");
     }
     else if (grid_object is AreaBuilding)
     {
         areaBuilding = (AreaBuilding)grid_object;
     }
     else if (grid_object is Building)
     {
         building = (Building)grid_object;
     }
     else if (grid_object is GridObject)         // for example road
     {
         gridObject = grid_object;
     }
     else
     {
         Debug.Log("Object not recognized");
     }
 }
예제 #6
0
 public void AddAreaBuilding(AreaBuilding areaBuilding)
 {
     areaBuildings.Add(areaBuilding);
 }
예제 #7
0
 public void AddAreaBuilding(AreaBuilding areaBuilding)
 {
     areaBuildings.Add (areaBuilding);
 }