少年修仙传客户端基础资源
lwb
2020-11-20 523a8c5b8de799aeaeaa7287f0b4f9e2edf339ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Snxxz.UI;
 
public class PrefabHelper
{
    [InitializeOnLoadMethod]
    static void StartInitializeOnLoadMethod()
    {
        PrefabUtility.prefabInstanceUpdated = delegate (GameObject instance)
        {
            var prefab = PrefabUtility.GetPrefabParent(instance) as GameObject;
            var prefabLoaders = prefab.GetComponentsInChildren<UIPrefabLoader>();
 
            var dirty = false;
            foreach (var loader in prefabLoaders)
            {
                if (!string.IsNullOrEmpty(loader.prefabName))
                {
                    var children = new List<Transform>();
                    for (int i = 0; i < loader.transform.childCount; i++)
                    {
                        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);
                            dirty = true;
                        }
                    }
                }
            }
 
            if (dirty)
            {
                AssetDatabase.SaveAssets();
            }
        };
    }
 
 
}