原文鏈接:https://github.com/hardlydifficult/Tutorials/blob/master/Platformer/C1.md
1) Project Setup
1.3) Configure Sprites
What's mesh type / full rect?
When a sprite is rendered to the screen, a combination of a mesh (like that used for 3D objects) outlining the sprite and transparency is used to draw the picture on-screen. Tradeoffs here are beyond the scope of this tutorial.
當(dāng)在屏幕上渲染精靈時(shí),(像在3D物體上使用那樣)用來描繪精靈的輪廓的mesh(網(wǎng)格)與透明度的組合被用來在屏幕上繪制圖像。這之間的折中(Tradeoffs )超出了本教程的范圍。
Tight will attempt to better outline the sprite, using more polygons in the mesh.
Tight(緊密的)將嘗試在mesh中使用更多的多邊形,以便獲得更好的精靈的輪廓
Full Rect will use 2 triangles per sprite.
Full Rect 將在每個(gè)精靈上使用兩個(gè)三角形
When using tiling on a sprite, Unity recommends updating the sprite sheet to use 'Full Rect'. I don't have an example of issues that may arise from using 'Tight' instead, but here is the warning from Unity recommending 'Full Rect':
當(dāng)在一個(gè)精靈上使用tiling(瓦片)時(shí),Unity推薦使用 'Full Rect'。我不知道使用'Tight' 會(huì)有什么問題,但Unity推薦使用'Full Rect',下面是它的警告:

What's filter mode / point?
Using Point filter mode gets us closer to pixel-perfect sprites and prevents some visual glitches.
使用Point濾鏡模式讓我們獲得更完美的精靈,防止產(chǎn)生一些視覺瑕疵。
Filter mode of Bilinear or Trilinear blurs the image a bit in attempt to make smooth lines. Often for a 2D game, we want control down to the pixel and this effect is not desirable. Here's an example with the character sprite we will be using:
Bilinear或Trilinear的濾鏡模式會(huì)對(duì)圖像進(jìn)行少許的模糊處理來平滑線條。通常在2D游戲中,我們希望控制獲得像素級(jí)控制,這種效果不滿足需求。下面是我們將使用的精靈的例子:

For sprite sheets, each object is often touching the one next to it. Filter Mode Point prevents blending between one sprite and its neighbor. The blending that occurs with other modes besides Point may lead to random lines showing up on-screen. For example:
對(duì)于精靈瓦片,每個(gè)對(duì)象常常與另一個(gè)接觸。Point濾鏡模式防止兩個(gè)相鄰精靈間的混合。除Point之外的其他模式的混合可能會(huì)導(dǎo)致隨機(jī)線出現(xiàn)在屏幕上。例如:

1.6) Auto Save Script
using UnityEditor;
using UnityEditor.SceneManagement;
[InitializeOnLoad]
public class AutoSave
{
static AutoSave()
{
EditorApplication.playmodeStateChanged
+= OnPlaymodeStateChanged;
}
static void OnPlaymodeStateChanged()
{
if(EditorApplication.isPlaying == false)
{
EditorSceneManager.SaveOpenScenes();
}
}
}
This is a Unity-specific, editor-only attribute that enables the script. The static constructor of any class with this attribute is executed before anything else in the game.
這是Unity特有的,editor-only腳本屬性。具有此屬性的任何類的靜態(tài)構(gòu)造函數(shù)在游戲中的任何其他事物之前執(zhí)行。
[InitializeOnLoad]
Here we register for a Unity event which will call the method below when the game begins while in the Unity editor. This event also fires when the game is paused or stopped.
在這里,我們注冊(cè)一個(gè)Unity事件,在Unity編輯器中,當(dāng)游戲開始時(shí),將會(huì)調(diào)用下面的方法。這個(gè)事件也會(huì)在游戲暫停或停止時(shí)觸發(fā)。
We don't need to deregister the event. Occasionally, Unity will terminate and restart this script, but otherwise we always want AutoSave to be running.
我們不需要銷毀這個(gè)事件。有時(shí)Unity會(huì)終止并重新啟動(dòng)這個(gè)腳本,但是我們總是希望AutoSave運(yùn)行。
EditorApplication.playmodeStateChanged
+= OnPlaymodeStateChanged;
}
What's a C# delegate / event?
A delegate in C# is an object representing method(s) to call at a later time. You may encounter delegates under the following names: Events, Action, Func, and delegate. Under the hood, these are all implemented with a 'multicast delegate'.
C#中的委托(delegate)是表示稍后調(diào)用的方法的對(duì)象。您可能會(huì)遇到以下名稱的委托:Events,Action,F(xiàn)unc和delegate。這些都是通過“多播委托( multicast delegate)”來實(shí)現(xiàn)的。
When a method is added to a delegate to be called later, this is referred to as 'subscribing'. 'Multicast delegate' means that any number of methods may subscribe to the same delegate. We use += when subscribing so as not to overwrite any other subscribers.
當(dāng)一個(gè)方法被添加到稍后調(diào)用的委托時(shí),這被稱為“訂閱”?!岸嗖ノ小币馕吨魏螖?shù)量的方法都可以訂閱相同的委托。訂閱時(shí)使用+ =,以免覆蓋任何其他訂閱者。
EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged;
If the owner of the delegate (EditorApplication in the example above) may outlive the subscriber, the subscriber should unsubscribe when it's destroyed. Also, any time you are no longer interested in future updates, unsubscribe. We do this with -= to remove our method and leave any remaining methods subscribed.
如果委托的所有者(上例中的EditorApplication)可能比訂閱者活的更久,則訂閱者在銷毀時(shí)應(yīng)該取消訂閱。此外,任何時(shí)候你不再對(duì)將來的更新感興趣時(shí),就取消訂閱。我們用 - =來移除我們的方法,并保留其余的方法訂閱。
EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged;
Events are a common use case for delegates. For example, you may have a GameManager with a field for Points include an event "onPointsChange". Other components/systems in the game, such as Achievements and the UI, may subscribe to the onPointsChange event. When a player earns points, a method in Achievements is then called which can consider awarding a high score achievement, and a method in the UI is called to refresh what the player sees on-screen. This way, those components only need to refresh when something has changed as opposed to checking the current state each frame.
Events 是委托的常見用例。例如,您可能有一個(gè)GameManager,用文本框來記錄得分,其中包含一個(gè)事件“onPointsChange”。游戲中的其他組件/系統(tǒng)(如Achievements和UI)可能會(huì)訂閱onPointsChange事件。當(dāng)玩家獲得得分時(shí),就會(huì)調(diào)用Achievements中的一個(gè)方法,這個(gè)方法可以考慮授予高分成就,并且調(diào)用UI中的方法來刷新玩家在屏幕上看到的內(nèi)容。這樣,這些組件只需要在某些事物發(fā)生變化時(shí)刷新,而不是每幀檢查當(dāng)前狀態(tài)。
using System;
using UnityEngine;
public static class GameManager
{
public static event Action onPointsChange;
static int _points;
public static int points
{
get
{
return _points;
}
set
{
_points = value;
if(onPointsChange != null)
{
onPointsChange();
}
}
}
}
public class MyCustomComponent : MonoBehaviour
{
protected void Awake()
{
GameManager.onPointsChange
+= GameManager_onPointsChange;
}
protected void OnDestroy()
{
GameManager.onPointsChange
-= GameManager_onPointsChange;
}
void GameManager_onPointsChange()
{
// React to points changing
}
}