Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

list view in unity

/*
The "easiest" and most elegant way I can think about is using a Vertical Layout Group

Add a new empty gameobject under your canvas
Set the desired dimensions using the RectTransform component
Attach the "Vertical Layout Group" component
In your code, for each string in your list :
Create a new GameObject :
Attach a text component to it
Fill the text attribute with your string
Set the parent of the transform to be the first empty gameobject in 1st step
Here is a piece of code I haven't tested :*/

// Drag & Drop the vertical layout group here
public UnityEngine.UI.VerticalLayoutGroup verticalLayoutGroup ;

// ... In your function
RectTransform parent = verticalLayoutGroup.GetComponent<RectTransform>() ;
for( int index = 0 ; index < stringList.Count ; ++index )
{
     GameObject g = new GameObject( stringList[index] ) ;
     UnityEngine.UI.Text t = g.AddComponent<UnityEngine.UI.Text>();
     t.addComponent<RectTransform>().setParent( parent ) ;
     t.text = stringList[index] ;
}
/*
If you need more customization, you can instantiate a prefab instead of
manually create the texts gameobjects.*/
Comment

PREVIOUS NEXT
Code Example
Csharp :: get xml from url 
Csharp :: ontriggerenter unity not working 
Csharp :: how to configure visual studio for unity 
Csharp :: remove control characters from string c# 
Csharp :: c# reflection create generic type 
Csharp :: unity action 
Csharp :: entity framework id not auto increment 
Csharp :: assert throw 
Csharp :: string length f# 
Csharp :: c# async task constructor 
Csharp :: EF .NET4 INSERT IMPROVE PERFORMACE 
Csharp :: concatenation on different lines in f# 
Csharp :: void on TriggerCollisionEnter2D 
Csharp :: unity SceneTemplatePipeline 
Csharp :: c sharp xml prettier 
Csharp :: c# get program version 
Csharp :: c# different getter setter types 
Csharp :: how to hide cell in epplus 
Csharp :: MissingMethodException: PlayerManager.OnPlayerLeft Due to: Attempted to access a missing member. 
Csharp :: Camera follow player script unity 
Csharp :: c# windows forms how to get controls in gropu box 
Csharp :: async method out parameter c# 
Csharp :: prevent C# app from lingering after closing in background processes 
Csharp :: replace filename extension c# 
Csharp :: convert enum to keyvalue 
Csharp :: C# Relational Operators 
Csharp :: Open API support for ASP.NET Core Minimal API 
Csharp :: How to set a Printer Port in C# on a specified Printer 
Csharp :: c# check if pdf is protected without password 
Csharp :: vb.net check operating system 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =