private VisualizationNodeData AddNodeCacheForNode(string id, string type) { string key = NodeDependencyLookupUtility.GetNodeKey(id, type); if (!_cachedVisualizationNodeDatas.ContainsKey(key)) { INodeHandler nodeHandler = GetNodeHandlerForType(type); ITypeHandler typeHandler = GetTypeHandlerForType(type); VisualizationNodeData data = typeHandler.CreateNodeCachedData(id); _nodeDependencyLookupContext.NodeHandlerLookup = GetNodeHandlerLookup(); if (_showThumbnails || DisplayData.ShowAdditionalInformation) { data.OwnSize = NodeDependencyLookupUtility.GetNodeSize(true, false, id, type, new HashSet <string>(), _nodeDependencyLookupContext, _cachedSizes); data.HierarchySize = NodeDependencyLookupUtility.GetNodeSize(true, true, id, type, new HashSet <string>(), _nodeDependencyLookupContext, _cachedSizes); } data.Id = id; data.Type = type; data.NodeHandler = nodeHandler; data.TypeHandler = typeHandler; data.Name = typeHandler.GetName(id); data.IsEditorAsset = nodeHandler.IsNodeEditorOnly(id, type); data.IsPackedToApp = NodeDependencyLookupUtility.IsNodePackedToApp(id, type, _nodeDependencyLookupContext, new HashSet <string>()); _cachedVisualizationNodeDatas.Add(key, data); } return(_cachedVisualizationNodeDatas[key]); }
private List <MergedNode> GetMergedNodes(List <Connection> connections) { Dictionary <string, MergedNode> result = new Dictionary <string, MergedNode>(); int i = 0; foreach (Connection connection in connections) { string nodeKey = NodeDependencyLookupUtility.GetNodeKey(connection.Node.Id, connection.Node.Type); if (!MergeRelations.GetValue()) { nodeKey = (i++).ToString(); // leads to nodes not being merged by target } if (!result.ContainsKey(nodeKey)) { result.Add(nodeKey, new MergedNode { Target = connection }); } result[nodeKey].Datas.Add(new VisualizationConnection.Data(connection.Type, connection.PathSegments)); } return(result.Values.ToList()); }
public Texture2D TryGetAssetPreview() { if (!_assetLoaded) { _loadedMainAsset = NodeDependencyLookupUtility.GetMainAssetById(Id); _assetLoaded = true; } if (_loadedMainAsset != null && _assetPreview == null && _assetPreviewRenderTries < MAX_ASSET_PREVIEW_RENDER_RETRIES) { Texture2D previewTexture = AssetPreview.GetAssetPreview(_loadedMainAsset); if (previewTexture != null) { Texture2D copyTexture = new Texture2D(previewTexture.width, previewTexture.height, previewTexture.format, false); Graphics.CopyTexture(previewTexture, copyTexture); _assetPreview = copyTexture; } else { _assetPreviewRenderTries++; } } return(_assetPreview); }
public void CreateNodeHierarchyRec(HashSet <string> addedVisualizationNodes, Stack <VisualizationNode> visualizationNodeStack, VisualizationNode visualizationNode, Connection connection, int depth, RelationType relationType, NodeDisplayOptions nodeDisplayOptions, ref int iterations) { // prevent the tree from becoming too big if (iterations >= 0xFFFF) { return; } iterations++; visualizationNode.Key = NodeDependencyLookupUtility.GetNodeKey(connection.Node.Id, connection.Node.Type); bool containedNode = addedVisualizationNodes.Contains(visualizationNode.Key); if (depth == nodeDisplayOptions.MaxDepth || (containedNode && nodeDisplayOptions.ShowHierarchyOnce)) { return; } if (!nodeDisplayOptions.ConnectionTypesToDisplay.Contains(connection.Type) && connection.Type != "Root") { return; } addedVisualizationNodes.Add(visualizationNode.Key); visualizationNodeStack.Push(visualizationNode); List <MergedNode> mergedNodes = GetMergedNodes(connection.Node.GetRelations(relationType)); foreach (MergedNode mergedNode in mergedNodes) { Node childNode = mergedNode.Target.Node; string childNodeKey = NodeDependencyLookupUtility.GetNodeKey(childNode.Id, childNode.Type); if (addedVisualizationNodes.Contains(childNodeKey) && _nodeDisplayOptions.ShowNodesOnce) { continue; } VisualizationNode recursionNode = HasRecursion(childNodeKey, visualizationNodeStack); bool isRecursion = recursionNode != null; VisualizationNode visualizationChildNode = isRecursion ? recursionNode : GetVisualizationNode(childNode.Id, childNode.Type); visualizationChildNode.IsFiltered = IsNodeFiltered(childNode.Id, childNode.Type); if (!isRecursion) { CreateNodeHierarchyRec(addedVisualizationNodes, visualizationNodeStack, visualizationChildNode, mergedNode.Target, depth + 1, relationType, nodeDisplayOptions, ref iterations); } if (!nodeDisplayOptions.HideFilteredNodes || HasNoneFilteredChildren(visualizationChildNode, relationType)) { visualizationChildNode.HasNoneFilteredChildren = true; AddBidirConnection(relationType, visualizationNode, visualizationChildNode, mergedNode.Datas, isRecursion); } } SortChildNodes(visualizationNode, relationType); visualizationNodeStack.Pop(); }
private bool IsNodeFiltered(string id, string type) { string key = NodeDependencyLookupUtility.GetNodeKey(id, type); VisualizationNodeData nodeData = _cachedVisualizationNodeDatas[key]; ITypeHandler typeHandler = nodeData.TypeHandler; return(typeHandler.HasFilter() && !typeHandler.IsFiltered(nodeData.Id)); }
public List <Dependency> GetDependenciesForId(string id) { if (NodeDependencyLookupUtility.IsResolverActive(_createdDependencyCache, AddressableAssetGroupResolver.Id, ConnectionType)) { return(Lookup[id].Dependencies); } return(new List <Dependency>()); }
public void OnSelectAsset(string id, string type) { if (type == GetHandledType()) { _selectedAsset = NodeDependencyLookupUtility.GetAssetById(id); } else { _selectedAsset = null; } }
private void CreateTypeHandlers() { _typeHandlers.Clear(); List <Type> types = NodeDependencyLookupUtility.GetTypesForBaseType(typeof(ITypeHandler)); foreach (Type type in types) { ITypeHandler typeHandler = NodeDependencyLookupUtility.InstantiateClass <ITypeHandler>(type); _typeHandlers.Add(typeHandler); } }
private void CreateNodeHandlers() { _nodeHandlerStates.Clear(); List <Type> types = NodeDependencyLookupUtility.GetTypesForBaseType(typeof(INodeHandler)); foreach (Type type in types) { INodeHandler nodeHandler = NodeDependencyLookupUtility.InstantiateClass <INodeHandler>(type); _nodeHandlerStates.Add(new NodeHandlerState(nodeHandler)); } }
public void Initialize(AssetDependencyCache cache, HashSet <string> changedAssets, ProgressBase progress) { SubSystem.Clear(); foreach (string assetId in changedAssets) { string guid = NodeDependencyLookupUtility.GetGuidFromAssetId(assetId); if (validGuids.Contains(guid)) { cache._hierarchyTraverser.AddAssetId(assetId, SubSystem); } } }
private void LoadDependencyCache(bool update = true) { _nodeDependencyLookupContext.Reset(); ResolverUsageDefinitionList resolverUsageDefinitionList = CreateCacheUsageList(); ProgressBase progress = new ProgressBase(null); progress.SetProgressFunction((title, info, value) => EditorUtility.DisplayProgressBar(title, info, value)); NodeDependencyLookupUtility.LoadDependencyLookupForCaches(_nodeDependencyLookupContext, resolverUsageDefinitionList, progress, true, update); SetNodeHandlerContext(); }
public override Result GetDependency(Type objType, object obj, SerializedProperty property, string propertyPath, SerializedPropertyType type, Stack <PathSegment> stack) { if (obj != null && IsType(obj.GetType(), AddressableType)) { AssetReference assetReference = obj as AssetReference; if (assetReference != null && assetReference.editorAsset != null) { string assetId = NodeDependencyLookupUtility.GetAssetIdForAsset(assetReference.editorAsset); return(new Result { Id = assetId, NodeType = NodeType, ConnectionType = ResolvedTypeAddressable }); } } return(null); }
public string GetName(string id) { Object asset = NodeDependencyLookupUtility.GetAssetById(id); string guid = NodeDependencyLookupUtility.GetGuidFromAssetId(id); string path = AssetDatabase.GUIDToAssetPath(guid); if (asset != null) { return($"{asset.name}"); } if (!string.IsNullOrEmpty(path)) { return(path); } return(id); }
public void SelectInEditor(string id) { string guid = NodeDependencyLookupUtility.GetGuidFromAssetId(id); long fileId = long.Parse(NodeDependencyLookupUtility.GetFileIdFromAssetId(id)); string path = AssetDatabase.GUIDToAssetPath(guid); Object[] allAssets = NodeDependencyLookupUtility.LoadAllAssetsAtPath(path); foreach (Object asset in allAssets) { AssetDatabase.TryGetGUIDAndLocalFileIdentifier(asset, out string aguid, out long afileId); if (afileId == fileId) { Selection.activeObject = asset; } } }
private Texture2D GetThumbnail() { if (_thumbNail == null) { string path = AssetDatabase.GUIDToAssetPath(NodeDependencyLookupUtility.GetGuidFromAssetId(Id)); _thumbNail = AssetDatabase.GetCachedIcon(path) as Texture2D; if (_thumbNail == null) { _thumbNail = AssetPreview.GetMiniTypeThumbnail(AssetDatabase.GetMainAssetTypeAtPath(path)); } if (_thumbNail == null) { _thumbNail = AssetPreview.GetMiniTypeThumbnail(typeof(Object)); } } return(_thumbNail); }
public void Update(ProgressBase progress) { AddressableAssetSettings settings = UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings; if (settings == null) { return; } Lookup.Clear(); Nodes = new IResolvedNode[0]; List <IResolvedNode> nodes = new List <IResolvedNode>(); foreach (AddressableAssetGroup group in settings.groups) { AddressableAssetGroupDependencyNode node = new AddressableAssetGroupDependencyNode(); node.groupId = group.Name; int i = 0; foreach (AddressableAssetEntry addressableAssetEntry in group.entries) { List <AddressableAssetEntry> entries = new List <AddressableAssetEntry>(); addressableAssetEntry.GatherAllAssets(entries, true, true, false); foreach (AddressableAssetEntry assetEntry in entries) { string assetId = NodeDependencyLookupUtility.GetAssetIdForAsset(assetEntry.MainAsset); string componentName = "GroupUsage " + i++; node.Dependencies.Add(new Dependency(assetId, "AddressableGroupUsage", "Asset", new [] { new PathSegment(componentName, PathSegmentType.Property), })); } } nodes.Add(node); Lookup.Add(node.Id, node); } Nodes = nodes.ToArray(); }
private void DisplayFilterOptions() { EditorGUILayout.BeginVertical(); Object newSelectedAsset = EditorGUILayout.ObjectField(_selectedAsset, typeof(Object), false); if (newSelectedAsset != _selectedAsset) { string fileId = NodeDependencyLookupUtility.GetAssetIdForAsset(newSelectedAsset); _viewerWindow.ChangeSelection(fileId, GetHandledType()); _selectedAsset = newSelectedAsset; } float origWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 50; _filterString.DirtyOnChange(EditorGUILayout.TextField("Filter:", _filterString, GUILayout.MinWidth(200))); EditorGUIUtility.labelWidth = origWidth; if (GUILayout.Button("Apply")) { _filteredNodes = CreateFilter(_filterString); _viewerWindow.InvalidateNodeStructure(); } AssetRelationsViewerWindow.TogglePref(_explorerSyncModePref, "Sync to explorer:", b => { if (b) { RegisterOnSelectionChanged(); } else { UnregisterOnSelectionChanged(); } }); EditorGUILayout.EndVertical(); }
private void DrawBasicOptions() { GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); GUI.enabled = _undoSteps.Count >= 2; if (GUILayout.Button("<<")) { UndoSelection(); } GUI.enabled = true; GUILayout.EndHorizontal(); IntSliderPref(DisplayData.AssetPreviewSize, "ThumbnailSize:", i => InvalidateTreeVisualization()); IntSliderPref(_nodeDisplayOptions.MaxDepth, "NodeDepth:", i => InvalidateNodeStructure()); if (GUILayout.Button("Refresh")) { ReloadContext(); } if (GUILayout.Button("Save and Refresh")) { AssetDatabase.SaveAssets(); ReloadContext(); } if (GUILayout.Button("Clear and refresh")) { AssetDatabase.SaveAssets(); NodeDependencyLookupUtility.ClearCachedContexts(); NodeDependencyLookupUtility.ClearCacheFiles(); _nodeDependencyLookupContext.CreatedCaches.Clear(); ReloadContext(); } GUILayout.EndVertical(); }
private void CreateCacheStates() { _cacheStates.Clear(); List <Type> types = NodeDependencyLookupUtility.GetTypesForBaseType(typeof(IDependencyCache)); foreach (Type type in types) { IDependencyCache cache = NodeDependencyLookupUtility.InstantiateClass <IDependencyCache>(type); var cacheState = new CacheState(cache); List <Type> resolverTypes = NodeDependencyLookupUtility.GetTypesForBaseType(cache.GetResolverType()); foreach (Type rtype in resolverTypes) { IDependencyResolver dependencyResolver = NodeDependencyLookupUtility.InstantiateClass <IDependencyResolver>(rtype); cacheState.ResolverStates.Add(new ResolverState(dependencyResolver)); } _cacheStates.Add(cacheState); } }
public int GetOwnFileSize(string id, string type, NodeDependencyLookupContext stateContext) { return(NodeDependencyLookupUtility.GetNodeSize(false, true, id, type, new HashSet <string>(), stateContext)); }