SpringDragon

导航

 

  单例是一种设计模式

  单例:不管在项目中的任何模块,当需要使用某个对象的时候,获取到的始终是同一个对象  

  在C#中 

public class InstanceDemo{
	private static InstanceDemo instance;
	public static InstanceDemo GetInstance(){
		if(instance == null){
			instance = new InstanceDemo();
		}
	}
	return instance;
	private InstanceDemo(){}
}

在Unity中

public class InstanceDemo{
	public static InstanceDemo instance;
	void Avake(){
		instance = this;
	}
}

  

posted on 2017-05-05 17:37  chenquanlong  阅读(465)  评论(0编辑  收藏  举报