agentleFS
skysepehruskysepehru/unity-claude-skills/skills/unity-ugui-list/SKILL.md

unity-ugui-list

Skill1 starsChanged 5 months agoMITView on GitHub

Generate uGUI list components where elements are created from a list of data.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Always create list UI files as a pair in a named subfolder under the feature's UI/ folder:

    line 206
  2. Distinctive:

    Item Prefab: Create prefab with ListUIComponentItem subclass

    line 223
  3. Distinctive:

    Add Button component (for selection)

    line 224
  4. Distinctive:

    Add selected indicator GameObject (hidden by default)

    line 225
  5. Distinctive:

    Add UI elements for data display

    line 226
  6. Distinctive:

    Component: Add ListUIComponent subclass to parent

    line 228

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Unity uGUI List Pattern

Generate list-type UI components using the ListUIComponent/ListUIComponentItem pattern.

Overview

This pattern provides:

  • Type-safe generic list containers
  • Automatic item instantiation from data
  • Selection management (optional)
  • Data export/import (Memento pattern)
  • Item reordering

Base Classes

ListUIComponent (Container)

public abstract class ListUIComponent<TListUIComponentItem, TListUIComponentItemDataType> : MonoBehaviour
    where TListUIComponentItem : ListUIComponentItem<TListUIComponentItem, TListUIComponentItemDataType>
    where TListUIComponentItemDataType : class, ICloneable<TListUIComponentItemDataType>, IEquatable<TListUIComponentItemDataType>
{
    [Inject] private DiContainer _diContainer;
    [SerializeField] private Transform _itemParent;
    [SerializeField] private TListUIComponentItem _itemPrefab;

    private readonly List<TListUIComponentItem> _items = new();

    public int CurrentSelectedItemIndex { get; private set; } = -1;
    public bool IsItemSelected => IsSelectable && CurrentSelectedItemIndex != -1;
    public bool IsEmpty => _items.Count == 0;
    public TListUIComponentItemDataType CurrentSelectedItemData =>
        IsItemSelected ? _items[CurrentSelectedItemIndex].CurrentDataSource : null;

    public event Action<TListUIComponentItemDataType> OnItemSelected;
    public event Action<TListUIComponentItemDataType> OnItemsUnselected;

    // Override to enable/disable selection behavior
    protected abstract bool IsSelectable { get; }

    // Load items from data list
    public void LoadItemsFromDataSourceList(List<TListUIComponentItemDataType> dataSourceList);

    // Export current items as data list
    public List<TListUIComponentItemDataType> ExportDataSourceListFromItems();

    // Item management
    public void AddItem(TListUIComponentItemDataType data, bool useClone = false);
    public void RemoveItemAtIndex(int index);
    public void RemoveItemByDataSource(TListUIComponentItemDataType data);
    public void RemoveCurrentSelectedItem();
    public void ClearItems();

    // Reordering
    public void MoveItemAtIndexUp(int index);
    public void MoveItemAtIndexDown(int index);
    public void MoveCurrentSelectedItemUp();
    public void MoveCurrentSelectedItemDown();

    // Modification
    public void ModifySelectedItem(Action<TListUIComponentItemDataType> modifier);
    public void ModifyItemAtIndex(int index, Action<TListUIComponentItemDataType> modifier);
    public void UpdateAllItemsWithTheirDataSource();
}

ListUIComponentItem (Item)

public abstract class ListUIComponentItem<TItemType, TItemDataType> : MonoBehaviour
    where TItemType : ListUIComponentItem<TItemType, TItemDataType>
{
    [SerializeField] private Button _button;
    [SerializeField] private GameObject _selectedIndicator;

    public event Action<TItemType> OnSelected;
    public event Action<TItemType> OnRequestDelete;

    public TItemDataType CurrentDataSource { get; private set; }

    public bool IsSelected
    {
        get => _selectedIndicator.activeSelf;
        set => _selectedIndicator.SetActive(value);
    }

    protected virtual void Awake()
    {
        _button.onClick.AddListener(() => OnSelected?.Invoke((TItemType)this));
        _selectedIndicator.SetActive(false);
    }

    public void SetData(TItemDataType data)
    {
        CurrentDataSource = data;
        ShowUIWithData(data);
    }

    // Implement to display data in UI elements
    protected abstract void ShowUIWithData(TItemDataType data);

    public void RefreshUIWithDataSource() => ShowUIWithData(CurrentDataSource);

    public void RequestDelete() => OnRequestDelete?.Invoke((TItemType)this);
}

Data Interface Requirements

Data types must implement:

public interface ICloneable<T>
{
    T Clone();
}

// Use System.IEquatable<T>

Usage Example

1. Define Data Model

public class PlayerData : ICloneable<PlayerData>, IEquatable<PlayerData>
{
    public string Id { get; set; }
    public string Name { get; set; }
    public int Score { get; set; }

    public PlayerData Clone() => new PlayerData { Id = Id, Name = Name, Score = Score };
    public bool Equals(PlayerData other) => other != null && Id == other.Id;
}

2. Create Item Class

public class PlayerListUIItem : ListUIComponentItem<PlayerListUIItem, PlayerData>
{
    [SerializeField] private TMP_Text _nameText;
    [SerializeField] private TMP_Text _scoreText;

    public string Name
    {
        get => _nameText.text;
        set => _nameText.text = value;
    }

    public int Score
    {
        get => int.Parse(_scoreText.text);
        set => _scoreText.text = value.ToString();
    }

    protected override void ShowUIWithData(PlayerData data)
    {
        Name = data.Name;
        Score = data.Score;
    }
}

3. Create Component Class

public class PlayerListUIComponent : ListUIComponent<PlayerListUIItem, PlayerData>
{
    // Set to true for selectable list, false for click-to-action list
    protected override bool IsSelectable => true;
}

4. Use in Panel

public class LeaderboardUIPanel : MonoBehaviour
{
    [SerializeField] private PlayerListUIComponent _playerList;

    private void Start()
    {
        _playerList.OnItemSelected += HandlePlayerSelected;
    }

    public void LoadPlayers(List<PlayerData> players)
    {
        _playerList.LoadItemsFromDataSourceList(players);
    }

    private void HandlePlayerSelected(PlayerData player)
    {
        Debug.Log($"Selected: {player.Name}");
    }
}

Folder Placement

Always create list UI files as a pair in a named subfolder under the feature's UI/ folder:

Scripts/{Feature}/UI/{ListName}/
├── {ListName}UIComponent.cs    # The list container (manages the collection)
└── {ListName}UIItem.cs         # Individual list item (one per row)

Example:

Scripts/Exercises/UI/ExerciseList/
├── ExerciseListUIComponent.cs
└── ExerciseListUIItem.cs

Inspector Setup

  1. Item Prefab: Create prefab with ListUIComponentItem subclass
    • Add Button component (for selection)
    • Add selected indicator GameObject (hidden by default)
    • Add UI elements for data display
  2. Component: Add ListUIComponent subclass to parent
    • Assign item prefab reference
    • Assign item parent transform (content container)

Selection Behavior

  • IsSelectable = true: Visual selection, deselect previous, track index
  • IsSelectable = false: Click fires event but no visual state management

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.