/// <summary> /// Instansiate new brick in place of all one. /// Copy to new brick position, rotation and scale. /// Make old brick inactive. /// </summary> /// <returns>The new brick.</returns> /// <param name="newBrickPath">New brick resources path.</param> /// <param name="oldBrick">Old brick.</param> Brick ChangeBrick(string newBrickPath, AgaQBrick oldBrick) { var newBrick = BrickBuilder.InstansiateFromResources(newBrickPath); if (newBrick == null) { return(null); } newBrick.transform.position = oldBrick.transform.position; newBrick.transform.rotation = oldBrick.transform.rotation; newBrick.transform.localScale = oldBrick.transform.localScale; if (oldBrick.isDragging && ToolsManager.instance.tool is MoveTool) { //let exchange bricks in move tool (ToolsManager.instance.tool as MoveTool).ChangeBrick(newBrick as DragableBrick); } else { oldBrick.gameObject.SetActive(false); } return(newBrick); }
/// <summary> /// Group given bricks /// </summary> /// <returns>The group.</returns> /// <param name="bricsToGroup">Brics to group.</param> public SelectableBrick Group(List <SelectableBrick> bricsToGroup) { bool allOrdinary = true; foreach (var brick in bricsToGroup) { if (!(brick is OrdinaryBrick)) { allOrdinary = false; break; } } //create group object and prepare it SelectableBrick groupScript = allOrdinary ? (SelectableBrick)BrickBuilder.InstansiateBricksGroup() : (SelectableBrick)BrickBuilder.InstansiateAgaQGroup(); //set group center groupScript.gameObject.transform.position = bricsToGroup[0].gameObject.transform.position; //move selected brck to group //and disable brick scripts foreach (var brick in bricsToGroup) { brick.transform.SetParent(groupScript.gameObject.transform); brick.grouped = true; } return(groupScript); }
/// <summary> /// Clone the specified brick. /// </summary> /// <param name="brick">Brick.</param> /// <param name="eventData">Event data.</param> public void Clone(DragableBrick brick, PointerEventData eventData) { var newBrick = BrickBuilder.Clone(brick); if (newBrick is DragableBrick) { dragableBrick = newBrick as DragableBrick; base.OnBeginDrag(dragableBrick, eventData); } }
/// <summary> /// Add one more the same brick after one frame /// </summary> /// <returns>The adding.</returns> public IEnumerator RestartAdding(Brick brick) { yield return(null); var newBrick = BrickBuilder.Clone(brick); if (newBrick != null) { Add(newBrick, false); } }
/// <summary> /// Add new brick to scene froms saved file (group or add) /// </summary> /// <param name="path">File path.</param> /// <param name="presentFirst">If true present first brick at center of edit area and wait for cursor entering edit area.</param> public void AddSaved(string path, bool presentFirst) { if (dragableBrick != null) { OnCancel(); } var newBrick = BrickBuilder.InstansiateFromFile(path); if (newBrick != null) { Add(newBrick, presentFirst); } }
/// <summary> /// Add new brick to scene. /// </summary> /// <param name="resourcePath">Resource path.</param> /// <param name="presentFirst">If true present first brick at center of edit area and wait for cursor entering edit area.</param> public void Add(string resourcePath, bool presentFirst) { if (dragableBrick != null) { OnCancel(); } var newBrick = BrickBuilder.InstansiateFromResources(resourcePath); if (newBrick != null) { Add(newBrick, presentFirst); } }
/// <summary> /// Clone selected bricks. /// </summary> /// <param name="brick">Clicked brick being selected</param> /// <param name="eventData">Event data.</param> public void CloneSelection(DragableBrick brick, PointerEventData eventData) { List <SelectableBrick> clonedBricks = new List <SelectableBrick>(); var bricks = SelectionManager.instance.GetSelected(); //clone bricks foreach (var brickToClone in bricks) { var newBrick = BrickBuilder.Clone(brickToClone); clonedBricks.Add(newBrick as SelectableBrick); } //start moving base.OnBeginDrag(clonedBricks, eventData); }