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); }
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); } } } } } }
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++; } }