---
title: "研究Unity引擎的技巧"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/unity-engine-research-tips/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/05-游戏图形与运行时/Unity/研究Unity引擎的技巧.md"
content_hash: a25bc5dbfd1371caccd838a8e268b453cc78a8b3e3739089b784b3fde0115bfd
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# 研究Unity引擎的技巧

> 创建时间：2020/6/4 11:12

参考:
https://www.xuanyusong.com/archives/4263（获取资源内存和硬盘大小)

Unity Editor实现的一些功能，调用了Editor本身的一些函数。这些函数可能没有作为API提供出来。如果想要调用，可以看Editor的源码：用dnSpy反编译一下，找到相关的代码与函数。
然后利用反射，根据函数名调用相应函数。

此外，该方法提供了一个思路：想要深入理解UnityEditor的实现，就多看看Editor的包文件，反编译看看源码。一个是顺藤摸瓜，看相应功能的实现。一个是看包的整体结构组织，了解各个模块的功能以及实现，理解模块之间的关系。
d
一个小工具（用来调用内部函数）：

```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```
```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```

## 监听Unity编辑器关闭的事件

```csharp
class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

```
