/unity-best-practices

Unity Best Practices for C#; Design principles, design patterns, coding challenges, and more!

Primary LanguageC#

Unity Best Practices

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

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

  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

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 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

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 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