Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
/ singleton Public archive

Provide Singleton accessor to any class.

License

Notifications You must be signed in to change notification settings

umm/singleton

Repository files navigation

What?

  • Singleton なアクセスを可能にする static アクセサを提供します。

Why?

  • シンプルな Singleton 機構を作りたかったので作りました。

Install

With Unity Package Manager

upm add package dev.upm-packages.singleton

Note: upm command is provided by this repository.

You can also edit Packages/manifest.json directly.

{
  "dependencies": {
    // (snip)
    "dev.upm-packages.singleton": "[latest version]",
    // (snip)
  },
  "scopedRegistries": [
    {
      "name": "Unofficial Unity Package Manager Registry",
      "url": "https://upm-packages.dev",
      "scopes": [
        "dev.upm-packages"
      ]
    }
  ]
}

Any other else (classical umm style)

$ npm install github:umm/singleton

Usage

using UnityEngine;
using UnityModule;

public class SampleSingleton : Singleton<SampleSingleton> {

    public string Hoge = "ほげ";

}

public class Sample {

    public void Run() {
        Debug.Log(SampleSingleton.Instance.Hoge);
    }

}
  • Singleton<T> を継承したクラスを作るだけです。
  • <T> には作成するクラスをそのまま用います。

License

Copyright (c) 2017 Tetsuya Mori

Released under the MIT license, see LICENSE.txt