Search Unity

How to convert a list of Resolution to String

Discussion in 'Scripting' started by Leooc13, Jul 28, 2014.

  1. Leooc13

    Leooc13

    Joined:
    Jul 28, 2014
    Posts:
    2
    Hi guys... First of all, i'm Brazilian and i'm sorry about my bad english...

    I am creating a PopUp Menu that shows all the resolutions supported by the monitor... To do this, i created a List of Resolution called resolutions and added the items after the foreach (Resolution res in resolutions)... Ok... Now i need to convert these resolutions to a string and add these string in other List of string... I can't add these items of the List because the other List is List, and when i put the .toString(), the console doesn't show the resolutions for me... The console shows me this (UnityEngine.Resolution)...

    My code:

    Code (CSharp):
    1. private UIPopupList uiPopUpScript;
    2. public List<Resolution> resolutionsList;
    3.     // Use this for initialization
    4.     void Start() {
    5.         uiPopUpScript = GetComponent<UIPopupList>();
    6.         resolutionsList = new List<Resolution>();
    7.         Resolution[] resolutions = Screen.resolutions;
    8.         foreach (Resolution res in resolutions) {
    9.             resolutionsList.Add(res);
    10.         }
    11.             uiPopUpScript.item = resolutionsList.ToString();     // This uiPopUpScript.item is the List of string that i need to put all the resolutions...
    12. }
    13.  
     
  2. Dave-xP

    Dave-xP

    Joined:
    Nov 8, 2013
    Posts:
    106
    Code (csharp):
    1.  
    2. private UIPopupList uiPopUpScript;
    3. public List<Resolution> resolutionsList;
    4.     // Use this for initialization
    5.     void Start() {
    6.         uiPopUpScript = GetComponent<UIPopupList>();
    7.         resolutionsList = new List<string>();
    8.         Resolution[] resolutions = Screen.resolutions;
    9.         foreach (Resolution res in resolutions) {
    10.             resolutionsList.Add(res.width+"x"+res.height);
    11.         }
    12.         uiPopUpScript.item = resolutionsList;
    13. }
    14.  
    I cannot test it because I dont have the uiPopUpScript, but that should work.
     
  3. Leooc13

    Leooc13

    Joined:
    Jul 28, 2014
    Posts:
    2
    Yeah, what i did was
    Code (CSharp):
    1. resolutionsList.Add((res.width).ToString()+"x"+(res.height).ToString());
    Thank you very much...