--- description: globs: alwaysApply: true --- # Cursor Rules for Unity Game Project ## Project Overview This is a Unity game project with a comprehensive framework architecture consisting of AFramework (core framework) and AGame (game logic). The project follows component-based architecture, uses state machines, proxy patterns, and event-driven communication. ## Code Style and Conventions ### C# Coding Standards - Use PascalCase for public members, camelCase for private members - Follow Unity naming conventions (e.g., MonoBehaviour classes end with descriptive names) - Use meaningful variable and function names - Add XML documentation comments for public APIs - Use regions (#region) to organize code sections ### Unity-Specific Guidelines - Inherit from MonoBehaviour for component scripts - Use ScriptableObjects for data containers and shared resources - Leverage Unity's built-in systems (Input System, UI system, physics engine) - Use Coroutines for time-based operations - Implement proper error handling with try-catch blocks - Use Unity's Debug class for logging (Debug.Log, Debug.LogWarning, Debug.LogError) ## Architecture Patterns ### Framework Layer (AFramework) - UIEx: Custom UI components and extensions - Runtime: Core framework libraries - Plugins: Third-party integrations (DOTween, AntiCheat, DynamicBone, etc.) - Editor: Unity editor extensions and tools ### Game Logic Layer (AGame) - Base: Core game systems (Launch, FSM, etc.) - Game: Gameplay systems (Entity, Skill, Effect, etc.) - Proxy: Data access layer for all game systems - UI: Modular UI system with Window/Box pattern - Platform: Multi-platform support - Command: Command pattern implementation - Item: Item system with static/entity/extension structure - Utils: Utility classes and extensions ### Key Design Patterns - **State Machine**: Game state management (Initial → Login → World) - **Proxy Pattern**: Data access and network communication - **Component Pattern**: Entity system with modular components - **Event-Driven**: Extensive use of events for system communication - **Command Pattern**: UI interactions and game actions ## File Organization ### Directory Structure ``` Assets/ ├── AFramework/ # Core framework │ ├── Scripts/UIEx/ # UI extensions │ ├── Runtime/ # Framework libraries │ ├── Plugins/ # Third-party integrations │ ├── Joystick/ # Input system │ └── Editor/ # Editor tools ├── AGame/ # Game logic │ ├── Scripts/ # Game scripts │ ├── Scenes/ # Unity scenes │ ├── Configs/ # Game configuration │ ├── Resources/ # Runtime resources │ ├── Res/ # Game assets │ └── Editor/ # Game editor tools ``` ### Naming Conventions - **Scripts**: PascalCase (e.g., `GameManager.cs`, `EntityPlayer.cs`) - **UI Components**: Window suffix for main windows, Box suffix for dialogs - **Proxy Classes**: System name + Proxy (e.g., `PlayerProxy.cs`, `NetworkProxy.cs`) - **Entity Classes**: Entity + Type (e.g., `EntityPlayer.cs`, `EntityBoss.cs`) - **State Classes**: Stat_ + Action (e.g., `Stat_IdleAction.cs`, `Stat_MoveAction.cs`) ## Development Guidelines ### Component Development - Keep components focused on single responsibility - Use composition over inheritance - Implement proper lifecycle methods (Awake, Start, Update, etc.) - Handle component dependencies through GetComponent or dependency injection ### UI Development - Follow Window/Box pattern for UI organization - Separate View logic from business logic - Use event-driven communication between UI components - Implement proper UI state management ### Data Management - Use Proxy classes for data access - Implement proper data validation - Use events for data change notifications - Follow the established data flow patterns ### Performance Considerations - Use object pooling for frequently instantiated objects - Optimize draw calls and material batching - Implement proper memory management - Use Unity's profiling tools for performance analysis ### Error Handling - Implement comprehensive error handling - Use Unity's assertion system for debugging - Log errors appropriately with context - Provide user-friendly error messages ## Testing and Debugging ### Debugging Tools - Use SRDebugger for runtime debugging - Implement custom debug visualizations - Use Unity's profiler for performance analysis - Add debug logs for critical game systems ### Testing Strategy - Unit test critical game logic - Integration test for system interactions - Performance test for resource-intensive operations - User acceptance testing for UI flows ## Platform Support ### Multi-Platform Considerations - Use platform abstraction layer (KPlatform) - Handle platform-specific features appropriately - Test on target platforms regularly - Follow platform-specific guidelines ### Build Process - Use proper build configurations - Implement asset bundling for optimization - Handle platform-specific asset requirements - Follow platform submission guidelines ## Documentation ### Code Documentation - Document public APIs with XML comments - Maintain README files for major systems - Document configuration file formats - Keep architecture documentation updated ### User Documentation - Document game features and mechanics - Maintain user guides and tutorials - Document known issues and workarounds - Keep release notes updated ## Security and Anti-Cheat ### Security Measures - Use AntiCheatToolkit for cheat prevention - Implement server-side validation - Secure sensitive data and communications - Follow security best practices ### Data Protection - Use ObscuredTypes for sensitive data - Implement proper data encryption - Secure network communications - Protect user privacy and data ## Asset Management ### Resource Organization - Organize assets by type and purpose - Use proper naming conventions for assets - Implement asset versioning - Optimize asset sizes and formats ### Asset Pipeline - Use Unity's asset pipeline effectively - Implement custom asset processors when needed - Optimize asset loading and streaming - Handle asset dependencies properly ## Version Control ### Git Workflow - Use meaningful commit messages - Follow branching strategy for features - Maintain clean commit history - Use .gitignore for Unity-specific files ### Collaboration - Coordinate on shared systems - Document breaking changes - Maintain coding standards across team - Use code review process ## Performance Optimization ### Memory Management - Implement proper object pooling - Minimize garbage collection - Use structs for small, frequently used data - Optimize asset loading and unloading ### Rendering Optimization - Use LOD systems for complex models - Implement occlusion culling - Optimize shader usage - Batch draw calls appropriately ### Network Optimization - Minimize network traffic - Implement proper packet compression - Use efficient serialization - Handle network latency appropriately ## Accessibility and Localization ### Accessibility - Support multiple input methods - Implement proper UI scaling - Provide audio alternatives - Follow accessibility guidelines ### Localization - Use proper localization system - Support multiple languages - Handle text direction and formatting - Test with different locales ## Monitoring and Analytics ### Game Analytics - Implement proper event tracking - Monitor player behavior - Track performance metrics - Use analytics for game balancing ### Error Monitoring - Implement crash reporting - Monitor error rates - Track performance issues - Use monitoring for proactive maintenance ## Deployment and Release ### Release Process - Follow proper versioning - Implement staged rollouts - Maintain backward compatibility - Handle hotfixes appropriately ### Quality Assurance - Implement comprehensive testing - Use automated testing where possible - Perform manual testing on all platforms - Maintain quality gates for releases ## Maintenance and Updates ### Code Maintenance - Refactor code regularly - Remove dead code - Update dependencies - Maintain code quality ### Content Updates - Plan for content updates - Implement content management system - Handle content versioning - Maintain content quality ## Emergency Procedures ### Critical Issues - Have rollback procedures ready - Maintain emergency contact list - Document incident response procedures - Test emergency procedures regularly ### Data Recovery - Implement proper backup systems - Test data recovery procedures - Maintain data integrity - Document recovery processes ## Future Considerations ### Scalability - Design for future growth - Plan for additional platforms - Consider international expansion - Prepare for increased user base ### Technology Updates - Stay updated with Unity versions - Plan for technology migrations - Evaluate new tools and libraries - Maintain technical debt awareness ## Team Collaboration ### Communication - Use clear communication channels - Document decisions and rationale - Maintain team knowledge sharing - Foster collaborative development ### Code Reviews - Implement thorough code reviews - Use review checklists - Provide constructive feedback - Maintain review standards ## Compliance and Legal ### Platform Compliance - Follow platform guidelines - Maintain compliance with terms of service - Handle user data appropriately - Stay updated with policy changes ### Legal Considerations - Protect intellectual property - Handle licensing appropriately - Maintain proper attribution - Follow legal requirements ## Continuous Improvement ### Process Improvement - Regularly evaluate development processes - Gather team feedback - Implement process improvements - Maintain agile development practices ### Skill Development - Encourage continuous learning - Share knowledge and best practices - Attend conferences and workshops - Stay updated with industry trends ## Notes - This project uses a sophisticated framework architecture - Pay attention to the established patterns and conventions - Follow the existing code style and organization - Maintain consistency with the current architecture - Consider the impact of changes on the overall system - Test thoroughly before implementing changes - Document any architectural decisions - Keep the codebase maintainable and scalable