0%

VS Code is an amazing code editor, which contains various extensions and support multi-languages.

Basic Skills

  • Use Ctrl+Shift+P to open the VSCode command center to input command
  • Use command center and type Open settings(JSON) to edit the VS Code settings
  • Some useful keyboard shortcuts

C#

In order to use VS Code for the C# programming, we need to install

  • .NET Core
  • C# Extension in VS Code

Then open a folder with VS Code, and use the terminal to type dotnet new console to establish a new console project.

Then the VS Code will automatically generate some files and new a Program.cs script.

Go to Dubug-Start without Debuging, VS Code will add the required assets to the project(or press ctrl+shift+p and type .net: Generate Assets for Build and Debug), and open a launch.json file for user to configure some settings of the C# project. Make sure the version of netcore is right. Then cick the Start without Debuging again, the program will run.

Python

For Python, we need to install

  • Python interpreter
  • Python Extension in VS Code

Open a folder and add a python file. Then press ctrl+shift+p to open the command and type Python: select interpreter to choose the python interpreter. Then go to Debug-Start without Debuging to run the code.

LaTex

In order to use Latex, we need to install

  • Tex Environment, like Tex Live
  • Latex Workshop Extension for VS Code

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

Refer a local page

  • See this post
  • See this section in this page
  • See this part on another page

Insert image

Tabs

This is Tab 1.
Text xxx

This is Tab 2.

This is Tab 3.

Note

No folding

title

With folding

Basic Skills

  • Usually set the values of private values in the Start() function.
  • Only gameObject has the function of GetComponent
  • Transform
    • Only transform has the function of Find(string name)
    • The function of Find(string name) for a transform can only find the direct children of a transform

Physics Engine

Collider

Wheel Collider

Wheel collider is a collider rather than the mesh of the wheel. You can add force or torque to the collider to make the collider rotate like a wheel.

Rigidbody

Rigidbody has a element named velocity, which can set the speed(Vector3) of the gameobject.

Detect collision or collision position between objects

  • Use OnCollisionEnter or OnTriggerEnter
    • Required object to have collider and rigidbody
  • Use Physics.OverlapSphere(point) to detect whether the point collides with other colliders.
  • Use Collider.Raycast to get the accurate collision position. It will ignore other colliders but this collider.

Scripting

Find Objects

  • Use transform.root.gameObject can find the root object
  • Use gameObject.GetComponentInChild() can find the script attached to the child objects.
  • Use transform.Find() can find the children objects, but this is only used to find the direct children objects.

Attributes

Attributes of C# can add metadata (information about the types defined in a program) to the program. In Unity, it can be used to show information in Unity editor’s inspector.

The attributes work by placing the name of the attribute enclosed in square brackets ([]) above the declaration of the entity to which it applies. There are several different attributes in Unity

Name Function
HideInInspector Hide public parameter in Unity Inspector
SerializeField Show the private parameter in Unity Inspector
Space Show a space line in Unity Inspector
Header(“XX”) Show a comment for the parameter in Unity Inspector
Range(min, max) Show the value range in Unity Inspector

Asynchronous

Unity can use async/await keywords of C# to achieve asynchronous methods, which can be found here.

However, some Unity library functions cannot be executed correctly in the asynchronous thread. Instead, Unity has its own asynchronous keyword, which is IEnumerator/yield return.

yield return keyword has many kinds of return type, which shows following

Type Function
yield return new WaitForEndofFrame() Wait until the end of current frame
yield return new WaitForFixedFrame() Wait until next frame
yield return new WaitForSeconds(xx) Wait for xx seconds
yield return new WaitForWhile(func) Wait until func return false
yield return new WaitForUntil(func) Wait until func return true

In Unity scripts, sometimes we need to do some actions after changing the properties of the GameObject, e.g. position, rotation. Unity will finish the changing action in the end of current frame. So we need to wait for a while before doing other actions.

Note. the event of delegate trigger is also finished in the current frame.

Also in Unity, we need to use yield return null or allow the code return to the main thread to do some changes in the scene.

Note. don’t use yield return 0 because it is the same with yield return null but it will lead to boxing action.

Compile

Conditional Compile

Unity has many targeted platforms, so the codes can be conditional complied according to this link

Compile Pipeline

  • Unity will compile C# scripts to IL with C# compiler firstly
  • Unity will also combines all the other assemblies like the UnityEngine.dll and mscorlib.dll
  • Unity will use Mono or IL2CPP to build the IL scripts to naive code

Git is a powerful version management system. This posts captures the common used commands.

Read more »