|
| 1 | +# Project Structure Specification |
| 2 | + |
| 3 | +## 1. Overview |
| 4 | + |
| 5 | +This document defines the Unity project structure for Knowledge RPG. The structure follows Unity best practices and supports the modular architecture defined in `SPEC.md`. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 2. Root Structure |
| 10 | + |
| 11 | +``` |
| 12 | +Knowledge/ |
| 13 | +├── Assets/ |
| 14 | +│ ├── Scripts/ |
| 15 | +│ ├── Editor/ |
| 16 | +│ ├── Resources/ |
| 17 | +│ ├── Plugins/ |
| 18 | +│ ├── ThirdParty/ |
| 19 | +│ ├── Art/ |
| 20 | +│ ├── Audio/ |
| 21 | +│ └── Prefabs/ |
| 22 | +├── Packages/ |
| 23 | +├── ProjectSettings/ |
| 24 | +├── Tests/ |
| 25 | +└── docs/ |
| 26 | +``` |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## 3. Assets/Scripts Structure |
| 31 | + |
| 32 | +``` |
| 33 | +Assets/Scripts/ |
| 34 | +├── Core/ |
| 35 | +│ ├── GameManager.cs |
| 36 | +│ ├── SaveLoadSystem.cs |
| 37 | +│ ├── SettingsManager.cs |
| 38 | +│ ├── EventSystem.cs |
| 39 | +│ └── AchievementSystem.cs |
| 40 | +├── Player/ |
| 41 | +│ ├── PlayerController.cs |
| 42 | +│ ├── CharacterData.cs |
| 43 | +│ ├── CharacterEditor.cs |
| 44 | +│ ├── InventorySystem.cs |
| 45 | +│ ├── EquipmentSystem.cs |
| 46 | +│ ├── CombatSystem.cs |
| 47 | +│ ├── AnimationSystem.cs |
| 48 | +│ └── SurvivalStats.cs |
| 49 | +├── Discovery/ |
| 50 | +│ ├── DiscoverySystem.cs |
| 51 | +│ ├── CraftingSystem.cs |
| 52 | +│ ├── RecipeSystem.cs |
| 53 | +│ ├── ResourceSystem.cs |
| 54 | +│ └── KnowledgeTreeUI.cs |
| 55 | +├── Environment/ |
| 56 | +│ ├── WeatherSystem.cs |
| 57 | +│ ├── EcosystemManager.cs |
| 58 | +│ ├── DayNightCycle.cs |
| 59 | +│ ├── WorldMap.cs |
| 60 | +│ ├── ZoneSystem.cs |
| 61 | +│ ├── TerrainSystem.cs |
| 62 | +│ ├── BuildingSystem.cs |
| 63 | +│ └── SoundSystem.cs |
| 64 | +├── Systems/ |
| 65 | +│ ├── KnowledgeSystem.cs |
| 66 | +│ ├── ProgressionSystem.cs |
| 67 | +│ ├── SkillSystem.cs |
| 68 | +│ ├── ItemDatabase.cs |
| 69 | +│ └── CraftingDatabase.cs |
| 70 | +├── AI/ |
| 71 | +│ ├── NPCManager.cs |
| 72 | +│ ├── DialogueSystem.cs |
| 73 | +│ ├── QuestSystem.cs |
| 74 | +│ ├── EnemySystem.cs |
| 75 | +│ └── ShopSystem.cs |
| 76 | +├── UI/ |
| 77 | +│ ├── UIManager.cs |
| 78 | +│ ├── MainMenu.cs |
| 79 | +│ ├── HUDSystem.cs |
| 80 | +│ ├── PauseMenu.cs |
| 81 | +│ ├── NotificationSystem.cs |
| 82 | +│ └── LoadingScreens.cs |
| 83 | +└── Utils/ |
| 84 | + ├── Extensions/ |
| 85 | + ├── Helpers/ |
| 86 | + └── Constants/ |
| 87 | +``` |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## 4. Assets/Art Structure |
| 92 | + |
| 93 | +``` |
| 94 | +Assets/Art/ |
| 95 | +├── Characters/ |
| 96 | +│ ├── Player/ |
| 97 | +│ ├── NPCs/ |
| 98 | +│ └── Enemies/ |
| 99 | +├── Environment/ |
| 100 | +│ ├── Tiles/ |
| 101 | +│ ├── Buildings/ |
| 102 | +│ └── Props/ |
| 103 | +├── Items/ |
| 104 | +│ ├── Icons/ |
| 105 | +│ ├── Equipment/ |
| 106 | +│ └── Materials/ |
| 107 | +├── Effects/ |
| 108 | +│ ├── Particles/ |
| 109 | +│ └── Shaders/ |
| 110 | +└── UI/ |
| 111 | + ├── Icons/ |
| 112 | + ├── Fonts/ |
| 113 | + └── Sprites/ |
| 114 | +``` |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## 5. Assets/Prefabs Structure |
| 119 | + |
| 120 | +``` |
| 121 | +Assets/Prefabs/ |
| 122 | +├── Characters/ |
| 123 | +│ ├── Player.prefab |
| 124 | +│ └── NPCs/ |
| 125 | +├── Environment/ |
| 126 | +│ ├── Buildings/ |
| 127 | +│ ├── Tiles/ |
| 128 | +│ └── Props/ |
| 129 | +├── UI/ |
| 130 | +│ ├── Panels/ |
| 131 | +│ └── Components/ |
| 132 | +└── Systems/ |
| 133 | +``` |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## 6. Assets/Resources Structure |
| 138 | + |
| 139 | +``` |
| 140 | +Assets/Resources/ |
| 141 | +├── Data/ |
| 142 | +│ ├── Items/ |
| 143 | +│ ├── Recipes/ |
| 144 | +│ ├── Dialogues/ |
| 145 | +│ └── Quests/ |
| 146 | +├── Localization/ |
| 147 | +│ └── Languages/ |
| 148 | +└── Config/ |
| 149 | +``` |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## 7. Assets/Editor Structure |
| 154 | + |
| 155 | +``` |
| 156 | +Assets/Editor/ |
| 157 | +├── CustomEditors/ |
| 158 | +├── PropertyDrawers/ |
| 159 | +├── EditorWindows/ |
| 160 | +├── Gizmos/ |
| 161 | +└── MenuItems/ |
| 162 | +``` |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## 8. Scene Structure |
| 167 | + |
| 168 | +``` |
| 169 | +Assets/Scenes/ |
| 170 | +├── Boot/ |
| 171 | +│ └── Boot.unity |
| 172 | +├── MainMenu/ |
| 173 | +│ └── MainMenu.unity |
| 174 | +├── CharacterCreation/ |
| 175 | +│ └── CharacterCreation.unity |
| 176 | +├── WorldMap/ |
| 177 | +│ └── WorldMap.unity |
| 178 | +├── Game/ |
| 179 | +│ ├── StoneAge/ |
| 180 | +│ ├── BronzeAge/ |
| 181 | +│ ├── IronAge/ |
| 182 | +│ ├── Medieval/ |
| 183 | +│ ├── Renaissance/ |
| 184 | +│ ├── Industrial/ |
| 185 | +│ ├── Modern/ |
| 186 | +│ └── Space/ |
| 187 | +└── System/ |
| 188 | + ├── Settings.unity |
| 189 | + └── Loading.unity |
| 190 | +``` |
| 191 | + |
| 192 | +--- |
| 193 | + |
| 194 | +## 9. Tests Structure |
| 195 | + |
| 196 | +``` |
| 197 | +Tests/ |
| 198 | +├── Editor/ |
| 199 | +│ ├── Core/ |
| 200 | +│ ├── Player/ |
| 201 | +│ ├── Discovery/ |
| 202 | +│ ├── Environment/ |
| 203 | +│ ├── Systems/ |
| 204 | +│ ├── AI/ |
| 205 | +│ └── UI/ |
| 206 | +└── PlayMode/ |
| 207 | + ├── Integration/ |
| 208 | + └── EndToEnd/ |
| 209 | +``` |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## 10. Naming Conventions |
| 214 | + |
| 215 | +| Element | Convention | Example | |
| 216 | +|---------|-----------|---------| |
| 217 | +| Scripts | PascalCase | `PlayerController.cs` | |
| 218 | +| Folders | PascalCase | `Assets/Scripts/Player/` | |
| 219 | +| Scenes | PascalCase | `StoneAge.unity` | |
| 220 | +| Prefabs | PascalCase | `Player.prefab` | |
| 221 | +| Assets | PascalCase | `player_idle.anim` | |
| 222 | +| ScriptableObjects | PascalCase | `ItemDatabase.asset` | |
| 223 | + |
| 224 | +--- |
| 225 | + |
| 226 | +## 11. Script Organization |
| 227 | + |
| 228 | +### Monobehaviour Scripts |
| 229 | + |
| 230 | +``` |
| 231 | +[RequireComponent(typeof(Rigidbody))] |
| 232 | +[RequireComponent(typeof(Collider))] |
| 233 | +public class PlayerController : MonoBehaviour |
| 234 | +{ |
| 235 | + [Header("Movement")] |
| 236 | + [SerializeField] private float moveSpeed = 5f; |
| 237 | +
|
| 238 | + [Header("References")] |
| 239 | + [SerializeField] private Rigidbody rb; |
| 240 | + [SerializeField] private Animator animator; |
| 241 | +
|
| 242 | + private void Awake() { } |
| 243 | + private void Start() { } |
| 244 | + private void Update() { } |
| 245 | + private void FixedUpdate() { } |
| 246 | +
|
| 247 | + public void PublicMethod() { } |
| 248 | + private void PrivateMethod() { } |
| 249 | +} |
| 250 | +``` |
| 251 | + |
| 252 | +### ScriptableObject Data |
| 253 | + |
| 254 | +``` |
| 255 | +[CreateAssetMenu(fileName = "NewItem", menuName = "Knowledge/Items")] |
| 256 | +public class ItemData : ScriptableObject |
| 257 | +{ |
| 258 | + public string itemId; |
| 259 | + public string itemName; |
| 260 | + public ItemType type; |
| 261 | + public Sprite icon; |
| 262 | + public int maxStack = 99; |
| 263 | +} |
| 264 | +``` |
| 265 | + |
| 266 | +--- |
| 267 | + |
| 268 | +## 12. Module Dependencies |
| 269 | + |
| 270 | +``` |
| 271 | +Core |
| 272 | +├── → All Modules (game manager orchestrates everything) |
| 273 | +├── Player |
| 274 | +│ └── → Core, Systems |
| 275 | +├── Discovery |
| 276 | +│ └── → Core, Systems |
| 277 | +├── Environment |
| 278 | +│ └── → Core |
| 279 | +├── Systems |
| 280 | +│ └── → Core |
| 281 | +├── AI |
| 282 | +│ └── → Core, Player, Systems |
| 283 | +└── UI |
| 284 | + └── → Core, Player, Systems |
| 285 | +``` |
| 286 | + |
| 287 | +--- |
| 288 | + |
| 289 | +## 13. Data Flow |
| 290 | + |
| 291 | +``` |
| 292 | +User Input → PlayerController → EventSystem → Relevant System → EventSystem → UI/Game State |
| 293 | +``` |
| 294 | + |
| 295 | +--- |
| 296 | + |
| 297 | +## 14. File Templates |
| 298 | + |
| 299 | +### New Script Template |
| 300 | + |
| 301 | +``` |
| 302 | +using UnityEngine; |
| 303 | +
|
| 304 | +namespace Knowledge.{Module} |
| 305 | +{ |
| 306 | + public class {ClassName} : MonoBehaviour |
| 307 | + { |
| 308 | + // Serialized fields |
| 309 | + // Private fields |
| 310 | + // Public properties |
| 311 | +
|
| 312 | + private void Awake() { } |
| 313 | + private void Start() { } |
| 314 | + private void OnEnable() { } |
| 315 | + private void OnDisable() { } |
| 316 | + } |
| 317 | +} |
| 318 | +``` |
| 319 | + |
| 320 | +--- |
| 321 | + |
| 322 | +## 15. Notes |
| 323 | + |
| 324 | +- Keep scripts focused on single responsibility |
| 325 | +- Use ScriptableObjects for data-driven design |
| 326 | +- Prefer composition over inheritance |
| 327 | +- Use events for loose coupling |
| 328 | +- All public methods should have XML documentation |
0 commit comments