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));
        }
Esempio n. 3
0
        private void RefreshPrefab()
        {
            GUILayout.BeginHorizontal();
            {
                indexPrefab.value = EditorGUILayout.Popup(indexPrefab.value, _list);
            }
            GUILayout.EndHorizontal();

            GUILayout.Box(string.Empty, GUILayout.Height(3), GUILayout.ExpandWidth(true));

            if (file == null)
            {
                return;
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.BeginVertical();
                {
                    EditorGUILayout.ObjectField(prefab, typeof(GameObject), false);

                    int count = dependencies.Count;

                    if (count > 0)
                    {
                        scroll = GUILayout.BeginScrollView(scroll);
                        {
                            GUI.enabled = false;

                            for (int i = 0; i < count; i++)
                            {
                                RefreshPrefabDependence(dependencies[i]);
                            }
                            GUI.enabled = true;
                        }
                        GUILayout.EndScrollView();
                    }
                }
                GUILayout.EndVertical();

                GUILayout.Box(string.Empty, GUILayout.Width(3), GUILayout.ExpandHeight(true));

                GUILayout.BeginVertical(GUILayout.Width(200));
                {
                    if (GUILayout.Button("检查引用"))
                    {
                        if (indexPrefab.value == 0)
                        {
                        }
                        else
                        {
                            PrefabModify.Missing(file.asset);
                        }
                    }
                    Horizontal(() =>
                    {
                        color[0] = EditorGUILayout.ColorField(color[0]);

                        if (GUILayout.Button("图像"))
                        {
                            PrefabModify.ModifyGraphicColor(file.asset, color[0]);
                        }
                    });
                    Horizontal(() =>
                    {
                        color[1] = EditorGUILayout.ColorField(color[1]);

                        if (GUILayout.Button("文本"))
                        {
                            PrefabModify.ModifyTextColor(file.asset, color[1]);
                        }
                    });
                    Horizontal(() =>
                    {
                        color[2] = EditorGUILayout.ColorField(color[2]);

                        if (GUILayout.Button("阴影"))
                        {
                            PrefabModify.ModifyShadowColor(file.asset, color[2]);
                        }
                    });
                    if (GUILayout.Button("触发:false"))
                    {
                        PrefabModify.ModifyGraphicRaycast(file.asset);
                    }
                    if (GUILayout.Button("复制"))
                    {
                        Selection.activeObject = prefab;

                        Open <PrefabCopy>("拷贝文件");
                    }
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();
        }