zoukankan      html  css  js  c++  java
  • 查看Unity脚本源代码

    在Unity脚本开发中,常常使用Debug.Log或print来打印调试信息,这俩有什么区别?

     1 using System.Collections;
     2 using System.Collections.Generic;
     3 using UnityEngine;
     4 
     5 public class Rotate : MonoBehaviour {
     6     public float speed = 100.0f;
     7     // Use this for initialization
     8     void Start () {
     9         Debug.Log("Start");
    10         print("OK");
    11     }
    12     
    13     // Update is called once per frame
    14     void Update () {
    15         transform.Rotate(speed, 0, 0);
    16     }
    17 }

    在VS2017中,光标定位到print上,按F12转到定义,只能转到MonoBehavior的声明中去:
    public static void print(object message);
    可见,print是父类的一个静态方法,可以直接使用。

    此时,需要找到Unity项目下"F:DoWorkUnity3DNewUnityProjectLibraryScriptAssembliesAssembly-CSharp.dll"。
    Unity编译C#脚本生成中间语言都存在在Assembly-CSharp.dll文件中,如果以后你在网上下载一个不错的Unity工程,想看下它的脚本写的什么,就找这个文件。
    我们使用ILSpy[.NET]反编译工具,下载解压后,直接运行ILSpy.exe:
     

    将Assembly-CSharp.dll拖拽到ILSpy.exe中:

    可见,print是MonoBehaviour中的方法,鼠标单击无法跳入定义,在VS2017中F12跳转到MonoBehavior的声明:

     可见,中间语言代码在UnityEngine.dll中,将其拖入ILSpy.exe中:

    可见,print内部调用的是Debug.Log,哈哈! 

  • 相关阅读:
    数组常用函数
    数组游标操作
    PHP中 字符串 常用函数
    mysqli扩展库的预处理技术 mysqli stmt
    mysql的事务处理
    mysqli的增强功能
    mysql扩展库-1
    抽象类与接口
    iOS判断字符串是否包含表情字符
    iOS8 UITableView 分割条设置separator intent = 0 不起作用
  • 原文地址:https://www.cnblogs.com/MakeView660/p/12251775.html
Copyright © 2011-2022 走看看