Other中的几个类

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返回指定路径字符串的文件基本组件,不含扩展名。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值