C# unity 中实现类的单例比较好的做法

2016-1-19 雨辰 C#

继承自Singleton 即可实现一个单例的类
using UnityEngine;
using System.Collections;

namespace DMGame
{
    public class Singleton<T> where T : class, new()
    {
        protected static T _instance = default(T);

        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new T();
                }
                return _instance;
            }
        }

        public static void Reset()
        {
            _instance = null;
        }
    }

    public class SystemBasis<T> where T : class, new()
    {
        public static T Instance { get { return Singleton<T>.Instance; } }
        public virtual void Init() { }
        public virtual void Update() { }
        public virtual void LateUpdate() { }
        public virtual void Reset() { }
        public virtual void Release() { }

        public virtual void OnAppQuit() { }
        public virtual void OnAppPause(bool pause) { }
        public virtual void OnAppFocus(bool focus) { }
    }
}

标签: Unity3D C#

评论:

radassure
2021-06-03 11:31
<a href="https://www.kozetgyapotar.com/pineapple-canvas-torba-torebkid">pineapple canvas torba</a> <a href="https://www.deeztailz.com/urban-queen-phone-case-casec">urban queen phone case</a> <a href="https://www.tabcruncher.com/fat-face-small-buckle-tote-zak-tassenb">fat face small buckle tote zak</a> <a href="https://www.accentskosher.com/iphone-clear-silicone-pouzdro-pouzdroe">iphone clear silicone pouzdro</a> <a href="https://www.kinocinemovie.com/quiz-zelen%C3%A1-velvet-wrap-%C5%A1aty-satyc">quiz zelen谩 velvet wrap 拧aty</a> <a href="https://www.doulaprograms.com/59fifty-custom-cappelli-cappelloa">59fifty custom cappelli</a>
radassure https://www.radassure.com/
demstrup
2021-05-25 03:29
<a href="http://www.utahmiataclub.com/create-your-own-iphone-7-plus-sag-saga">create your own iphone 7 plus sag</a> <a href="http://www.martianprince.com/wszystko-czarny-balenciaga-triple-s-tenisc">wszystko czarny balenciaga triple s</a> <a href="http://www.adatogeljitu.com/svart-turtleneck-under-kjole-kjoleb">svart turtleneck under kjole</a> <a href="http://www.jgbello.com/topshop-marissa-tasche-tasched">topshop marissa tasche</a> <a href="http://www.servicioshost.com/felpa-psg-nera-tutab">felpa psg nera</a> <a href="http://www.gobarnstorm.com/air-max-97-blanc-et-gray-chaussures1">air max 97 blanc et gray</a>
demstrup http://www.demstrup.com/
buyinaustintx
2021-05-23 18:54
<a href="https://www.masessamd.com/yankees-berretto-rosso-cappelloa">yankees berretto rosso</a> <a href="https://www.optisaurus.com/black-non-slip-polishable-shoes-bootsa">black non slip polishable shoes</a> <a href="https://www.skylineblade.com/hausschuhe-21-junge-stiefeld">hausschuhe 21 junge</a> <a href="https://www.xlbutt.com/oneplus-6-plastic-hoesje-hoesjea">oneplus 6 plastic hoesje</a> <a href="https://www.mayepmuncua.com/limited-nike-aqua-green-mens-matt-haack-alternate-jersey-nfl-2-miami-dolphins-vapor-untouchable-jerseyc">limited nike aqua green mens matt haack alternate jersey nfl 2 miami dolphins vapor untouchable</a> <a href="https://www.gototagaytay.com/m%C4%99skie-holdall-weekend-torba-torebkid">m臋skie holdall weekend torba</a>
buyinaustintx https://www.buyinaustintx.com/
owneriqnet
2021-05-22 08:20
<a href="http://www.joshwoodward.net/into-the-spider-verse-phone-hoesje-hoesjea">into the spider verse phone hoesje</a> <a href="http://www.zicklincenter.net/nike-limited-kj-wright-jersey-50-nfl-seattle-seahawks-player-name-number-tank-top-mens-navy-blue-jerseyc">nike limited kj wright jersey 50 nfl seattle seahawks player name number tank top mens navy blue</a> <a href="http://www.lernfest.net/czarny-quilted-belt-torba-torebkid">czarny quilted belt torba</a> <a href="http://www.historead.net/astroworld-iphone-xr-case-casec">astroworld iphone xr case</a> <a href="http://www.glfusion.net/faux-fur-chain-zak-tassenb">faux fur chain zak</a> <a href="http://www.jodisolomon.net/marble-phone-pouzdro-iphone-xr-pouzdroe">marble phone pouzdro iphone xr</a>
owneriqnet http://www.owneriqnet.net/
alivres
2021-05-04 04:15
<a href="http://www.haeshop.net/kryt-samsung-s4-galaxy-pouzdroe">kryt samsung s4 galaxy</a> <a href="http://www.externateam.net/adicolor-cotton-bodycon-%C5%A1aty-satyc">adicolor cotton bodycon 拧aty</a> <a href="http://www.hcrecruiters.net/detroit-tigers-new-era-mlb-core-classic-39thirty-berretto-cappelloa">detroit tigers new era mlb core classic 39thirty berretto</a> <a href="http://www.riskoffall.net/leopard-print-peep-toe-booties-bootsa">leopard print peep toe booties</a> <a href="http://www.josephjackson.net/schwarze-schn%C3%BCrboots-stiefeld">schwarze schn眉rboots</a> <a href="http://www.brekkestranda.net/nokia-8-bumper-hoesje-hoesjea">nokia 8 bumper hoesje</a>
alivres http://www.alivres.net/
luzudu
2021-05-01 20:59
<a href="http://www.aliseofoods.com/magpul-field-sag-iphone-8-saga">magpul field sag iphone 8</a> <a href="http://www.demstrup.com/p%C3%B3%C5%82buty-damskie-41-tenisc">p贸艂buty damskie 41</a> <a href="http://www.polymeur.com/gr%C3%B8nn-og-gull-lace-kjole-kjoleb">gr酶nn og gull lace kjole</a> <a href="http://www.vanitetown.com/new-it-tasche-2019-tasched">new it tasche 2019</a> <a href="http://www.meetmeatax.com/vestito-adidas-verde-tutab">vestito adidas verde</a> <a href="http://www.graphilactic.com/blanc-air-max-97-triple-blanc-chaussures1">blanc air max 97 triple blanc</a>
[url=http://www.luzudu.com/]luzudu[/url]
librify
2021-04-29 21:40
<a href="http://www.joshwoodward.net/%C4%8Dern%C3%A1-linen-pinafore-%C5%A1aty-satyc">膷ern谩 linen pinafore 拧aty</a> <a href="http://www.zicklincenter.net/miami-dolphins-new-era-nfl-basso-profile-draft-59fifty-berretto-cappelloa">miami dolphins new era nfl basso profile draft 59fifty berretto</a> <a href="http://www.lernfest.net/merrell-waterproof-hiking-shoes-womens-bootsa">merrell waterproof hiking shoes womens</a> <a href="http://www.historead.net/silber-medium-abs%C3%A4tze-stiefeld">silber medium abs盲tze</a> <a href="http://www.glfusion.net/lilo-en-stitch-iphone-7-plus-hoesje-hoesjea">lilo en stitch iphone 7 plus hoesje</a> <a href="http://www.jodisolomon.net/turkey-9-tosun-away-soccer-country-jersey-jerseyc">turkey 9 tosun away soccer country jersey</a>
librify http://www.librify.net/

发表评论:

朱文华 joyimp|@2011-2021 京ICP备16030765号-2