protected override void Draw(Rect r) { var drawR = r; drawR.xMin -= 16f; asset.Draw(drawR, false, false); var bRect = r; bRect.xMin += bRect.width - 50f; if (GUI.Button(bRect, "Use", EditorStyles.miniButton)) { EditorGUIUtility.systemCopyBuffer = asset.guid; Selection.objects = (parent as FR2_DuplicateFolder).children.Select( a => FR2_Unity.LoadAssetAtPath <Object>(((FR2_DuplicateAsset)a).asset.assetPath) ).ToArray(); FR2_Export.MergeDuplicate(); } //if (GUI.Button(bRect, "Remove Others", EditorStyles.miniButton)) //{ // EditorGUIUtility.systemCopyBuffer = asset.guid; // Selection.objects = (parent as FR2_DuplicateFolder).children.Select( // a => FR2_Unity.LoadAssetAtPath<Object>(((FR2_DuplicateAsset)a).asset.assetPath) // ).ToArray(); // FR2_Export.MergeDuplicate(); //} }
internal void LoadBinaryAsset() { UseGUIDs.Clear(); //var assets = AssetDatabase.LoadAllAssetsAtPath(assetPath); //for (var i = 0;i < assets.Length; i++){ // Debug.Log(i + " : "+ assets[i].name + ":" + assets[i].GetType() + "\n" + // //EditorUtility.GetAssetPath(assets[i]) + "\n" // assets[i].GetHashCode() // ); //} var assetData = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)); if (assetData is GameObject) { type = FR2_AssetType.MODEL; LoadGameObject(assetData as GameObject); } else if (assetData is TerrainData) { type = FR2_AssetType.TERRAIN; LoadTerrainData(assetData as TerrainData); } //Debug.Log("LoadBinaryAsset :: " + assetData + ":" + type); assetData = null; FR2_Unity.UnloadUnusedAssets(); }
public FR2_SceneRef(int depth, Object target) : base(0, depth, null, null) { component = target; this.depth = depth; isSceneRef = true; var obj = target as GameObject; if (obj == null) { var com = target as Component; if (com != null) { obj = com.gameObject; } } scenePath = FR2_Unity.GetGameObjectPath(obj, false); if (component == null) { return; } sceneFullPath = scenePath + component.name; targetType = component.GetType().Name; }
private static void ShowWindow() { var _window = CreateInstance <FR2_WindowAll>(); _window.InitIfNeeded(); FR2_Unity.SetWindowTitle(_window, "FR2"); _window.Show(); }
private void DrawGUIDs() { var ids = FR2_Unity.Selection_AssetGUIDs; var objs = Selection.objects; GUILayout.Label("GUID to Object", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); { var guid = EditorGUILayout.TextField(tempGUID ?? string.Empty); EditorGUILayout.ObjectField(tempObject, typeof(Object), false, GUILayout.Width(120f)); if (GUILayout.Button("Paste", EditorStyles.miniButton, GUILayout.Width(70f))) { guid = EditorGUIUtility.systemCopyBuffer; } if (guid != tempGUID && !string.IsNullOrEmpty(guid)) { tempGUID = guid; tempObject = FR2_Unity.LoadAssetAtPath <Object> ( AssetDatabase.GUIDToAssetPath(tempGUID) ); } } GUILayout.EndHorizontal(); GUILayout.Space(10f); //GUILayout.Label("Selection", EditorStyles.boldLabel); if (ids.Length == objs.Length) { scrollPos = GUILayout.BeginScrollView(scrollPos); { for (var i = 0; i < ids.Length; i++) { GUILayout.BeginHorizontal(); { EditorGUILayout.ObjectField(objs[i], typeof(Object), false); var idi = ids[i]; GUILayout.TextField(idi, GUILayout.Width(240f)); if (GUILayout.Button("Copy", EditorStyles.miniButton, GUILayout.Width(50f))) { EditorGUIUtility.systemCopyBuffer = idi; //Debug.Log(EditorGUIUtility.systemCopyBuffer); } } GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Merge Selection")) { FR2_Export.MergeDuplicate(); } }
private static void Initialize() { if (window == null) { window = GetWindow <FR2_Window>(); window.Init(); } FR2_Unity.SetWindowTitle(window, "FR2"); window.Show(); }
internal void AddToSelection() { var list = Selection.objects.ToList(); var obj = FR2_Unity.LoadAssetAtPath <Object>(assetPath); if (!list.Contains(obj)) { list.Add(obj); Selection.objects = list.ToArray(); } }
//-------------------------- UTILS --------------------- internal static void AddToDict(Dictionary <string, Object> dict, params FR2_Asset[] list) { for (var j = 0; j < list.Length; j++) { string guid = list[j].guid; if (!dict.ContainsKey(guid)) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); dict.Add(guid, FR2_Unity.LoadAssetAtPath <Object>(assetPath)); } } }
internal void ReadFromProject(bool force) { var paths = AssetDatabase.GetAllAssetPaths().ToList(); paths.RemoveAll(item => !item.StartsWith("Assets/")); var guids = paths.Select(item => AssetDatabase.AssetPathToGUID(item)).ToArray(); cacheStamp++; // Check for new assets for (var i = 0; i < guids.Length; i++) { if (!FR2_Asset.IsValidGUID(guids[i])) { continue; } FR2_Asset asset; if (AssetMap.TryGetValue(guids[i], out asset)) { asset.cacheStamp = cacheStamp; continue; } ; // New asset AddAsset(guids[i]); } // Check for deleted assets for (var i = AssetList.Count - 1; i >= 0; i--) { if (AssetList[i].cacheStamp != cacheStamp) { RemoveAsset(AssetList[i]); } } // Refresh definition list for (var i = 0; i < AssetList.Count; i++) { AddSymbols(AssetList[i]); } if (force) { timeStamp = FR2_Unity.Epoch(DateTime.Now); workCount += AssetMap.Count; queueLoadContent.AddRange(AssetMap.Values.ToList()); } }
private static bool RestoreCacheFromPath(string path, bool savePrefs, bool writeFile) { if (string.IsNullOrEmpty(path)) { return(false); } _cache = FR2_Unity.LoadAssetAtPath <FR2_Cache>(path); if (_cache != null) { FoundCache(savePrefs, writeFile); } return(_cache != null); }
public override void OnSelectionChange() { isNoticeIgnore = false; if (!FR2_Cache.isReady) { return; } if (lockSelection) { return; } if (focusedWindow == null) { return; } if (SceneUsesDrawer == null) { InitIfNeeded(); } ids = FR2_Unity.Selection_AssetGUIDs; //ignore selection on asset when selected any object in scene if (Selection.gameObjects.Length > 0 && !FR2_Unity.IsInAsset(Selection.gameObjects[0])) { ids = new string[0]; } if (IsFocusingSceneInScene) { RefSceneInScene.ResetSceneInScene(Selection.gameObjects); } if (IsFocusingUses) { SceneUsesDrawer.ResetSceneUseSceneObjects(Selection.gameObjects); } if (IsFocusingFindInScene) { RefInScene.Reset(ids, this as IWindow); } level = 0; EditorApplication.delayCall += Repaint; }
private static void ExportAsset() { var list = GetSelectionDependencies(); for (var i = list.Count - 1; i >= 0; i--) { if (list[i] is MonoScript) { list.RemoveAt(i); } //Debug.Log(i + ":" + list[i] + ":" + list[i].GetType()); } Selection.objects = list.ToArray(); FR2_Unity.ExportSelection(); }
private static List <Object> GetSelectionDependencies() { if (!FR2_Cache.isReady) { Debug.LogWarning("FR2 cache not yet ready, please open Window > FR2_Window !"); return(null); } return(FR2_Cache.FindUsage(FR2_Unity.Selection_AssetGUIDs).Select( guid => { var assetPath = AssetDatabase.GUIDToAssetPath(guid); return FR2_Unity.LoadAssetAtPath <Object>(assetPath); } ).ToList()); }
internal void LoadAssetInfo() { assetPath = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(assetPath)) { state = FR2_AssetState.MISSING; return; } if (!assetPath.StartsWith("Assets/", StringComparison.Ordinal)) { #if FR2_DEBUG Debug.LogWarning("Something wrong ! Should never be here !\n" + assetPath + "\n" + guid); #endif return; } var info = new FileInfo(assetPath); assetName = info.Name; extension = info.Extension.ToLower(); assetFolder = assetPath.Substring(7, Mathf.Max(0, assetPath.Length - assetName.Length - 7)); // 7 = "Assets/".Length loaded = stamp == FR2_Unity.Epoch(info.LastWriteTime); if (Directory.Exists(info.FullName)) { type = FR2_AssetType.FOLDER; } else if (File.Exists(info.FullName)) { if (type == FR2_AssetType.UNKNOWN) { GuessAssetType(); } fileSize = info.Length; inEditor = assetPath.Contains("/Editor/"); inResources = assetPath.Contains("/Resources/"); inStreamingAsset = assetPath.Contains("/StreamingAsset/"); inPlugins = assetPath.StartsWith("Assets/Plugins/", StringComparison.Ordinal); fileInfoHash = info.Length + info.Extension; } else { state = FR2_AssetState.MISSING; } }
private static void FoundCache(bool savePrefs, bool writeFile) { var elapseTime = FR2_Unity.Epoch(DateTime.Now) - _cache.timeStamp; _cache.Check4Changes(!EditorApplication.isPlaying, elapseTime > FORCE_REFRESH_DURATION); _cachePath = AssetDatabase.GetAssetPath(_cache); _cacheGUID = AssetDatabase.AssetPathToGUID(_cachePath); if (savePrefs) { EditorPrefs.SetString("fr2_cache.guid", _cacheGUID); } if (writeFile) { File.WriteAllText("Library/fr2_cache.guid", _cacheGUID); } }
// ------------------------- Scene use scene objects public static Dictionary <string, FR2_Ref> FindSceneUseSceneObjects(GameObject[] targets) { var results = new Dictionary <string, FR2_Ref>(); GameObject[] objs = Selection.gameObjects; for (var i = 0; i < objs.Length; i++) { if (FR2_Unity.IsInAsset(objs[i])) { continue; } string key = objs[i].GetInstanceID().ToString(); if (!results.ContainsKey(key)) { results.Add(key, new FR2_SceneRef(0, objs[i])); } Component[] coms = objs[i].GetComponents <Component>(); Dictionary <Component, HashSet <FR2_SceneCache.HashValue> > SceneCache = FR2_SceneCache.Api.cache; for (var j = 0; j < coms.Length; j++) { HashSet <FR2_SceneCache.HashValue> hash = null; if (SceneCache.TryGetValue(coms[j], out hash)) { foreach (FR2_SceneCache.HashValue item in hash) { if (item.isSceneObject) { Object obj = item.target; string key1 = obj.GetInstanceID().ToString(); if (!results.ContainsKey(key1)) { results.Add(key1, new FR2_SceneRef(1, obj)); } } } } } } return(results); }
public void DrawSettings() { if (FR2_Unity.DrawToggle(ref pingRow, "Full Row click to Ping")) { setDirty(); } GUILayout.BeginHorizontal(); { if (FR2_Unity.DrawToggle(ref alternateColor, "Alternate Odd & Even Row Color")) { setDirty(); FR2_Unity.RepaintFR2Windows(); } EditorGUI.BeginDisabledGroup(!alternateColor); { var c = EditorGUILayout.ColorField(rowColor); if (!c.Equals(rowColor)) { rowColor = c; setDirty(); FR2_Unity.RepaintFR2Windows(); } } EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); if (FR2_Unity.DrawToggle(ref referenceCount, "Show Usage Count in Project panel")) { setDirty(); FR2_Unity.RepaintProjectWindows(); } if (FR2_Unity.DrawToggle(ref showSelection, "Show Selection")) { setDirty(); FR2_Unity.RepaintFR2Windows(); } }
public static Dictionary <string, FR2_Ref> FindUsageScene(GameObject[] objs, bool depth) { var dict = new Dictionary <string, FR2_Ref>(); // var list = new List<FR2_Ref>(); for (var i = 0; i < objs.Length; i++) { if (FR2_Unity.IsInAsset(objs[i])) { continue; //only get in scene } //add selection if (!dict.ContainsKey(objs[i].GetInstanceID().ToString())) { dict.Add(objs[i].GetInstanceID().ToString(), new FR2_SceneRef(0, objs[i])); } foreach (Object item in FR2_Unity.GetAllRefObjects(objs[i])) { AppendUsageScene(dict, item); } if (depth) { foreach (GameObject child in FR2_Unity.getAllChild(objs[i])) { foreach (Object item2 in FR2_Unity.GetAllRefObjects(child)) { AppendUsageScene(dict, item2); } } } } return(dict); }
internal void LoadContent(bool force) { if (state == FR2_AssetState.NEW) { LoadAssetInfo(); } if (IsMissing || type == FR2_AssetType.NON_READABLE) { return; } if (type == FR2_AssetType.DLL) { #if FR2_DEBUG Debug.LogWarning("Parsing DLL not yet supportted "); #endif return; } if (loaded && !force) { return; } // Check for file / folder changes & validate if file / folder exist var newStamp = stamp; var exist = true; if (IsFolder) { var info = new DirectoryInfo(assetPath); exist = info.Exists; newStamp = FR2_Unity.Epoch(info.LastWriteTime); } else { var info = new FileInfo(assetPath); exist = info.Exists; newStamp = FR2_Unity.Epoch(info.LastWriteTime); } if (!exist) { state = FR2_AssetState.MISSING; return; } loaded = true; if (newStamp == stamp && !force) { #if FR2_DEBUG Debug.Log("Unchanged : " + stamp + ":" + assetName + ":" + type); #endif return; // nothing changed } stamp = newStamp; UseGUIDs.Clear(); if (IsFolder) { LoadFolder(); } else if (IsReferencable) { LoadYAML(); } else if (IsBinaryAsset) { LoadBinaryAsset(); } else if (IsScript) { LoadScript(); } }
private void ApplyFilter() { dirty = false; if (refs == null) { return; } if (list == null) { list = new List <FR2_Ref>(); } else { list.Clear(); } int minScore = searchTerm.Length; string term1 = searchTerm; if (!caseSensitive) { term1 = term1.ToLower(); } string term2 = term1.Replace(" ", string.Empty); excludeCount = 0; foreach (KeyValuePair <string, FR2_Ref> item in refs) { FR2_Ref r = item.Value; if (r.depth == 0 && !FR2_Setting.ShowSelection) { continue; } if (FR2_Setting.IsTypeExcluded(r.type)) { excludeCount++; continue; //skip this one } if (!showSearch || string.IsNullOrEmpty(searchTerm)) { r.matchingScore = 0; list.Add(r); continue; } //calculate matching score string name1 = r.isSceneRef ? (r as FR2_SceneRef).sceneFullPath : r.asset.assetName; if (!caseSensitive) { name1 = name1.ToLower(); } string name2 = name1.Replace(" ", string.Empty); int score1 = FR2_Unity.StringMatch(term1, name1); int score2 = FR2_Unity.StringMatch(term2, name2); r.matchingScore = Mathf.Max(score1, score2); if (r.matchingScore > minScore) { list.Add(r); } } RefreshSort(); }
// ----------------------------- REPLACE GUIDS --------------------------------------- internal bool ReplaceReference(string fromGUID, string toGUID) { if (IsMissing) { return(false); } if (IsReferencable) { var text = string.Empty; if (!File.Exists(assetPath)) { state = FR2_AssetState.MISSING; return(false); } try { text = File.ReadAllText(assetPath).Replace("\r", "\n"); File.WriteAllText(assetPath, text.Replace(fromGUID, toGUID)); return(true); } catch (Exception e) { state = FR2_AssetState.MISSING; //#if FR2_DEBUG Debug.LogWarning("Replace Reference error :: " + e + "\n" + assetPath); //#endif } return(false); } if (type == FR2_AssetType.TERRAIN) { var fromObj = FR2_Unity.LoadAssetWithGUID <Object>(fromGUID); var toObj = FR2_Unity.LoadAssetWithGUID <Object>(toGUID); var found = 0; var terrain = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)) as TerrainData; if (fromObj is Texture2D) { var arr = terrain.detailPrototypes; for (var i = 0; i < arr.Length; i++) { if (arr[i].prototypeTexture == (Texture2D)fromObj) { found++; arr[i].prototypeTexture = (Texture2D)toObj; } } terrain.detailPrototypes = arr; var arr3 = terrain.splatPrototypes; for (var i = 0; i < arr3.Length; i++) { if (arr3[i].texture == (Texture2D)fromObj) { found++; arr3[i].texture = (Texture2D)toObj; } if (arr3[i].normalMap == (Texture2D)fromObj) { found++; arr3[i].normalMap = (Texture2D)toObj; } } terrain.splatPrototypes = arr3; } if (fromObj is GameObject) { var arr2 = terrain.treePrototypes; for (var i = 0; i < arr2.Length; i++) { if (arr2[i].prefab == (GameObject)fromObj) { found++; arr2[i].prefab = (GameObject)toObj; } } terrain.treePrototypes = arr2; } EditorUtility.SetDirty(terrain); AssetDatabase.SaveAssets(); fromObj = null; toObj = null; terrain = null; FR2_Unity.UnloadUnusedAssets(); return(found > 0); } Debug.LogWarning("Something wrong, should never be here - Ignored <" + assetPath + "> : not a readable type, can not replace ! " + type); return(false); }
// ------------------------- Scene in scene public static Dictionary <string, FR2_Ref> FindSceneInScene(GameObject[] targets) { var results = new Dictionary <string, FR2_Ref>(); GameObject[] objs = Selection.gameObjects; for (var i = 0; i < objs.Length; i++) { if (FR2_Unity.IsInAsset(objs[i])) { continue; } string key = objs[i].GetInstanceID().ToString(); if (!results.ContainsKey(key)) { results.Add(key, new FR2_SceneRef(0, objs[i])); } foreach (KeyValuePair <Component, HashSet <FR2_SceneCache.HashValue> > item in FR2_SceneCache.Api.cache) { foreach (FR2_SceneCache.HashValue item1 in item.Value) { // if(item.Key.gameObject.name == "ScenesManager") // Debug.Log(item1.objectReferenceValue); GameObject ob = null; if (item1.target is GameObject) { ob = item1.target as GameObject; } else { var com = item1.target as Component; if (com == null) { continue; } ob = com.gameObject; } if (ob == null) { continue; } if (ob != objs[i]) { continue; } key = item.Key.GetInstanceID().ToString(); if (!results.ContainsKey(key)) { results.Add(key, new FR2_SceneRef(1, item.Key)); } (results[key] as FR2_SceneRef).usingType.Add(item1.target.GetType().FullName); } } } return(results); }
public FR2_RefDrawer Reset(GameObject[] objs, bool findDept, bool findPrefabInAsset) { refs = FR2_Ref.FindUsageScene(objs, findDept); var guidss = new List <string>(); Dictionary <GameObject, HashSet <string> > dependent = FR2_SceneCache.Api.prefabDependencies; foreach (GameObject gameObject in objs) { HashSet <string> hash; if (!dependent.TryGetValue(gameObject, out hash)) { continue; } foreach (string guid in hash) { guidss.Add(guid); } } Dictionary <string, FR2_Ref> usageRefs1 = FR2_Ref.FindUsage(guidss.ToArray()); foreach (KeyValuePair <string, FR2_Ref> kvp in usageRefs1) { if (refs.ContainsKey(kvp.Key)) { continue; } if (guidss.Contains(kvp.Key)) { kvp.Value.depth = 1; } refs.Add(kvp.Key, kvp.Value); } if (findPrefabInAsset) { var guids = new List <string>(); for (var i = 0; i < objs.Length; i++) { string guid = FR2_Unity.GetPrefabParent(objs[i]); if (string.IsNullOrEmpty(guid)) { continue; } guids.Add(guid); } Dictionary <string, FR2_Ref> usageRefs = FR2_Ref.FindUsage(guids.ToArray()); foreach (KeyValuePair <string, FR2_Ref> kvp in usageRefs) { if (refs.ContainsKey(kvp.Key)) { continue; } if (guids.Contains(kvp.Key)) { kvp.Value.depth = 1; } refs.Add(kvp.Key, kvp.Value); } } dirty = true; if (list != null) { list.Clear(); } return(this); }
//[MenuItem("Assets/FR2/Export Selection", false, 21)] private static void ExportSelection() { FR2_Unity.ExportSelection(); }
public void Draw(Rect r, IWindow window) { bool selected = isSelected(); var margin = 2; var left = new Rect(r); left.width = r.width / 3f; var right = new Rect(r); right.x += left.width + margin; right.width = r.width * 2f / 3 - margin; if (/* FR2_Setting.PingRow && */ Event.current.type == EventType.MouseDown && Event.current.button == 0) { Rect pingRect = FR2_Setting.PingRow ? new Rect(0, r.y, r.x + r.width, r.height) : left; if (pingRect.Contains(Event.current.mousePosition)) { if (Event.current.control || Event.current.command) { if (selected) { FR2_Selection.RemoveSelection(this); } else { FR2_Selection.AppendSelection(this); } if (window != null) { window.Repaint(); } } EditorGUIUtility.PingObject(component); //Event.current.Use(); } } EditorGUI.ObjectField(left, GUIContent.none, component, typeof(GameObject), true); bool drawPath = FR2_Setting.GroupMode != FR2_RefDrawer.Mode.Folder; float pathW = drawPath ? EditorStyles.miniLabel.CalcSize(new GUIContent(scenePath)).x : 0; string assetName = component.name; // if(usingType!= null && usingType.Count > 0) // { // assetName += " -> "; // foreach(var item in usingType) // { // assetName += item + " - "; // } // assetName = assetName.Substring(0, assetName.Length - 3); // } Color cc = FR2_Cache.Api.setting.SelectedColor; var lableRect = new Rect( right.x, right.y, pathW + EditorStyles.boldLabel.CalcSize(new GUIContent(assetName)).x, right.height); if (selected) { Color c = GUI.color; GUI.color = cc; GUI.DrawTexture(lableRect, EditorGUIUtility.whiteTexture); GUI.color = c; } if (drawPath) { GUI.Label(LeftRect(pathW, ref right), scenePath, EditorStyles.miniLabel); right.xMin -= 4f; GUI.Label(right, assetName, EditorStyles.boldLabel); } else { GUI.Label(right, assetName); } if (!FR2_Setting.ShowUsedByClassed || usingType == null) { return; } float sub = 10; var re = new Rect(r.x + r.width - sub, r.y, 20, r.height); Type t = null; foreach (string item in usingType) { string name = item; if (!CacheType.TryGetValue(item, out t)) { t = FR2_Unity.GetType(name); // if (t == null) // { // continue; // } CacheType.Add(item, t); } GUIContent content; var width = 0.0f; if (!FR2_Asset.cacheImage.TryGetValue(name, out content)) { if (t == null) { content = new GUIContent(name); } else { Texture text = EditorGUIUtility.ObjectContent(null, t).image; if (text == null) { content = new GUIContent(name); } else { content = new GUIContent(text, name); } } FR2_Asset.cacheImage.Add(name, content); } if (content.image == null) { width = EditorStyles.label.CalcSize(content).x; } else { width = 20; } re.x -= width; re.width = width; GUI.Label(re, content); re.x -= margin; // margin; } // var nameW = EditorStyles.boldLabel.CalcSize(new GUIContent(assetName)).x; }
private static void ApplicationUpdate() { bool notComplete = listReplace.Where(x => x.Value.processIndex >= 0).Count() > 0; if (lstThreads.Count <= 0 && notComplete) { foreach (KeyValuePair <string, ProcessReplaceData> item in listReplace) { if (item.Value.processIndex >= 0) { ReplaceData a = item.Value.datas[item.Value.processIndex--]; a.isTerrian = a.asset.type == FR2_AssetType.TERRAIN; if (a.isTerrian) { a.terrainData = AssetDatabase.LoadAssetAtPath(a.asset.assetPath, typeof(Object)) as TerrainData; } var thread = new Thread( delegate() { lock (a) { a.isSucess = a.asset.ReplaceReference(a.from, a.to, a.terrainData); // Debug.Log(a.asset.assetPath+" "+ a.isSucess); } }); lstThreads.Add(thread); thread.Start(); } } } for (int i = lstThreads.Count - 1; i >= 0; i--) { if (!lstThreads[i].IsAlive) { lstThreads.RemoveAt(i); } } foreach (KeyValuePair <string, ProcessReplaceData> item in listReplace) { List <ReplaceData> lst = item.Value.datas; for (var i = 0; i < lst.Count; i++) { ReplaceData data = lst[i]; if (!data.isUpdated && data.isSucess) { data.isUpdated = true; if (data.isTerrian) { EditorUtility.SetDirty(data.terrainData); AssetDatabase.SaveAssets(); data.terrainData = null; FR2_Unity.UnloadUnusedAssets(); } else { AssetDatabase.ImportAsset(data.asset.assetPath, ImportAssetOptions.Default); } } } } if (lstThreads.Count <= 0 && !notComplete) //complete { var guidsRefreshed = new HashSet <string>(); EditorApplication.update -= ApplicationUpdate; foreach (KeyValuePair <string, ProcessReplaceData> item in listReplace) { List <ReplaceData> lst = item.Value.datas; for (var i = 0; i < lst.Count; i++) { ReplaceData data = lst[i]; if (data.isSucess && !guidsRefreshed.Contains(data.asset.guid)) { guidsRefreshed.Add(data.asset.guid); FR2_Cache.Api.RefreshAsset(data.asset.guid, true); } } } lstThreads = null; listReplace = null; FR2_Cache.Api.RefreshSelection(); FR2_Cache.Api.Check4Usage(); // EditorUtility.SetDirty(FR2_Cache.Api); AssetDatabase.Refresh(); IsMergeProcessing = false; } }
public override void OnSelectionChange() { Repaint(); isNoticeIgnore = false; if (!FR2_Cache.isReady) { return; } if (lockSelection) { return; } if (focusedWindow == null) { return; } if (SceneUsesDrawer == null) { InitIfNeeded(); } if (UsesDrawer == null) { InitIfNeeded(); } ids = FR2_Unity.Selection_AssetGUIDs; //ignore selection on asset when selected any object in scene if (Selection.gameObjects.Length > 0 && !FR2_Unity.IsInAsset(Selection.gameObjects[0])) { ids = new string[0]; } level = 0; if (IsFocusingSceneToAsset) { SceneToAssetDrawer.Reset(Selection.gameObjects, true, true); } if (IsFocusingUses) { UsesDrawer.Reset(ids, true); } if (IsFocusingUsedBy) { UsedByDrawer.Reset(ids, false); } if (IsFocusingSceneInScene) { RefSceneInScene.ResetSceneInScene(Selection.gameObjects); } if (IsFocusingUses) { SceneUsesDrawer.ResetSceneUseSceneObjects(Selection.gameObjects); } if (IsFocusingFindInScene) { RefInScene.Reset(ids, this as IWindow); } if (IsFocusingGUIDs) { objs = new Object[ids.Length]; for (var i = 0; i < ids.Length; i++) { objs[i] = FR2_Unity.LoadAssetAtPath <Object> ( AssetDatabase.GUIDToAssetPath(ids[i]) ); } } if (FR2_SceneCache.Api.Dirty && !Application.isPlaying) { FR2_SceneCache.Api.refreshCache(this); } EditorApplication.delayCall -= Repaint; EditorApplication.delayCall += Repaint; }
private void OnUpdate() { for (var i = 0; i < 5 * FR2_Cache.Api.priority; i++) { if (listGO == null || listGO.Count <= 0) { //done // Debug.Log("done"); EditorApplication.update -= OnUpdate; ready = true; Dirty = false; listGO = null; if (onReady != null) { onReady(); } if (window != null) { window.OnSelectionChange(); } return; } int index = listGO.Count - 1; GameObject go = listGO[index]; if (go == null) { continue; } string prefabGUID = FR2_Unity.GetPrefabParent(go); if (!string.IsNullOrEmpty(prefabGUID)) { Transform parent = go.transform.parent; while (parent != null) { GameObject g = parent.gameObject; if (!prefabDependencies.ContainsKey(g)) { prefabDependencies.Add(g, new HashSet <string>()); } prefabDependencies[g].Add(prefabGUID); parent = parent.parent; } } Component[] components = go.GetComponents <Component>(); foreach (Component com in components) { if (com == null) { continue; } var serialized = new SerializedObject(com); SerializedProperty it = serialized.GetIterator().Copy(); while (it.NextVisible(true)) { if (it.propertyType != SerializedPropertyType.ObjectReference) { continue; } if (it.objectReferenceValue == null) { continue; } var isSceneObject = true; string path = AssetDatabase.GetAssetPath(it.objectReferenceValue); if (!string.IsNullOrEmpty(path)) { string dir = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty(dir)) { isSceneObject = false; if (!folderCache.ContainsKey(dir)) { folderCache.Add(dir, new HashSet <Component>()); } if (!folderCache[dir].Contains(com)) { folderCache[dir].Add(com); } } } if (!_cache.ContainsKey(com)) { _cache.Add(com, new HashSet <HashValue>()); } _cache[com].Add(new HashValue { target = it.objectReferenceValue, isSceneObject = isSceneObject }); // if (!_cache.ContainsKey(com)) _cache.Add(com, new HashSet<SerializedProperty>()); // if (!_cache[com].Contains(it)) // _cache[com].Add(it.Copy()); // string path = AssetDatabase.GetAssetPath(it.objectReferenceValue); // if (string.IsNullOrEmpty(path)) continue; // string dir = System.IO.Path.GetDirectoryName(path); // if (string.IsNullOrEmpty(dir)) continue; // if (!folderCache.ContainsKey(dir)) folderCache.Add(dir, new HashSet<Component>()); // if (!folderCache[dir].Contains(com)) // folderCache[dir].Add(com); } } listGO.RemoveAt(index); current++; } }
private static void ApplyFilter(Dictionary <string, FR2_Ref> refs, FR2_Asset asset) { string targetPath = AssetDatabase.GUIDToAssetPath(asset.guid); if (string.IsNullOrEmpty(targetPath)) { return; // asset not found - might be deleted! } //asset being moved! if (targetPath != asset.assetPath) { asset.LoadAssetInfo(); } Object target = AssetDatabase.LoadAssetAtPath(targetPath, typeof(Object)); if (target == null) { Debug.LogWarning("target is null"); return; } bool targetIsGameobject = target is GameObject; if (targetIsGameobject) { foreach (GameObject item in FR2_Unity.getAllObjsInCurScene()) { if (FR2_Unity.CheckIsPrefab(item)) { string itemGUID = FR2_Unity.GetPrefabParent(item); // Debug.Log(item.name + " itemGUID: " + itemGUID); // Debug.Log(target.name + " asset.guid: " + asset.guid); if (itemGUID == asset.guid) { Add(refs, item, 1); } } } } string dir = Path.GetDirectoryName(targetPath); if (FR2_SceneCache.Api.folderCache.ContainsKey(dir)) { foreach (Component item in FR2_SceneCache.Api.folderCache[dir]) { if (FR2_SceneCache.Api.cache.ContainsKey(item)) { foreach (FR2_SceneCache.HashValue item1 in FR2_SceneCache.Api.cache[item]) { if (targetPath == AssetDatabase.GetAssetPath(item1.target)) { Add(refs, item, 1); } } } } } }
//[MenuItem("Assets/FR2/Export Dependencies", false, 40)] private static void ExportDependencies() { Selection.objects = GetSelectionDependencies().ToArray(); FR2_Unity.ExportSelection(); }