顯示具有 C# 標籤的文章。 顯示所有文章
顯示具有 C# 標籤的文章。 顯示所有文章

2016年9月11日 星期日

JetBrains Project Rider with Unity

JetBrains 針對 C# 做了一個 IDE 叫 Project Rider。用 Unity 一定會用到 C#,是有 MonoDevelop 可以用,它的幾個不可思議的 bugs 也可以容忍,但...。反正用過 Intellij IDEA 和 Android Studio 的人,一定會知道 JetBrains  IDE 的價值在哪。


雖然 Project Rider 支援 C#,但要給 Unity 用,要動點手腳。這裡就是我的幾個步驟。
  1. 現在有 Project Rider  EAP 可以抓。可能會要你填問卷。填完後,去你的信箱找下載網址。點兩下 .exe 安裝,記住裝在哪裡。
  2. 接下來,抓這個 plugin。這是 JetBrains 做給 Unity3D Editor 用的。把裡面的
    /Assets/Plugins/Editor/RiderUnityIntegration.cs
    複製到
    Unity project 的 /Assets/Plugins/Editor。需要時自己建目錄。
  3. 為了可以在 Unity 中點兩下 .cs 就開啟 Project Rider,還要在 Unity 改設定:
    Edit->Preferences ->External Tools-> Browse -> 找你安裝的 Rider.exe。


就是把 plugin 複製到這地方




打開畫面。一貫的 JetBrains IDE 風格





More:
  • 開啟第一個 .cs 時,Project Rider 會花點時間。
  • 以後每個 Unity Project,都要記得複製 RiderUnityIntegration.cs 進來。不用擔心會有影響,因為 plugin 是放在 Editor 目錄下,編譯成 target 時,會被 Unity 自動排除。
  • 開不同的 Unity Project 時,最好先把上次的 Project Rider 關閉。


2016年5月24日 星期二

C# script template in Unity

新建 C# script 時,Unity 會很貼心幫你補上Update()、Start()、註解:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class MainPlayer : MonoBehaviour {
 5 
 6     // Use this for initialization
 7     void Start () {
 8 
 9     }
10 
11     // Update is called once per frame
12     void Update () {
13 
14     }
15 }


剛開始很方便,但不必超過5次,你就會覺得很煩,因為你每次都要砍掉註解,或是根本不需要 Start()/Update()。有這種困擾的話,可以去改一下 template:

$(UNITY_FOLDER)\Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviourScript.cs.txt

我自己有在用 doxygen, 加上懶得一一補上 import,所以常用的 libs 都先寫了,看起來像這樣:
 1 namespace ThisGame
 2 {
 3   using UnityEngine;
 4   using UnityEngine.UI;
 5   using System.Collections;
 6   using System.Collections.Generic;
 7   using System;
 8   using Random = UnityEngine.Random;
 9 
10   using UnityEngine.Events;
11   using UnityEngine.EventSystems;
12 
13   /**
14    * @brief #SCRIPTNAME#
15    *
16    *
17    */
18   public class #SCRIPTNAME# : MonoBehaviour
19   {
20 
21   }
22 }