少年修仙传客户端基础资源
lwb
2020-12-15 72e89391ca4fc27f3b67c3fa3616f29a106317d5
9527 预制时保存剔除【自动加载的go】
1个文件已修改
29 ■■■■■ 已修改文件
Assets/Editor/Tool/PrefabHelper.cs 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/PrefabHelper.cs
@@ -1,19 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Snxxz.UI;
public class PrefabHelper
{
    [InitializeOnLoadMethod]
    static void StartInitializeOnLoadMethod()
    {
        PrefabUtility.prefabInstanceUpdated = delegate (GameObject instance)
        PrefabUtility.prefabInstanceUpdated += OnPrefabInstanceUpdate;
    }
    static void OnPrefabInstanceUpdate(GameObject instance)
        {
            var prefab = PrefabUtility.GetPrefabParent(instance) as GameObject;
            var prefabLoaders = prefab.GetComponentsInChildren<UIPrefabLoader>();
        string path = UnityEditor.PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(instance);
        var rootGO = PrefabUtility.LoadPrefabContents(path);
        var prefabLoaders = rootGO.GetComponentsInChildren<UIPrefabLoader>();
            var dirty = false;
            foreach (var loader in prefabLoaders)
            {
@@ -24,25 +26,20 @@
                    {
                        children.Add(loader.transform.GetChild(i));
                    }
                    for (int i = children.Count - 1; i >= 0; i--)
                    {
                        if (children[i].name == loader.prefabName)
                        {
                            GameObject.DestroyImmediate(children[i].gameObject, true);
                            EditorUtility.SetDirty(loader.gameObject);
                        var childGo = children[i].gameObject;
                        GameObject.DestroyImmediate(childGo, true);
                        DebugEx.LogFormat("保存预制:{0},删除了:{1}", path, loader.prefabName);
                            dirty = true;
                        }
                    }
                }
            }
            if (dirty)
            {
                AssetDatabase.SaveAssets();
            PrefabUtility.SaveAsPrefabAsset(rootGO, path);
        PrefabUtility.UnloadPrefabContents(rootGO);
            }
        };
    }
}