private object GetRefObj(UFileInfo info) { switch (info.assetFrom) { case AssetFrom.StringFinder: return(stringFinder.curFindString); case AssetFrom.OtherAsset: return(curFindAsset); case AssetFrom.Resources: return(assetRefFinder.curFindString); } return(null); }
private void DrawUFileInfo(UFileInfo v, ReferenceToolBase maid) { GUILayout.BeginHorizontal(); var content = EditorGUIUtility.ObjectContent(null, v.assetType); content.text = v.fileName; if (GUILayout.Button( content, EditorStyles.objectField, GUILayout.Height(16f), GUILayout.Width(250f) )) { EditorGUIUtility.PingObject(v.asset); } // EditorGUI.BeginDisabledGroup(true); // EditorGUILayout.ObjectField(v.Obj, v.ObjType, false); // EditorGUI.EndDisabledGroup(); switch (v.extension) { case ".prefab": case ".unity": if (GUILayout.Button("Open", GUILayout.Height(16))) { EditRefer(v); } break; } EditorGUI.BeginDisabledGroup(!enableReplace); DrawUFileInfoReplacePne(v, maid); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); }
private void EditRefer(UFileInfo info) { void ClearConsoleLog() { var consoleWindowInst = ReflectionUtil.GetEditorWindow("UnityEditor.ConsoleWindow"); ReflectionUtil.CallStatic("UnityEditor.LogEntries", "Clear"); consoleWindowInst.Call("DoLogChanged"); } ClearConsoleLog(); switch (info.extension) { case ".prefab": { var stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage == null || stage.prefabContentsRoot.name != info.fileName) { AssetDatabase.OpenAsset(info.asset); stage = PrefabStageUtility.GetCurrentPrefabStage(); } var root = stage.prefabContentsRoot; if (root) { var refObj = GetRefObj(info); HighlightUtil.HighlightRefer( root, refObj, true, findThingType ); } break; } case ".unity": { var path = UToolsUtil.AssetRelativePath(info.relativePath); var scene = SceneManager.GetSceneByPath(path); if (!scene.IsValid()) { var index = EditorUtility.DisplayDialogComplex( "Warning", $"How to open this scene {info.fileName} ?", "Cancel", "SingleOpen", "Additive" ); switch (index) { case 0: break; case 1: scene = EditorSceneManager.OpenScene( path, OpenSceneMode.Single ); break; case 2: scene = EditorSceneManager.OpenScene( path, OpenSceneMode.Additive ); break; } if (!scene.isLoaded) { scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Additive); } } if (scene.IsValid()) { var refObj = GetRefObj(info); HighlightUtil.HighlightRefer( scene, refObj, true, findThingType ); } break; } } }
private void DrawUFileInfoReplacePne(UFileInfo v, ReferenceToolBase worker) { if (v.assetFrom == AssetFrom.Resources) { //todo 暂时禁用 return; } if (v.isWaiting) { GUILayout.Label("Waiting...", GUILayout.Height(16)); } else { var replaceInfo = worker.FindReplaceInfo(v.relativePath); if (replaceInfo != null) { if (GUILayout.Button("Revert", GUILayout.Width(60f), GUILayout.Height(16))) { worker.RevertReplace(replaceInfo); } } else { switch (findThingType) { case FindThingType.Assets: if (!(curFindAsset is GameObject)) { EditorGUI.BeginDisabledGroup(!replaceTargetAsset); { if (GUILayout.Button( "Replace", GUILayout.Width(60f), GUILayout.Height(16) )) { if (EnsureReplaceToStr(worker)) { worker.ReplaceOne(v); } } EditorGUI.EndDisabledGroup(); } } break; case FindThingType.CustomStr: EditorGUI.BeginDisabledGroup(!replaceTargetString.IsNNOE()); if (GUILayout.Button( "Replace", GUILayout.Width(60f), GUILayout.Height(16) )) { if (EnsureReplaceToStr(worker)) { worker.ReplaceOne(v); } } EditorGUI.EndDisabledGroup(); break; } } } }