3.Memory Profiler Used Total: 当前帧的Unity内存、Mono内存、GfxDriver内存、Profiler内存的总和. Reserved Total:系统在当前帧的申请内存. Total System Memory Usage:当前帧的虚拟内存使用量.(通常是我们当前使用内存的1.5~3倍) GameObjects in Scene:当前帧场景中的GameObject数量. Total Objects in Scene:当前帧场景中的Object数量(除GameObject外,还有Component等). Total Object Count: Object数据 + Asset数量
4.Detail Memory Profiler Texture2d:记录当前帧内存中所使用的纹理资源情况,包括各种GameObject的纹理、天空盒纹理以及场景中所用的Lightmap资源. Scene Memory: 记录当前场景中各个方面的内存占用情况,包括GameObject、所用资源、各种组件以及GameManager等(天般情况通过AssetBundle加载的不会显示在这里). ManagedHeap.UseSize:代码在运行时造成的堆内存分配,表示上次GC到目前为止所分配的堆内存量. WebStream:这个是由WWW来进行加载的内存占用. System.ExecutableAndDlls:不同平台和不同硬件得到的值会不一样。
public class TestChild< T, S> : Test< String, int> { } 泛型方法:C#的泛型机制只支持在方法申明上包含类型参数,也即是泛型方法
1 2 3 4 5 6
public T getvalue<T>(T t) { return t; } 使用: Int a = getvalue<Int>(10);
泛型接口:
public interface IList { T[] GetElements(); } 泛型委托:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
public class MyClass<T> { public delegate void GenericDelegate(T t); public void SomeMethod(T t) { } }
public GenericMethodDemo() { MyClass<int> obj = new MyClass<int>(); MyClass<int>.GenericDelegate del; del = new MyClass<int>.GenericDelegate(obj.SomeMethod); del(3); }
public static T CreateObject(out int objectId) where T : new() public class CSingleton where T : new() 基类约束,还包括基类和接口:
public T FindControl(string name) where T : Component public class CSingleton where T : IComparable 值约束:
public class MyClass where T : struct { } 引用约束:
public class MyClass where T : class { } 约束组合:
public class MyClass where T : IComparable, new() { } public class MyClass where T : struct, IComparable { } public class MyClass where T : B, IComparable, ICloneable { } public class MyClass<T, U> where T : IComparable where U : class { } 约束 说明 T:struct 类型参数必须是值类型。可以指定除 Nullable 以外的任何值类型。与接口约束同时使用,在最前面(不能与基类约束,构造函数约束一起使用) T:class 类型参数必须是引用类型,包括任何类、接口、委托或数组类型。 T:new() 类型参数必须具有无参数的公共构造函数。当与其他约束一起使用时,new() 约束必须最后指定。 T:<基类名> 类型参数必须是指定的基类或派生自指定的基类。 T:<接口名称> 类型参数必须是指定的接口或实现指定的接口。可以指定多个接口约束。约束接口也可以是泛型的。 T:U 为 T 提供的类型参数必须是为 U 提供的参数或派生自为 U 提供的参数。这称为裸类型约束.
public GoodItem CloneItem() { MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, this); stream.Position = 0; return formatter.Deserialize(stream) as GoodItem; }
2.利用xml序列化和反序列化实现
1 2 3 4 5 6 7 8 9 10 11
public T DeepCopy<T>(T obj) { object retval; MemoryStream ms = new MemoryStream() XmlSerializer xml = new XmlSerializer(typeof(T)); xml.Serialize(ms, obj); ms.Seek(0, SeekOrigin.Begin); retval = xml.Deserialize(ms); ms.Close(); return (T)retval; }
3.利用反射实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14
public static T DeepCopy<T>(T obj) { //如果是字符串或值类型则直接返回 if (obj is string || obj.GetType().IsValueType) return obj;
属性 作用 Textture 指定要显示的图片,注意:图片类型可以是任何类型 Color 设置图片的主颜色 Material 设定Image控件的渲染材质 Raycast Target 决定是否可接收射线碰撞事件检测(取消勾选不会挡住下层UI事件) UV Rect 可以让图片的一部分显示在RawImage组件中,x、y属性用于控制UV左右、上下偏移,W、H用于控制UV的重复次数。
OnApplicationFocus is called when the application loses or gains focus. Alt-tabbing or Cmd-tabbing can take focus away from the Unity application to another desktop application. This causes the GameObjects to receive an OnApplicationFocus call with the argument set to false. When the user switches back to the Unity application, the GameObjects receive an OnApplicationFocus call with the argument set to true. hasFocus True if the GameObjects have focus, else False.