Table of Contents

File Structure & Organization

One type per file. Filename matches type name.

File Layout Order

// 1. Using directives (System.* first)
using System;
using UnityEngine;
using PixelEngine.Architecture;

// 2. Namespace
namespace PixelEngine.Core
{
    // 3. One primary type per file
    public class GameManagerComponent : MonoBehaviour, IDisposable
    {
        // ── 4. Constants / static readonly ──
        public const int MAX_PLAYERS = 100;
        private static readonly float s_tickRate = 0.02f;

        // ── 5. Static fields ──
        private static int s_instanceCount;

        // ── 6. Nested types (Configuration, Reference, State, Components) ──
        [Serializable]
        public struct Configuration : IConfiguration
        {
            public int maxPlayers;

            public static readonly Configuration Default = new Configuration
            {
                maxPlayers = 100
            };
        }

        [Serializable]
        public struct Reference : IReference
        {
            public static readonly Reference Default = new Reference();
        }

        public struct State : IState
        {
            public int activePlayers;
            public bool isRunning;
        }

        public class Components : IComponents { }

        // ── 7. Serialized fields ──
        [SerializeField]
        private Configuration _configuration = Configuration.Default;

        [SerializeField]
        private Reference _reference = Reference.Default;

        // ── 8. Private fields ──
        private State _state;

        // ── 9. Properties ──
        public ref readonly Configuration configuration => ref _configuration;
        public ref readonly Reference reference => ref _reference;
        public State state => _state;
        public Components components { get; private set; }

        // ── 10. Events / Delegates ──
        public event Action<int> PlayerCountChanged;

        // ── 11. Unity lifecycle (Awake → OnDestroy) ──
        private void Awake()
        {
            _state = new State();
            components = new Components();
            Init();
        }

        private void OnDestroy()
        {
            Dispose();
        }

        // ── 12. Public methods ──
        public void SetConfiguration(in Configuration configuration)
        {
            _configuration = configuration;
        }

        // ── 13. Private methods ──
        private void Init() { }

        // ── 14. Dispose ──
        public void Dispose() { }
    }
}

Namespace Pattern

PixelEngine.<Package>                  → PixelEngine.Common, PixelEngine.Architecture
PixelEngine.<Package>.<Module>         → PixelEngine.Core.FSM, PixelEngine.Core.BT
PixelEngine.<Package>.Editor           → PixelEngine.Platform.Editor

Unity-Specific File Rules

Rule Details
[SerializeField] Own line above field
[CreateAssetMenu] On ScriptableObject configs
Editor code Editor/ folder, .Editor namespace suffix
Runtime code Runtime/ folder
Assembly definitions One .asmdef per package root

References