[Unity]Unity2018.4的Prefab Variant(Prefab变种)功能

2019/09 01 17:09

Unity 2018.4中送了一个新的功能: Prefab Variant

思路是, Prefab Variant 继承于一个父Prefab, 父Prefab属性修改后:

(1)如果子Prefab的某些属性不动, 则父Prefab的属性影响子Prefab的属性, 此为 [属性继承]

(2)如果对子Prefab的某些属性进行修改/覆盖, 则父Prefab的属性无法影响, 此为 [属性定制]

创建Prefab Variant的方法为: 把Prefab从Hierarchy再次拉到Project中,选择 Prefab Variant

用处举例:

比如做一个UGUI窗体模板, 上面有标题文字和关闭按钮

邮件窗体继承于此窗体模板,制作成为一个PrefabVariant, 但是标题文字定制修改为”邮件”

这时,可以通过修改窗体模板中的关闭按钮,对所有派生的窗体按钮进行修改

附:以下为官方对PrefabAssetType的解释:


    public enum PrefabAssetType
    {
 
        //
        // 摘要:
        //     The object being queried is not part of a Prefab at all.
        NotAPrefab = 0, // 不是Prefab
 
        //
        // 摘要:
        //     The object being queried is part of a regular Prefab.
        Regular = 1, // 常规的Prefab
 
        //
        // 摘要:
        //     The object being queried is part of a Model Prefab.
        Model = 2, // 模型(例如:FBX)
 
        //
        // 摘要:
        // The object being queried is part of a Prefab Variant.
        // A Variant Prefab is a Prefab that is derived from another Prefab, 
        // that be could be a Regular, Model or even Variant Prefab.
        Variant = 3, // Prefab变种
 
        //
        // 摘要:
        //     The object being queried is part of a Prefab instance, but because the asset
        //     it missing the actual type of Prefab can’t be determined.
        MissingAsset = 4 // Prefab实例化出来的对象,但是Prefab被删了(红色)
    }