UnityEngine
UnityEditor
Other
Other 中,几个类
Array、Hashtable、NonSerializable、Path、Serializable、String
应该来说,不是unity自身的,而是在这里单独说明而已。
Serializable
标记一个类
当需要一个类继承 System.Object ,然后其中有一些可序列化属性
通常用于一个数据类,要想在被实例化的时候能够在 Inspector中显示
//试过了,如果没有标记为可序列化,那么是不会在Inspector中显示的
//至于要不要继承 System.Object ,貌似没什么影响
using UnityEngine;
[System.Serializable]
class Test : System.Object
{
public int p = 5;
public Color c = Color.white;
}
public class Another : MonoBehaviour
{
//此时,这个属性就会在Inspector中显示为一个带折叠符号的属性,可以显示子属性
public Test test;
}
NonSerializable
标记一个属性
通过这个可以保持一个属性为public,但是不想序列化或者不想显示在Inspector中
class Test
{
// p will not be shown in the inspector or serialized
[System.NonSerialized]
public int p = 5;
}
String
在C#中,string 是 System.String 的别名,
这个string不需要引用 System 命名空间,但 String 需要
关于String类,还是有必要重新看看它的一些特殊用法。以后写一篇总结。
Array
Note: Unity doesn’t support serialization of a List of Lists, nor an Array of Arrays.
unity中有两种 Array
There are two types of arrays in Unity, builtin arrays and normal Javascript Arrays.
Builtin arrays (native .NET arrays), are extremely fast and efficient but they can not be resized.
System 命名空间下
public abstract class Array : ICloneable, IList, ICollection, IEnumerable { ... }
Array类 | 内容 |
---|---|
属性 | length |
构造函数 | Array |
公有方法 | Add Clear Concat Join Pop Push RemoveAt Shift Sort Unshift |
Hashtable
可以使用 Hashtable 存储 键值对
C#中,通用的代替方案是用 Dictionary
Hashtable | 说明 |
---|---|
属性 | Count |
公有方法 | Add、Clear、Contains、ContainsKey、ContainsValue、Remove |
Path
对包含文件或目录路径信息的字符串执行操作。
这是标准库System.IO.Path类。为了方便您,这里提供了常用类成员的文档。
Path 属性 | 说明 |
---|---|
AltDirectorySeparatorChar | 用于分隔目录级别的备用字符。 (只读) |
DirectorySeparatorChar | 用于分隔目录级别的默认字符。 (只读) |
公有方法 | 说明 |
---|---|
Combine | 连接两个路径字符串。 |
GetDirectoryName | 返回指定路径字符串的目录名称组件。 |
GetExtension | 返回指定路径字符串的扩展组件。 |
GetFileName | 返回指定路径字符串的文件名,包括扩展名(如果有)。 |
GetFileNameWithoutExtension | 返回指定路径字符串的文件基本组件,不含扩展名。 |