public void ProcessEvent(ImageChoiceEvent e, ImageChoiceEventProcessor eventManager) { var choices = e.Choices; foreach (ImageChoice c in choices) { GameObject choiceGameObject = Instantiate(ImageChoiceButtonPrefab); choiceGameObject.SetActive(true); choiceGameObject.transform.SetParent(transform, true); ImageChoiceData imageChoiceData = choiceGameObject.GetComponent <ImageChoiceData>(); imageChoiceData.SetEvent(c, eventManager); string path = Path.Combine(Constants.ArticleImagesResourceFolder, c.ImagePath).Replace('\\', '/'); Debug.Log("Image path for choice" + c.Title + "=" + path); Sprite image = Resources.Load <Sprite>(path); ; imageChoiceData.ImageButton.GetComponent <Image>().sprite = image; var texture = image.texture; float aspectRatio = texture.width / (float)texture.height; imageChoiceData.ImageButton.GetComponent <AspectRatioFitter>().aspectRatio = aspectRatio; imageChoiceData.ImageMargin.GetComponent <AspectRatioFitter>().aspectRatio = aspectRatio; _choiceGameObjects.Add(choiceGameObject); } }
public void SetEvent(ImageChoice choice, ImageChoiceEventProcessor viewProcessor) { _choice = choice; _owner = viewProcessor; }