少年修仙传客户端基础资源
dabaoji
2025-06-09 8ee0256378cbf5dbc9d76ed10b60b65a844ef4dd
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Text.RegularExpressions;
using System.IO;
using UnityEngine.UI;
using vnxbqy.UI;
public class ReplaceImgTool : EditorWindow {
 
    [MenuItem("策划工具/批量替换预制体图片", false)]
    public static void CreateWindow()
    {
        ReplaceImgTool window = (ReplaceImgTool)EditorWindow.GetWindow(typeof(ReplaceImgTool), true, "批量替换预制体图片", true);
        window.Show();
    }
 
    private static Sprite replaceSprite;
    private static int redpointImgSize = 23;
    private static string topFilePath=string.Empty;
    private static string replaceName = string.Empty;
    private static GameObject replacePrefab = null;
 
    static ReplaceType replaceType = ReplaceType.RedPoint;
 
    enum ReplaceType
    {
        RedPoint,
    }
 
    private void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        replaceSprite = EditorGUILayout.ObjectField("Replace Sprite", replaceSprite, typeof(Sprite), false,GUILayout.Width(300)) as Sprite;
        EditorGUILayout.EndHorizontal();
 
        EditorGUILayout.BeginHorizontal();
        redpointImgSize = EditorGUILayout.IntField("Img Size", redpointImgSize);
        EditorGUILayout.EndHorizontal();
 
        EditorGUILayout.BeginHorizontal();
        replaceType=(ReplaceType)EditorGUILayout.EnumPopup("ReplaceType:", replaceType);
        EditorGUILayout.EndHorizontal();
 
        switch (replaceType) {
            case ReplaceType.RedPoint: {
                    UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets);
                    topFilePath = (arr == null || arr.Length == 0) ? topFilePath : Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/')) + "/" + AssetDatabase.GetAssetPath(arr[0]);
                    EditorGUILayout.BeginHorizontal();
                    topFilePath = EditorGUILayout.TextField("Top File Path:", topFilePath);
                    EditorGUILayout.EndHorizontal();
                }
                break;
        }
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("开始替换",GUILayout.Width(100))) {
            Replace();
        }
        EditorGUILayout.EndHorizontal();
    }
 
 
    private static void Replace()
    {
        if (replaceSprite == null) 
        {
            Debug.LogError("图片不能为空");
            return;
        }
        if (replaceType ==ReplaceType.RedPoint&&Regex.IsMatch(topFilePath, @".*\..*")) {
            Debug.LogError("必须为文件夹路径");
            return;
        }
        switch (replaceType) {
            case ReplaceType.RedPoint: {
                    string[] filepaths = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories);
                    int startIndex = 0;
                    EditorApplication.update = delegate () {
                        string file = filepaths[startIndex];
                        file = file.Substring(file.IndexOf("Assets"));
                        bool isCancel = EditorUtility.DisplayCancelableProgressBar("替换图片资源", file, (float)startIndex / (float)filepaths.Length);
                        GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file);
                        ReplaceRedPoint(_prefab);
                        startIndex++;
                        if (isCancel || startIndex >= filepaths.Length) {
                            EditorUtility.ClearProgressBar();
                            EditorApplication.update = null;
                            startIndex = 0;
                            AssetDatabase.SaveAssets();
                            AssetDatabase.Refresh();
                        }
                    };
                }
                break;
        }
    }
 
    private static void ReplaceRedPoint(GameObject source)
    {
        if (RecursionFind(source.transform)) {
            EditorUtility.SetDirty(source);
        }
    }
 
    private static bool RecursionFind(Transform parent)
    {
        RedpointBehaviour redpointBehaviour = parent.GetComponent<RedpointBehaviour>();
        bool chanaged = false;
        if (redpointBehaviour != null) {
            if (redpointBehaviour.simpleRedpoint != null) {
                Image img = redpointBehaviour.simpleRedpoint.GetComponent<Image>();
                if (img != null) {
                    img.sprite = replaceSprite;
                    img.color = Color.white;
                    img.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
                    img.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                    img.rectTransform.sizeDelta = new Vector2(redpointImgSize, redpointImgSize);
                }
            }
            if (redpointBehaviour.quantityRedpoint != null) {
                Image img = redpointBehaviour.quantityRedpoint.GetComponent<Image>();
                if (img != null) {
                    img.sprite = replaceSprite;
                    img.color = Color.white;
                    img.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
                    img.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                    img.rectTransform.sizeDelta = new Vector2(redpointImgSize, redpointImgSize);
                }
            }
            if (redpointBehaviour.quantityText != null) {
                redpointBehaviour.quantityText.color = new Color32(247, 247, 247, 255);
                redpointBehaviour.quantityText.fontSize = 22;
                redpointBehaviour.quantityText.rectTransform.sizeDelta = new Vector2(25, 25);
                redpointBehaviour.quantityText.rectTransform.localPosition = Vector3.zero;
            }
            chanaged = true;
        }
        foreach (Transform child in parent) {
            if (RecursionFind(child)) {
                chanaged = true;
            }
        }
        return chanaged;
    }
}