void StartDrag() { ForwardOffsetBeforeDragging = UIController.Instance.forwardOffset; if (ConstraintController.CanPlace(currentBC)) { string templateName = currentBC.template.name; string name = templateName + "_" + (nbObjectsPlaced++); // Place the first Ghost = still green, still not collidin' TemplateController.PlaceObject(currentBC, name, BC_State.Ghost); draggedBC.Add(currentBC); draggingGroup = currentBC.beyondGroup; lastGroupPosition = currentBC.groupPosition; currentBC = null; CreateNewPlaceableObject(templateName); // TODO : another hardcoded position. Not good. Yet, I must move the currentBC to where I started dragging or else I'm going to drag to some unknown place. currentBC.transform.position = draggedBC[0].transform.position; currentBC.transform.rotation = draggedBC[0].transform.rotation; // Instantiate a big bunch of placeable object based on what we are currently dragging for (int i = 0; i < MaxDraggedObjectCount; i++) { BeyondComponent bc = TemplateController.CreateObject(templateName); //TODO Better names, please name = templateName + "_Ghost" + i; bc.SetBCinGroup(draggingGroup, lastGroupPosition); TemplateController.PlaceObject(bc, name, BC_State.Ghost); bc.gameObject.SetActive(false); draggedBC.Add(bc); } } }
public static void SetCanPlaceObjectColour(BeyondComponent bc) { Renderer r = bc.gameObject.GetComponent <Renderer>(); r.material.color = (ConstraintController.CanPlace(bc) ? Color.green : Color.red); //Debug.Log("Setting can place colour on " + bc.name + " in group " + (bc.beyondGroup==null ? "null" : bc.beyondGroup.name) + " at position "+bc.groupPosition + " = "+ ConstraintController.CanSnapTo(bc, bc.beyondGroup, bc.groupPosition)); //r.material.color = (ConstraintController.CanSnapTo(bc, bc.beyondGroup , bc.groupPosition) ? Color.green : Color.red); }
private void PlaceOnClic() { if (Input.GetMouseButtonUp(0)) { //TODO : dragging stuff - make it better for (int i = 0; i < draggedBC.Count; i++) { if (draggedBC[i].gameObject.activeSelf && ConstraintController.CanPlace(draggedBC[i])) { string name = currentBC.template.name + "_" + (nbObjectsPlaced++); TemplateController.PlaceObject(draggedBC[i], name, BC_State.Blueprint); } else { Destroy(draggedBC[i].gameObject); } } Destroy(currentBC.gameObject); draggingGroup = null; draggedBC.Clear(); UIController.Instance.SetForwardOffset(ForwardOffsetBeforeDragging); // reset ForwardOffset to what it was before dragging - less annoying /* * This works for 1 clic : * * if (ConstraintController.CanPlace(currentPlaceableObject)) * { * string name = currentBC.template.name + "_" + (nbObjectsPlaced++) ; * TemplateController.PlaceObject(ref currentPlaceableObject , name , BC_State.Blueprint) ; * } * else * { * //Debug.Log("Destroyed currentPlaceableObject "+ currentPlaceableObject .GetInstanceID()+ " as I couldn't place it"); * Destroy(currentPlaceableObject); * } */ } }