Dev Guide
WebsiteGitHubGitBook
  • 📝Dev Intro
    • Using GitHub
    • Using Unity
    • Licensing
    • File Naming & Organization
      • File Naming
      • File Organization
        • Object Type
  • 📡Networking
    • Introduction to Game Networking
    • FishNet Networking
      • Server
      • Client
      • Server RPC
      • ObserversRPC
      • Network Message
  • 🖊️Guidelines
    • The C# Style Guide
      • Nomenclature
        • Namespaces
        • Classes & Interfaces
        • Methods
        • Fields
        • Parameters
        • Delegates
        • Events
        • Misc
      • Declarations
        • One declaration per source file
        • General class structure
        • Access Level Modifiers
        • Spacing
        • Brace Style
        • Switch Statements
        • Language
        • Common Patterns and Structure
          • Applying attributes on all network related methods.
    • Code Design Definitions
      • Actor
      • System
      • View
      • Events
        • Event Bus
        • Action
      • System Locator
      • Tweening
    • Asset Criteria
      • External Criteria
        • Animations
        • Fonts
        • Models
        • Textures
        • Graphics
        • Audio
      • Importing Criteria
        • 3D Models
        • 3D Animations
        • Textures
        • Graphics
        • Audio
      • Internal Criteria
        • 3D Models
        • 3D Animations
        • Textures
        • Graphics
        • Audio
    • SS3D's coder good practices
    • Code design patterns
  • 📖Guides
    • Application Settings
    • Running the Project
      • Configure your firewall and antivirus
      • Building the game
      • Joining a server
      • Hosting a server
      • Setting up a dedicated server
    • Debugging SS3D
    • Maintainer Guide
      • Pull request review process
    • Testing SS3D
      • Assets audit tests
      • Edit mode tests
      • Play mode tests
        • Inventory test
        • Health tests
    • Working with animations
  • 🛣️Roadmap
    • Releases
Powered by GitBook
On this page
  • Using the SystemLocator
  • ⚠️ IMPORTANT!
  • Examples

Was this helpful?

Edit on GitHub
Export as PDF
  1. Guidelines
  2. Code Design Definitions

System Locator

Class used to get game systems, using generics and then making cache of said systems.

PreviousActionNextTweening

Last updated 2 years ago

Was this helpful?

The SystemLocator is a class used to easily find any system that has been registered on it.

It helps us avoid falling into the , and does something similar to the . Also good for performance reasons, It can handle over a million calls every frame with no issues.

Using the SystemLocator

To register a new system you can call the SystemLocator.Register(this) method, it'll add that system into a dictionary of systems, preventing two of the same system from existing.

Then you can get this system from somewhere else using SystemLocator.Get<T>()

⚠️ IMPORTANT!

Note that is done automatically by classes inheriting System and NetworkedSystem. They register on Awake:

public class System : Actor
    {
        protected override void OnAwake()
        {
            base.OnAwake();
            SystemLocator.Register(this);
        }
    }

Examples

Getting the spawned players list

EntitySpawnSystem entitySpawnSystem = SystemLocator.Get<EntitySpawnSystem>();

List<PlayerControllable> playersToAssign = entitySpawnSystem.SpawnedPlayers;

Ending the round after detonating a nuke

// Ends the round, regardless of how many objectives were completed SystemLocator.Get<GamemodeSystem>().EndRound();

🖊️
Singleton pattern
Service Locator pattern