| | |
| | | _window.autoRepaintOnSceneChange = true;
|
| | | }
|
| | |
|
| | | // [MenuItem("Assets/查找引用", true)]
|
| | | // private static bool FindReferenceValid()
|
| | | // {
|
| | | // string _path = AssetDatabase.GetAssetPath(Selection.activeObject);
|
| | | // return (!string.IsNullOrEmpty(_path));
|
| | | // }
|
| | |
|
| | | private void OnGUI()
|
| | | {
|
| | | // 缓存原始颜色,防止污染全局 GUI 皮肤
|
| | | Color oldColor = GUI.skin.button.normal.textColor;
|
| | | GUI.skin.button.normal.textColor = Color.white;
|
| | |
|
| | | DisplayFuncToggle();
|
| | |
| | | ToolsHelper.folderPath = _selectPath;
|
| | | }
|
| | |
|
| | | GUI.skin.button.normal.textColor = Color.gray;
|
| | | // 恢复原始颜色
|
| | | GUI.skin.button.normal.textColor = oldColor;
|
| | |
|
| | | switch (m_SpriteManageType)
|
| | | {
|
| | |
| | | {
|
| | | var _replaceGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_ReferenceReplace));
|
| | | m_ReferenceGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_ReferenceSource));
|
| | | foreach (var _object in m_ReferenceReplaceDict.Keys)
|
| | | |
| | | // 1. 先保存当前内存中的修改
|
| | | AssetDatabase.SaveAssets(); |
| | |
|
| | | // 为了避免在遍历字典时移除元素报错,将 Key 存放到 List 中遍历
|
| | | var keys = m_ReferenceReplaceDict.Keys.ToList();
|
| | | foreach (var _object in keys)
|
| | | {
|
| | | if (m_ReferenceReplaceDict[_object] && m_ReferenceObjectDict.ContainsKey(_object))
|
| | | {
|
| | |
| | | {
|
| | | string _file = Regex.Replace(_allText, m_ReferenceGUID, _replaceGuid);
|
| | | File.WriteAllText(_path, _file);
|
| | | AssetDatabase.SaveAssets();
|
| | | AssetDatabase.Refresh();
|
| | | |
| | | // 2. 强制刷新修改过的特定资源
|
| | | AssetDatabase.ImportAsset(_path, ImportAssetOptions.ForceUpdate);
|
| | | }
|
| | | m_ReferenceObjectDict.Remove(_object);
|
| | | }
|
| | | }
|
| | | |
| | | // 3. 整体刷新
|
| | | AssetDatabase.Refresh();
|
| | | |
| | | // 4. 清除当前选中物体,防止 Inspector 面板报错
|
| | | Selection.activeObject = null;
|
| | | }
|
| | | }
|
| | | GUILayout.FlexibleSpace();
|
| | |
| | | }
|
| | |
|
| | | m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition);
|
| | | foreach (var _object in m_ReferenceObjectDict.Keys)
|
| | | // 使用 ToList 避免 InvalidOperationException 遍历修改错误
|
| | | var objectKeys = m_ReferenceObjectDict.Keys.ToList();
|
| | | foreach (var _object in objectKeys)
|
| | | {
|
| | | GUILayout.BeginHorizontal();
|
| | | EditorGUILayout.ObjectField(_object, typeof(UnityEngine.Object), false);
|
| | |
| | | EditorUtility.DisplayDialog("提示", "未找到任意文件", "确定");
|
| | | return;
|
| | | }
|
| | | EditorApplication.update = delegate ()
|
| | |
|
| | | // 定义安全的委托
|
| | | EditorApplication.CallbackFunction updateAction = null;
|
| | | updateAction = delegate ()
|
| | | {
|
| | | string _file = _files[_index];
|
| | | bool isCancel = EditorUtility.DisplayCancelableProgressBar("查找引用资源", _file, (float)_index / (float)_files.Length);
|
| | |
| | | if (isCancel || _index >= _files.Length)
|
| | | {
|
| | | EditorUtility.ClearProgressBar();
|
| | | EditorApplication.update = null;
|
| | | // 使用 -= 注销
|
| | | EditorApplication.update -= updateAction;
|
| | | _index = 0;
|
| | | }
|
| | | };
|
| | |
|
| | | // 使用 += 注册
|
| | | EditorApplication.update += updateAction;
|
| | | }
|
| | |
|
| | | private List<string> GetReferenceExtention()
|
| | |
| | | return Regex.IsMatch(x, "^[0-9]+$");
|
| | | });
|
| | | var _index = 1;
|
| | | EditorApplication.update = delegate ()
|
| | |
|
| | | // 第一个委托
|
| | | EditorApplication.CallbackFunction updateAction1 = null;
|
| | | updateAction1 = delegate ()
|
| | | {
|
| | | var _match = _matchs[_index - 1];
|
| | | GetRefComponent(_list[_index], _list[_index].Split('\n'), _match.Groups[1].Value);
|
| | | bool isCancel = EditorUtility.DisplayCancelableProgressBar("查找引用资源",
|
| | | StringUtility.Concat(_index.ToString(), "/", _list.Count.ToString()), (float)_index / (float)_list.Count);
|
| | | _index++;
|
| | | |
| | | if (isCancel || _index >= _list.Count)
|
| | | {
|
| | | _index = 0;
|
| | | // 使用 -= 注销
|
| | | EditorApplication.update -= updateAction1;
|
| | |
|
| | | if (_guid == string.Empty)
|
| | | {
|
| | | _details.AddRange(m_RefDetailDict.Values.ToList());
|
| | | EditorUtility.ClearProgressBar();
|
| | | EditorApplication.update = null;
|
| | | System.GC.Collect();
|
| | | return;
|
| | | }
|
| | |
|
| | | var _keys = m_RefDetailDict.Keys.ToList();
|
| | | EditorApplication.update = delegate ()
|
| | | |
| | | // 嵌套的第二个委托
|
| | | EditorApplication.CallbackFunction updateAction2 = null;
|
| | | updateAction2 = delegate ()
|
| | | {
|
| | | var _detail = m_RefDetailDict[_keys[_index]];
|
| | | if (_detail.guids.Contains(_guid))
|
| | |
| | | {
|
| | | EditorUtility.ClearProgressBar();
|
| | | _index = 0;
|
| | | EditorApplication.update = null;
|
| | | // 使用 -= 注销
|
| | | EditorApplication.update -= updateAction2;
|
| | | System.GC.Collect();
|
| | | }
|
| | | };
|
| | | |
| | | // 使用 += 注册内部的委托
|
| | | EditorApplication.update += updateAction2;
|
| | | }
|
| | | };
|
| | |
|
| | | // 使用 += 注册外部的委托
|
| | | EditorApplication.update += updateAction1;
|
| | | }
|
| | | }
|
| | |
|
| | | private void GetRefComponent(string _source, string[] _msgs, string _fileId)
|
| | | {
|
| | | if (_msgs != null)
|
| | | if (_msgs != null && _msgs.Length > 1) // 加上长度判断避免数组越界报错
|
| | | {
|
| | | switch (_msgs[1])
|
| | | {
|
| | |
| | | case "MonoBehaviour:":
|
| | | {
|
| | | var _match = s_GameObjectRegex.Match(_source);
|
| | | if (_match != null)
|
| | | if (_match != null && _match.Groups.Count > 1)
|
| | | {
|
| | | var _id = _match.Groups[1].Value;
|
| | | var _refDetail = m_RefDetailDict.ContainsKey(_id) ? m_RefDetailDict[_id] : null;
|
| | |
| | | case "RectTransform:":
|
| | | {
|
| | | var _match = s_GameObjectRegex.Match(_source);
|
| | | if (_match != null)
|
| | | if (_match != null && _match.Groups.Count > 1)
|
| | | {
|
| | | var _id = _match.Groups[1].Value;
|
| | | var _refDetail = m_RefDetailDict.ContainsKey(_id) ? m_RefDetailDict[_id] : null;
|
| | |
| | | {
|
| | | _refDetail.rectId = _fileId;
|
| | | var _fatherMatch = s_GameObjectFatherRegex.Match(_source);
|
| | | _refDetail.fatherId = _fatherMatch != null ? _fatherMatch.Groups[1].Value : string.Empty;
|
| | | _refDetail.fatherId = (_fatherMatch != null && _fatherMatch.Groups.Count > 1) ? _fatherMatch.Groups[1].Value : string.Empty;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | GUILayout.EndHorizontal();
|
| | | }
|
| | |
|
| | |
|
| | | static string content = string.Empty;
|
| | | static Font fontData = null;
|
| | | static FontStyle fontStyle;
|
| | | static int fontSize = 14;
|
| | | static float lineSpacing = 0f;
|
| | | static bool richText = true;
|
| | | static TextAnchor alignment;
|
| | | static HorizontalWrapMode hwmode;
|
| | | static VerticalWrapMode vwmode;
|
| | | static Color m_Color;
|
| | | static Material m_Material;
|
| | | static bool raycastTarget;
|
| | |
|
| | | public static TextEx PasteText(Text text)
|
| | | {
|
| | | content = text.text;
|
| | | fontData = text.font;
|
| | | fontStyle = text.fontStyle;
|
| | | fontSize = text.fontSize;
|
| | | lineSpacing = text.lineSpacing;
|
| | | richText = text.supportRichText;
|
| | | alignment = text.alignment;
|
| | | hwmode = text.horizontalOverflow;
|
| | | vwmode = text.verticalOverflow;
|
| | | m_Color = text.color;
|
| | | m_Material = text.material;
|
| | | raycastTarget = text.raycastTarget;
|
| | |
|
| | | var gameObject = text.gameObject;
|
| | | Component.DestroyImmediate(text);
|
| | | TextEx textex = gameObject.AddMissingComponent<TextEx>();
|
| | |
|
| | | textex.text = content;
|
| | | textex.font = fontData;
|
| | | textex.fontStyle = fontStyle;
|
| | | textex.fontSize = fontSize;
|
| | | textex.lineSpacing = lineSpacing;
|
| | | textex.supportRichText = richText;
|
| | | textex.alignment = alignment;
|
| | | textex.horizontalOverflow = hwmode;
|
| | | textex.verticalOverflow = vwmode;
|
| | | textex.color = m_Color;
|
| | | textex.material = m_Material;
|
| | | textex.raycastTarget = raycastTarget;
|
| | |
|
| | | return textex;
|
| | | }
|
| | | // 假设以下需要 TextEx 组件和 AddMissingComponent 方法存在
|
| | | // static string content = string.Empty;
|
| | | // ... 原本后面的 PasteText 方法由于缺少 TextEx 类型定义暂时保留不变
|
| | | } |