Awesome
Unity Best Practices
Design principles, design patterns, coding challenges, and more!
<img src="./Unity/Assets/Samples/~ Shared/Documentation/Images/BestPractices.png" width="600" /> <BR>Details
Here is a complete overview of Best Practices and related topics for Unity.
The repo is complete with code samples.
Enjoy!
<BR> <BR>Related Repos
Name | Description | Educational Use | Production Use | Link |
---|---|---|---|---|
Unity Best Practices | Repo with best practices for Unity. It covers project structure and code standards. | ✅ | ❌ | (See below) |
Unity Project Template | Template showcasing best practices and coding standards for Unity projects. | ❌ | ✅ | link |
Table of Contents
<BR> <BR>Getting Started
Instructions
- Download this repo (*.zip or *.git)
- Download the Unity Editor (See
Unity Version
below) - Open the Unity Hub
- Unity Hub: Click the 'Add' button
- Unity Hub: Choose the
Unity
folder from the repo - Unity Hub: Choose the project from the project list to open the Unity Editor
- Unity Editor: Open one of the included Scenes
- Unity Editor: Play the Scene
- Enjoy!
Configuration
Documentation
ReadMe.md
- The primary documentation for this repo
Configuration
Unity Target
- Standalone MAC/PCUnity Version
- Use this VersionUnity Rendering
- Universal Render Pipeline (URP)Unity Aspect Ratio
- Game View 10x16
Structure
Unity
- Open this folder in the Unity Editor
Dependencies
Various
- Already included via Unity Package Manager as this Version
Design Principles
Theory
S.O.L.I.D. Principles make software designs more understandable, easier to maintain and easier to extend. As a software engineer, these 5 principles are essential to know! (See <a href="https://itnext.io/solid-principles-explanation-and-examples-715b975dcad4">ITNext.io</a>)
List
Name | Description | Code Sample Complete |
---|---|---|
Single Responsibility | One reason to change. | ✅ |
Open/Closed | Open for extension, closed for modification. | ✅ |
Liskov Substitution | Subtypes must be substitutable for their base types. | ✅ |
Interface Segregation | No client should be forced to depend on interfaces they do not use. | ✅ |
Dependency Inversion | High-level modules should not depend on low-level ones; both should depend on abstractions. | ✅ |
Design Patterns
Theory
These patterns provide solutions to common design problems and are a foundational part of software design knowledge. There are 3 types.
- Behavioral Patterns - Design patterns to deal with object-object communication. (See <a href="https://en.wikipedia.org/wiki/Behavioral_pattern">Wikipedia</a>)
- Creational Patterns - Design patterns to deal with object creation. (See <a href="https://en.wikipedia.org/wiki/Creational_pattern">Wikipedia</a>)
- Structural Patterns - Design patterns to deal with object-object relationships. (See <a href="https://en.wikipedia.org/wiki/Structural_pattern">Wikipedia</a>)
Diagram
<BR> <img src="./Unity/Assets/Samples/~ Shared/Documentation/Images/design-patterns.gif" width="600" /> <BR> <BR>List
Type | Name | Description | Code Sample Complete |
---|---|---|---|
Behavioral | |||
Chain of Responsibility | Passes request among a chain of objects. | ❌ | |
Command | Encapsulates a request as an object. | ✅ | |
Interpreter | Provides a language interpreter. | ❌ | |
Iterator | Sequentially access elements in a collection. | ❌ | |
Mediator | Centralized external communications. | ❌ | |
Memento | Capture and restore object's internal state. | ✅ | |
Observer | Notify changes to its state. | ❌ | |
State | Alter behavior when its state changes. | ✅ | |
Strategy | Encapsulates algorithms using strategy pattern. | ✅ | |
Template Method | Defer exact steps to subclasses. | ❌ | |
Visitor | Add new operations without altering a class. | ❌ | |
Creational | |||
Abstract Factory | Creates families of related objects. | ❌ | |
Builder | Separates object construction from its representation. | ✅ | |
Factory Method | Creates objects without specifying the exact class to create. | ✅ | |
Prototype | Clone or copy initialized instances. | ❌ | |
Singleton | Ensures a class has one instance. | ✅ | |
Structural | |||
Adapter | Matches interfaces of different classes. | ❌ | |
Bridge | Separates an object’s interface from its implementation. | ❌ | |
Composite | Tree structure of simple and composite objects. | ❌ | |
Decorator | Adds responsibilities to objects dynamically. | ✅ | |
Facade | Simplified interface to a subsystem. | ✅ | |
Flyweight | Reuses objects by sharing common state. | ✅ | |
Proxy | Represents another object. | ❌ |
Features
- Editor Scripting - Unity lets you extend the editor with your own custom inspectors and Editor Windows and you can define how properties are displayed in the inspector with custom Property Drawers. See <a href="https://docs.unity3d.com/Manual/ExtendingTheEditor.html">Unity Docs</a> for more.
Tooling
- Unit Testing - Software testing where individual units/ components of a software are tested. The purpose is to validate that each unit of the software performs as designed. A unit is the smallest testable part of any software. See <a href="https://docs.unity3d.com/Manual/testing-editortestsrunner.html">Unity Docs</a> for more.
Credits
Created By
- Samuel Asher Rivello
- Over 25 years XP with game development (2024)
- Over 11 years XP with Unity (2024)
Contact
- Twitter - <a href="https://twitter.com/srivello/">@srivello</a>
- Git - <a href="https://github.com/SamuelAsherRivello/">Github.com/SamuelAsherRivello</a>
- Resume & Portfolio - <a href="http://www.SamuelAsherRivello.com">SamuelAsherRivello.com</a>
- LinkedIn - <a href="https://Linkedin.com/in/SamuelAsherRivello">Linkedin.com/in/SamuelAsherRivello</a> <--- Say Hello! :)
License
Provided as-is under <a href="./LICENSE">MIT License</a> | Copyright ™ & © 2006 - 2024 Rivello Multimedia Consulting, LLC