Esempio n. 1
0
        static void SaveSelectPrefab(IList <string> files, string debugText, System.Func <Object, CustomizeData, bool> onSet, System.Action onend)
        {
            var start = System.DateTime.Now;

            Debug.Log($"开始执行:{debugText}");
            GlobalCoroutine.StartCoroutine(EditorHelper.ForEachAsync(debugText, files, (file) =>
            {
                bool isOk = PrefabModify.Modify(file, (go) =>
                {
                    var serials = go.GetComponentsInChildren <ISerializationCallbackReceiver>(true);
                    int cnt     = serials.Length;
                    if (serials.Length == 0)
                    {
                        return;
                    }

                    bool isDirty = false;
                    for (int i = 0; i < cnt; ++i)
                    {
                        var obj  = serials[i] as Object;
                        var type = obj.GetType();
                        var customizeDataField = IL.Help.GetField(type, "customizeData");
                        if (customizeDataField != null)
                        {
                            var customizeData = customizeDataField.GetValue(obj) as CustomizeData;
                            if (customizeData != null)
                            {
                                if (onSet(obj, customizeData))
                                {
                                    isDirty = true;
                                }
                            }
                        }
                    }

                    if (isDirty)
                    {
                        EditorUtility.SetDirty(go);
                    }
                });
            },
                                                                     () =>
            {
                var now = System.DateTime.Now;
                Debug.Log($"{debugText}执行完毕!用时:{(now-start).TotalSeconds}s");
                onend?.Invoke();
            }));
        }
Esempio n. 2
0
        static void SaveSelectPrefab(Object[] objects, System.Action <CustomizeData> onSet, System.Action onend)
        {
            int count = 10;

            GlobalCoroutine.StartCoroutine(EditorHelper.ForEachSelectASync(objects, (file) =>
            {
                if (!file.EndsWith(".prefab"))
                {
                    return(null);
                }

                if (!isNeedCheck(AssetDatabase.LoadAssetAtPath <GameObject>(file)))
                {
                    return(null);
                }

                bool isOk = PrefabModify.Modify(file, (go) =>
                {
                    var serials = go.GetComponentsInChildren <ISerializationCallbackReceiver>(true);
                    int cnt     = serials.Length;
                    if (serials.Length == 0)
                    {
                        return;
                    }

                    for (int i = 0; i < cnt; ++i)
                    {
                        var obj  = serials[i] as Object;
                        var type = obj.GetType();
                        var customizeDataField = IL.Help.GetField(type, "customizeData");
                        if (customizeDataField != null)
                        {
                            var customizeData = customizeDataField.GetValue(obj) as CustomizeData;
                            if (customizeData != null)
                            {
                                onSet?.Invoke(customizeData);
                                EditorUtility.SetDirty(obj);
                            }
                        }
                    }
                });

                if (isOk)
                {
                    Debug.Log(file);
                    --count;
                    return(() =>
                    {
                        if (count == 0)
                        {
                            count = 10;
                            return true;
                        }

                        return false;
                    });
                }
                else
                {
                    return(null);
                }
            }, onend));
        }