Unity Best Practices

October 22, 2024 · View on GitHub

Design principles, design patterns, coding challenges, and more!


Details

Here is a complete overview of Best Practices and related topics for Unity.

The repo is complete with code samples.

Enjoy!



Related Repos

NameDescriptionEducational UseProduction UseLink
Unity Best PracticesRepo with best practices for Unity. It covers project structure and code standards.(See below)
Unity Project TemplateTemplate showcasing best practices and coding standards for Unity projects.link


Table of Contents

  1. Configuration
  2. Design Principles
  3. Design Patterns
  4. Features
  5. Tooling
  6. Credits


Getting Started

Instructions

  1. Download this repo (*.zip or *.git)
  2. Download the Unity Editor (See Unity Version below)
  3. Open the Unity Hub
  4. Unity Hub: Click the 'Add' button
  5. Unity Hub: Choose the Unity folder from the repo
  6. Unity Hub: Choose the project from the project list to open the Unity Editor
  7. Unity Editor: Open one of the included Scenes
  8. Unity Editor: Play the Scene
  9. Enjoy!


Configuration

Documentation

  • ReadMe.md - The primary documentation for this repo

Configuration

Structure

  • Unity - Open this folder in the Unity Editor

Dependencies



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 ITNext.io)

List

NameDescriptionCode Sample Complete
Single ResponsibilityOne reason to change.
Open/ClosedOpen for extension, closed for modification.
Liskov SubstitutionSubtypes must be substitutable for their base types.
Interface SegregationNo client should be forced to depend on interfaces they do not use.
Dependency InversionHigh-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 Wikipedia)
  • Creational Patterns - Design patterns to deal with object creation. (See Wikipedia)
  • Structural Patterns - Design patterns to deal with object-object relationships. (See Wikipedia)

Diagram




List

TypeNameDescriptionCode Sample Complete
Behavioral
Chain of ResponsibilityPasses request among a chain of objects.
CommandEncapsulates a request as an object.
InterpreterProvides a language interpreter.
IteratorSequentially access elements in a collection.
MediatorCentralized external communications.
MementoCapture and restore object's internal state.
ObserverNotify changes to its state.
StateAlter behavior when its state changes.
StrategyEncapsulates algorithms using strategy pattern.
Template MethodDefer exact steps to subclasses.
VisitorAdd new operations without altering a class.
Creational
Abstract FactoryCreates families of related objects.
BuilderSeparates object construction from its representation.
Factory MethodCreates objects without specifying the exact class to create.
PrototypeClone or copy initialized instances.
SingletonEnsures a class has one instance.
Structural
AdapterMatches interfaces of different classes.
BridgeSeparates an object’s interface from its implementation.
CompositeTree structure of simple and composite objects.
DecoratorAdds responsibilities to objects dynamically.
FacadeSimplified interface to a subsystem.
FlyweightReuses objects by sharing common state.
ProxyRepresents 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 Unity Docs 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 Unity Docs for more.


Credits

Created By

  • Samuel Asher Rivello
  • Over 25 years XP with game development (2024)
  • Over 11 years XP with Unity (2024)

Contact

License

Provided as-is under MIT License | Copyright ™ & © 2006 - 2024 Rivello Multimedia Consulting, LLC