public void Place(PlacingToGrid PlacingObject) { if (PlacingObject.Col_size == 0 && PlacingObject.Row_size == 0) return; PlacingObject.RelaseAll(); GridElement element = Grid[PlacingObject.Col, PlacingObject.Row]; PlacingObject.setPosition( new Vector3(element.getA().x + (element.getB().x - element.getA().x) + PlacingObject.GetSpace_X(), element.getB().y - (element.getB().y - element.getA().y) - PlacingObject.GetSpace_Y(), PlacingObject.transform.position.z)); int ColSize = (int)Mathf.Ceil( (float)PlacingObject.Col_size / 2f); int RowSize = (int)Mathf.Ceil( (float)PlacingObject.Row_size / 2f); for(int i = 0; i < PlacingObject.Col_size; i++) { for(int j = 0; j < PlacingObject.Row_size; j++) { GridElement element1 = Grid[PlacingObject.Col + i, PlacingObject.Row + j]; element1.ToggleOn(); PlacingObject.addElementToList(Grid[PlacingObject.Col + i, PlacingObject.Row + j]); } } if (TilleOnGrid.Contains(PlacingObject) == false) { TilleOnGrid.Add(PlacingObject); } }
public void Build(ItemShop item, GuiBuyBuilding BuyGui) { this.BuyGui = BuyGui; if (BuildObjectPlacingToGrid == null) { BuildObjectPlacingToGrid = BuildingSkeleton; BuildObjectSprite = TMPsprite; BuildObjectPlacingToGrid.ReloadNormal(); } shopitem = item; Debug.Log("BUILDER: " + item.DefaultGroup.name); Vector3 Position = Camera.main.ScreenToWorldPoint( new Vector3(Camera.main.transform.position.x + Screen.width / 2 , Camera.main.transform.position.y + Screen.height / 2, 0)); Position.z = 0; // Building build = item.DefaultGroup.AddBuild(Position); GridElement element = Grid.DetechTouchPositionOnGrid(Position); // PlacingToGrid placetogrid = build.GetComponent<PlacingToGrid>(); // placetogrid.Col = element.getCol(); // placetogrid.Row = element.getRow(); BuildObjectSprite.sprite = item.Sprite.sprite; BuildObjectSprite.gameObject.SetActive(true); BuildObjectSprite.transform.localScale = item.transform.localScale; BuildObjectPlacingToGrid.Col_size = item.GetPlacingToGrid().Col_size; BuildObjectPlacingToGrid.Row_size = item.GetPlacingToGrid().Row_size; BuildObjectPlacingToGrid.setNormalSpace_x( item.GetPlacingToGrid().getNormalSpace_x()); BuildObjectPlacingToGrid.setNormalSpace_y( item.GetPlacingToGrid().getNormalSpace_y()); BuildObjectPlacingToGrid.setMirrorSpace_x(item.GetPlacingToGrid().getMirrorSpace_x()); BuildObjectPlacingToGrid.setMirrorSpace_y(item.GetPlacingToGrid().getMirrorSpace_y()); BuildObjectPlacingToGrid.Col = element.getCol(); BuildObjectPlacingToGrid.Row = element.getRow(); BuildObjectPlacingToGrid.ReloadNormal(); BoxCollider2D boxcollider = item.GetComponent<BoxCollider2D>(); Collider2D.size = new Vector2(boxcollider.size.x ,boxcollider.size.y); Grid.Place(BuildObjectPlacingToGrid); isBuild = true; BuildObjectPlacingToGrid.gameObject.SetActive(true); CheckGridCollision(); FirstObjectPosition.Col = BuildObjectPlacingToGrid.Col; FirstObjectPosition.Row = BuildObjectPlacingToGrid.Row; FirstObjectPosition.scale = BuildObjectPlacingToGrid.scale; }
public void Initialize(PlacingToGrid _Place, BuilderManager Builder) { this._PlacingObject = _Place; this.Builder = Builder; }
public void CancleBuild() { if(isTransfered == false)BuildObjectPlacingToGrid.gameObject.SetActive(false); BuildObjectSprite.color = DefaultColor; BuildObjectPlacingToGrid.Col = FirstObjectPosition.Col; BuildObjectPlacingToGrid.Row = FirstObjectPosition.Row; BuildObjectPlacingToGrid.scale = FirstObjectPosition.scale; BuildObjectPlacingToGrid = null; isBuild = false; isTransfered = false; Controller.DisableDoubleTouch = false; BuyGui = null; }
// Use this for initialization void Start() { OldPositionElement = new GridElement(); OldPositionElement.setCol(0); OldPositionElement.setRow(0); TMPsprite = BuildObjectSprite; FirstObjectPosition = new PlacingToGrid(); }
public void Transfer(PlacingToGrid item) { BuildObjectPlacingToGrid = item; BuildObjectSprite = item.GetComponent<SpriteRenderer>(); Vector3 Position = Camera.main.ScreenToWorldPoint(new Vector3(Camera.main.transform.position.x + Screen.width / 2, Camera.main.transform.position.y + Screen.height / 2, 0)); isBuild = true; isTransfered = true; CheckGridCollision(); }
public void Tranfer(PlacingToGrid PlacingObject) { BuildObjectPlacingToGrid.RelaseAll(); BuildObjectPlacingToGrid = PlacingObject; BuildObjectSprite.sprite = PlacingObject.gameObject.GetComponent<SpriteRenderer>().sprite; isBuild = true; }
public void FinalizeBuild() { if(isTransfered == true) { BuildObjectSprite.color = DefaultColor; } else { Building build = shopitem.DefaultGroup.AddBuild(BuildObjectPlacingToGrid.transform.position); PlacingToGrid placetogrid = build.GetComponent<PlacingToGrid>(); placetogrid.Col = BuildObjectPlacingToGrid.Col; placetogrid.Row = BuildObjectPlacingToGrid.Row; placetogrid.Col_size = BuildObjectPlacingToGrid.Col_size; placetogrid.Row_size = BuildObjectPlacingToGrid.Row_size; build.transform.localScale = new Vector3(BuildObjectPlacingToGrid.transform.localScale.x, BuildObjectPlacingToGrid.transform.localScale.y, build.transform.localScale.z); build.InConstruction.active = true; build.InConstruction.FirstInitialize(); build.Initialize(); build.Produce(); BuildObjectSprite.gameObject.SetActive(false); placetogrid.scale = BuildObjectPlacingToGrid.scale; } BuildObjectSprite.color = DefaultColor; isBuild = false; isTransfered = false; BuildObjectPlacingToGrid = null; BuildingSkeleton.RelaseAll(); Controller.DisableDoubleTouch = false; if(BuyGui != null) BuyGui.Finalize(); BuyGui = null; }