Skip to content

MuharremTozan/Agentic-Duel / .agent/skills/unity-mvc-pattern

unity-mvc-pattern

Verified

Implementation of Model-View-Controller (MVC) and Model-View-Presenter (MVP) patterns in Unity. Focuses on Separation of Concerns for scalable UI and game systems.

assets/code/ObservableList.cs.txt

View on GitHub
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Standard.Patterns.MVC {
    /// <summary>
    /// A decorator for List<T> that publishes events when the list structure changes.
    /// Essential for dynamic UI like inventory or hotbars.
    /// </summary>
    [Serializable]
    public class ObservableList<T> : IList<T> {
        [SerializeField] private List<T> list = new List<T>();
        
        public event Action<List<T>> OnChanged;

        public T this[int index] { 
            get => list[index]; 
            set { list[index] = value; Invoke(); } 
        }

        public int Count => list.Count;
        public bool IsReadOnly => false;

        public void Add(T item) { list.Add(item); Invoke(); }
        public void Clear() { list.Clear(); Invoke(); }
        public bool Contains(T item) => list.Contains(item);
        public void CopyTo(T[] array, int arrayIndex) => list.CopyTo(array, arrayIndex);
        public IEnumerator<T> GetEnumerator() => list.GetEnumerator();
        public int IndexOf(T item) => list.IndexOf(item);
        public void Insert(int index, T item) { list.Insert(index, item); Invoke(); }
        public bool Remove(T item) { var success = list.Remove(item); if (success) Invoke(); return success; }
        public void RemoveAt(int index) { list.RemoveAt(index); Invoke(); }
        IEnumerator IEnumerable.GetEnumerator() => list.GetEnumerator();

        private void Invoke() {
            Debug.Log($"[MVC] Status: ObservableList Changed | Data: Count {list.Count}");
            OnChanged?.Invoke(list);
        }
    }
}
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall