zoukankan      html  css  js  c++  java
  • Unity3D脚本行尾(Line Endings)

    行尾不一致(inconsistent line endings )

    开发环境

    有时候编辑Unity的脚本文件,代码diff之后,或者从svn更新文件之后,Unity中会出现行尾不一致的信息。

    我的开发环境如下:

    visual studio 2015,unity3d 5.x,beyond compare 4,notepad++ 6.x

    windows 7/10

    行尾不一致

    当Unity在编译时,如果脚本的行尾不一致,会出现以下提示信息:

    There are inconsistent line endings in the 'someFileName.cs' script. Some are Mac OS X (UNIX)

    and some are Windows.This might lead to incorrect line numbers in stacktraces and compiler

    errors. Unitron and other text editors can fix this using Convert Line Endings menu commands.

    产生原因

    ​ 这是由Windows和Unix不同的标准引起的,即“回车”和“换行”的问题。“回车”和“换行”是ASCII

    字符集中两个不可见的控制符。“回车”就是CHAR(13),即 ;“换行”就是CHAR(10),即 。至于“回

    车”和“换行”是来源于打字机,没见过打字机或没见过DOS时代的光标恐怕不好理解,因为GUI时代光

    标都是自由移动的不再有回车的意义。

    ​ 在Unix中“回车”不换行,“换行”才换行,行尾只需要一个“换行”,而在Windows中,“回 车”和“换

    行”都换行,“回车”+“换行”才是行尾,所以符合Windows开发标准的文本编辑器才会提醒你当前编辑

    的文本不符合Windows行尾标准。

    Unix和Windows行尾

    Unix平台: 行尾'LF'

    Windows平台: 行尾‘CRLF’

    CR回车(
    ) LF换行(
    ) Windows/Dos CRLF 
    
    Linux/Unix LF 
    
    MacOS CR 
    

    解决办法

    unity中创建的新脚本的默认行尾是LF,而visual studio中创建的新文件中默认行尾为CRLF,需要统一文件的行尾

    统一为LF(Unix)

    Visual Studio插件:Strip'em Add-in for Visual Studio

    官网:http://www.grebulon.com/software/stripem.php

    这个插件当你在Visual Studio中保存文本时自动转换文件的格式,对你在Windows和Unix环境中混合工作时非常有用的。

    在Unix中,文本文件的行结束是换行字符,在Windows中——一个回车和换行。

    这个插件确保文件将被保存你所希望的方式。  

    它支持行尾(EOL)转换到Unix,Windows或旧的Mac约定。

    统一为CRLF(Windwos)

    1. 打开Unity安装目录(*C:Program FilesUnityEditorDataResourcesScriptTemplates*)
    2. 找到Unity新建文件的模板文件(xx.txt),有规律的txt文件
    3. 用visual studio 打开这些文件,在文件 - 高级保存选项 - 行尾 选择 window(CRLF)

    以Unity 5.3.5为例,新建文件的模板文件如下:

    • 81-C# Script-NewBehaviourScript.cs.txt
    • 83-Editor Test C# Script-NewEditorTest.cs.txt
    • 86-C# Script-NewStateMachineBehaviourScript.cs.txt
    • 86-C# Script-NewSubStateMachineBehaviourScript.cs.txt
    • 83-Shader__Standard Surface Shader-NewSurfaceShader.shader.txt
    • 84-Shader__Unlit Shader-NewUnlitShader.shader.txt
    • 90-Shader__Compute Shader-NewComputeShader.compute.txt
    • 82-Javascript-NewBehaviourScript.js.txt
    • 85-Shader__Image Effect Shader-NewImageEffectShader.shader.txt

    参考资料

    https://www.reddit.com/r/Unity3D/comments/3dl8oz/psa_how_to_fix_line_endings_in_unity_for_windows/

    http://forum.unity3d.com/threads/inconsistent-line-endings.40671/

    http://www.cnblogs.com/sevenyuan/archive/2012/12/06/2805114.html

  • 相关阅读:
    消息分发
    subprocess.CalledProcessError: Command ‘(‘lsb_release’, ‘-a’)’ returned non-zero exit status 1.
    ubuntu14.04 安装python3.7
    通过shell脚本查看python版本并比较
    shell 小数比较大小
    python 私有方法
    python 类的倒入
    python 路径拼接
    python 脚本接受参数
    python 获取文件运行路径
  • 原文地址:https://www.cnblogs.com/zhaoqingqing/p/5883005.html
Copyright © 2011-2022 走看看