SpriteAtlasManager
命名空間:UnityEngine.U2D
描述:
在運行時管理SpriteAtlas
可以在不引用任何Sprite Atlas
的情況下加載Sprite
,這樣的結果是沒有紋理。在用戶通過監聽SpriteAtlasManager.atlasRequested
回調將圖集注冊到Sprite
之前,它將是不可見的。觸發時,它將傳入atlas tag
和System.Action
,它將接收一個atlas對象.
事件:
事件 | 描述 |
---|---|
atlasRegistered | SpriteAtlasManager.atlasRequested中調用回調來注冊SpriteAtlas時觸發 |
atlasRequested | 當任何Sprite綁定到SpriteAtlas但在運行時無法找到atlas asset 時觸發。 |
使用時發現的細節:
altasRequested
是在Start
之后調用,即在即將顯示的時候,atlasRegistered
是在altasRequested
使用回調后調用.
altasRequested
即使該精靈綁定的sprite atlas
已經存在,還是會觸發該事件.
另外還發現了一個Unitybug,??
操作符有bug在2018.4.8版本中
public class Test : MonoBehaviour
{
public Text Text; // text已序列化
public Font Font;// null
void Start()
{
Text.font = Font == null ? Text.font : Font; // 正確.text.font 沒改變
//Text.font = Font ?? Text.font; // 錯誤.text.font會變成null,但這個寫法是上面的簡化版本
}
// Update is called once per frame
void Update()
{
}
}
bug的QA反饋,說是沒有重載??
操作符,所以以后還是得注意不能對Unity.Object
使用??
操作符。
Hi,
Thank you for contacting us about your issue.
Such behavior is expected. Null objects in Unity are not equal to null from the C# perspective, therefore, you get such results. The other line works correctly because it uses '==' operator, which is overloaded in Unity to make Unity null equal to C# null. There is no such overload for '??' operator, so you get Text.font set to null.
這段時間,一直都比較忙,沒多少時間寫博客學習東西,不斷地在人生的漩渦中掙扎,不知這樣是否真的會改變什么...