private void OnButtonClicked(PlaceableObjectButton clickedButton) { //Makes that only the button of the selected object is shown as selected PlaceableObject previewedObject = null; foreach (var button in _placeableObjectButtons) { if (button.Key == clickedButton && button.Key.Toggled) { previewedObject = button.Key.Prefab; } //Deactivate other buttons if needed if (button.Key != clickedButton && button.Key.Toggled) { button.Key.Toggle(false); } } Texture2D previewTexture = null; if (previewedObject != null) { previewTexture = previewedObject.Preview; } SetPreviewImage(previewTexture); }
public void Initialize(PlaceableObject[] placeableObjects, GuideLine guideLinePrefab) { //We create all the buttons to select the different parts foreach (var placeableObject in placeableObjects) { PlaceableObjectButton button = Instantiate(PartButton, PartButton.transform.parent); button.gameObject.SetActive(true); button.Initialize(placeableObject, Tray, guideLinePrefab, () => OnButtonClicked(button)); _placeableObjectButtons[button] = placeableObject.ModelName; } }