国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

unity - 餓漢單例與懶漢單例的實(shí)現(xiàn)與特性講解

2023-06-12 13:07 作者:塵風(fēng)一枚  | 我要投稿

#餓漢單例


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


/// <summary>

/// 餓漢單例

/// </summary>

public class HungryManSingleton : MonoBehaviour

{

private static HungryManSingleton Singleton;

public static HungryManSingleton Instance { get => Singleton; }


public string csName;


private void Awake()

{

if (Singleton == null)

{

Singleton = this;

}

else

{

Destroy(this.gameObject);

}

}

}


#懶漢單例


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


/// <summary>

/// 懶漢單例

/// </summary>

public class SlackerSingleton : MonoBehaviour

{

private static SlackerSingleton Singleton;

public static SlackerSingleton Instance

{

get

{

if (Singleton != null)

return Singleton;


Singleton = FindObjectOfType<SlackerSingleton>();


if (Singleton == null)

{

Singleton = new SlackerSingleton();

}

else

{

foreach (var item in FindObjectsOfType<SlackerSingleton>())

{

if (item.gameObject.GetComponent<SlackerSingleton>() != Singleton)

Destroy(item.gameObject);

}


}

return Singleton;

}

}


public string csName;

}

unity - 餓漢單例與懶漢單例的實(shí)現(xiàn)與特性講解的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
万山特区| 霞浦县| 兴业县| 奈曼旗| 福贡县| 大田县| 香河县| 福泉市| 云林县| 时尚| 海盐县| 诏安县| 阜南县| 高雄县| 靖安县| 荣昌县| 敦化市| 临沂市| 泸水县| 耒阳市| 靖远县| 高平市| 介休市| 如东县| 永定县| 泌阳县| 连平县| 凤凰县| 大新县| 丽江市| 登封市| 孟津县| 南川市| 黑龙江省| 乐都县| 新余市| 白银市| 富民县| 平陆县| 岑溪市| 隆德县|