美文网首页Unity程序员简宝玉分享会日更写作打卡
Unity 3D 开发《王者荣耀》:Hello World

Unity 3D 开发《王者荣耀》:Hello World

作者: iOSDevLog | 来源:发表于2018-05-22 22:46 被阅读0次

    Unity 安装


    Unity 官方网站:https://unity3d.com

    点击右上角的 获取Unity

    系统要求

    OS: Windows 7 SP1+, 8, 10, 64-bit versions only; Mac OS X 10.9+.
    GPU:有DX9(着色器模型2.0)功能的显卡。2004年以来的产品应该都可以。

    版本

    Unity 2018.1.1f1: https://unity3d.com/cn/unity/whatsnew/unity-2018.1.1

    默认安装即可。

    登录 Unity 账户,我有一个 Unity 线下活动中的一年 Unity Plus with Unity Teams Advanced

    • ¥2,880.00/year

    再不用就浪费了。555

    Key.png

    《王者荣耀》 App Store 英文名称是 《Arena of Valor》

    Arena of Valor

    Visual Studio 设置

    • 代码格式化(自动对齐):(三个键同时按下)

    Windows

    Ctrl+K+D
    

    macOS

    ^ + I
    
    • Tab(制表符) 转 4 个 Space (空格)
    Tab.png

    在 Camera 上面添加 C# 脚本。

    Hello World


    https://zh.m.wikipedia.org/zh-sg/Hello_World

    Hello, World是指在电脑屏幕显示“Hello, World!”(你好,世界!)字符串的计算机程序。相关的程序通常都是每种电脑编程语言最基本、最简单的程序,也会用作示范一个编程语言如何运作[1]。同时它亦可以用来确认一个编程语言的编译器、程序开发环境及运行环境是否已经安装妥当。因为写法简单可见,这也是很多初学者首次接触编程语言时会撰写的程序。

    传统用途

    传统来说,当一位程序员接触一门新的编程语言的时候,“Hello, World”就会成为首个接触的内容。

    与此同时,相同的字符串亦会用作检测开发环境是否安装妥当以及相关的操作人员是否理解相关的环境。

    历史

    于1972年,Bear实验室成员布莱恩·柯林汉撰写的内部技术文件《A Tutorial Introduction to the Language B》首次提到了Hello World这字符串。当时,他使用B语言撰写了第一个使用参数的Hello World相关程序:

    main(){
      extrn a,b,c;
      putchar(a); putchar(b); putchar(c); putchar('!*n');
      }
    
    a 'hell';
    b 'o, w';
    c 'orld';
    

    由 布莱恩·柯林汉 撰写的“Hello, world”程序 (1978年)
    这个程序成为了第一个Hello World的示范程序。之所以会这样切割,是因为于B语言中,每个参数只能放置四个ASCII字符[5]。两年后,布莱恩·柯林汉和丹尼斯·里奇基于B语言写成C语言后,在他们撰写的《C程序设计语言》使用更简单的方式展示Hello World:

    #include <stdio.h>
    
    main( )
    {
            printf("hello, world\n");
    }
    

    自此,Hello World成为了电脑程序员学习新的编程语言的传统[6]。但是,有些人认为 hello, world 的字符串早于1966年的BCPL语言出现的时候已经出现[7]。虽然相关的字词确实在发明者记录的文件出现,但是可以肯定的是,Hello World这字符串于当时确实未变得流行。因此,人们公认为布莱恩·柯林汉是令相关字符串走进公众目光的人。

    但是需要注意的是,Hello World的初始写法为“hello, world”,并没有任何感叹号,全部都是小写,内含逗号,后面亦有空格,而和现在流行的写法并不一致。

    Unity 中的 Hello World

    VS.png
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class HelloWorld : MonoBehaviour
    {
    
        // Use this for initialization
        void Start()
        {
            print("Hello, World!");
        }
    
        // Update is called once per frame
        void Update()
        {
            Debug.Log("hello, world");
        }
    }
    

    print vs Debug.Log 区别

    .NET Decompiler  .NET反编译器 ILSpy: https://github.com/icsharpcode/ILSpy

    • vs 中查看 print 定义
    print.png
    • 找到 dll 路径
    #region 程序集 UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    // C:\Program Files\Unity\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
    #endregion
    
    VS_print.png
    • ILSpy 打开 dll 搜索 print 方法之后 Ctrl + 点击 Debug.log
    ILSpy_print.png
    // UnityEngine.MonoBehaviour
    /// <summary>
    ///   <para>Logs message to the Unity Console (identical to Debug.Log).</para>
    /// </summary>
    /// <param name="message"></param>
    public static void print(object message)
    {
        Debug.Log(message);
    }
    
    • ILSpy 查看 Debug.log 方法
    ILSpy_Debug.log.png
    // UnityEngine.Debug
    /// <summary>
    ///   <para>Logs message to the Unity Console.</para>
    /// </summary>
    /// <param name="message">String or object to be converted to string representation for display.</param>
    /// <param name="context">Object to which the message applies.</param>
    public static void Log(object message)
    {
        unityLogger.Log(LogType.Log, message);
    }
    

    在学习或使用 Unity 的时候,就会遇到调试的问题,在 Unity 3d 中调试比较麻烦,不像在vs中可以直接设置断点来调,所以选择打印消息的方式来调试。

    但是打印消息也有几种方式,一种的 Print,一种的 Debug.Log 等。

    PrintMonoBehaviour 的一个成员。

    Debug 则是一个密闭的类。
    所以在使用的范围上,Print 必须要继承 MonoBehaviour 类,而 Debug 不用。

    在 ILSpy 中反编译 UnityEngine.CoreModule.dll 这个 DLL 会发现 Print 方法的实现其实非常简单。

    结论:Print 就是 Debug.Log 的一个简单封装。实现就是通过Debug.Log来完成的。

    运行

    Run.png

    GitHub for Unity: https://unity.github.com/

    GitHub for Unity 是一款将 unity 发布到 GitHub 的扩展插件。

    今天刚刚发布了 1.0 版本。

    GitHub for Unity

    If the current Unity project is not in a Git repository, the GitHub for Unity extension will offer to initialize the repository for you. This will:

    • Initialize a git repository at the Unity project root via git init 初始化 git
    • Initialize git-lfs via git lfs install 安装 git-lfs 和 git lfs
    • Set up a .gitignore file at the Unity project root. 添加 .gitignore 到 Unity 项目根目录
    • Set up a .gitattributes file at the Unity project root with a large list of known binary filetypes (images, audio, etc) that should be tracked by LFS 添加 .gitattributes 文件过滤 大文件
    • Configure the project to serialize meta files as text 设置 meta
    • Create an initial commit with the .gitignore and .gitattributes file. 初始化提交包括 .gitignore and .gitattributes 在内的文件

    Publish a new repository

    1. Go to github.com and create a new empty repository - do not add a license, readme or other files during the creation process. 去 github.com 创建一个空的仓库。
    github.png
    1. Copy the https URL shown in the creation page 拷贝 https URL。
    2. In Unity, go to Windows -> GitHub -> Settings and paste the url into the Remote textbox. 在 Unity 中添加远程仓库。
    3. Click Save repository. 保存。
    remote.png
    1. Go to the History tab and click Push. 推送到 github.com

    issus: Push 按钮是灰色的,不能点击

    用命令行工具上传

    $ git push -u origin master
    

    GitHub for Unity 链接: https://pan.baidu.com/s/1atsoakxUFDDbFcSlIme1qw 密码: ytsv

    明天加载地图,控制英雄运动。

    简宝玉写作群日更打卡第 32 天

    相关文章

      网友评论

        本文标题:Unity 3D 开发《王者荣耀》:Hello World

        本文链接:https://www.haomeiwen.com/subject/kibhjftx.html