Unity手册SpriteAtlasManager翻译

SpriteAtlasManager

命名空间:UnityEngine.U2D

描述:
在运行时管理SpriteAtlas
可以在不引用任何Sprite Atlas的情况下加载Sprite,这样的结果是没有纹理。在用户通过监听SpriteAtlasManager.atlasRequested回调将图集注册到Sprite之前,它将是不可见的。触发时,它将传入atlas tagSystem.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.


这段时间,一直都比较忙,没多少时间写博客学习东西,不断地在人生的漩涡中挣扎,不知这样是否真的会改变什么...

原文地址:https://www.cnblogs.com/Fallever/p/11482848.html