public override RdUsageGroup CreateModel(IOccurrence occurrence, IOccurrenceBrowserDescriptor descriptor) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { if (occurrence is UnityAssetOccurrence assetOccurrence && !assetOccurrence.SourceFile.GetLocation().IsAsset()) { using (ReadLockCookie.Create()) { var solution = occurrence.GetSolution(); var processor = solution.GetComponent <AssetHierarchyProcessor>(); var consumer = new UnityScenePathGameObjectConsumer(); processor.ProcessSceneHierarchyFromComponentToRoot(assetOccurrence.OwningElementLocation, consumer, true, true); string name = "..."; if (consumer.NameParts.Count > 0) { name = string.Join("\\", consumer.NameParts); } return(CreateModel(name)); } } } return(EmptyModel()); }
public string GetPresentation(ISolution solution, IDeclaredElement declaredElement, bool prefabImport) { solution.GetComponent <IShellLocks>().AssertReadAccessAllowed(); var hierarchyContainer = solution.GetComponent <AssetDocumentHierarchyElementContainer>(); if (UnityApi.IsDescendantOfScriptableObject((declaredElement as IField)?.Type.GetTypeElement())) { if (Reference is LocalReference localReference && localReference.LocalDocumentAnchor == 0) { return("None"); } var sourceFile = hierarchyContainer.GetSourceFile(Reference, out _); if (sourceFile == null) { return("..."); } var relativePath = sourceFile.DisplayName.Replace('\\', '/').RemoveStart("Assets/"); return(relativePath); } if (Reference.LocalDocumentAnchor == 0) { return("None"); } var processor = solution.GetComponent <AssetHierarchyProcessor>(); var consumer = new UnityScenePathGameObjectConsumer(true); var element = hierarchyContainer.GetHierarchyElement(Reference, prefabImport); if (element == null) { return("..."); } string result = ""; if (!element.IsStripped) { processor.ProcessSceneHierarchyFromComponentToRoot(element, consumer, prefabImport); if (consumer.NameParts.Count == 0) { return("..."); } result += string.Join("/", consumer.NameParts); } if (element is IComponentHierarchy componentHierarchy) { result += $" ({AssetUtils.GetComponentName(solution.GetComponent<MetaFileGuidCache>(), componentHierarchy)})"; } return(result); }
private string GetAttachedGameObjectName(AssetHierarchyProcessor processor, UnityAssetOccurrence occurrence) { var consumer = new UnityScenePathGameObjectConsumer(); processor.ProcessSceneHierarchyFromComponentToRoot(occurrence.AttachedElementLocation, consumer, true, true); var parts = consumer.NameParts; if (parts.Count == 0) { return("..."); } return(string.Join("/", consumer.NameParts)); }
private static AssetFindUsagesResultBase CreateRequest(FileSystemPath solutionDirPath, AssetHierarchyProcessor assetDocumentHierarchy, LocalReference location, IPsiSourceFile sourceFile, bool needExpand = false) { if (!GetPathFromAssetFolder(solutionDirPath, sourceFile, out var pathFromAsset, out var fileName, out var extension)) { return(null); } if (sourceFile.GetLocation().ExtensionWithDot.EndsWith(UnityYamlFileExtensions.AssetFileExtensionWithDot)) { return(new AssetFindUsagesResult(needExpand, pathFromAsset, fileName, extension)); } var consumer = new UnityScenePathGameObjectConsumer(); assetDocumentHierarchy.ProcessSceneHierarchyFromComponentToRoot(location, consumer, true, true); return(new HierarchyFindUsagesResult(consumer.NameParts.ToArray(), consumer.RootIndexes.ToArray(), needExpand, pathFromAsset, fileName, extension)); }
private static AssetFindUsagesResultBase CreateRequest(FileSystemPath solutionDirPath, AssetHierarchyProcessor assetDocumentHierarchy, [NotNull] AnimatorScriptUsagesElementContainer animatorContainer, LocalReference location, IPsiSourceFile sourceFile, [NotNull] IDeclaredElement declaredElement, bool needExpand = false) { if (!GetPathFromAssetFolder(solutionDirPath, sourceFile, out var pathFromAsset, out var fileName, out var extension)) { return(null); } var path = sourceFile.GetLocation(); if (path.IsControllerFile() && animatorContainer.GetElementsNames(location, declaredElement, out var names, out var isStateMachine) && names != null) { return(new AnimatorFindUsagesResult(names, isStateMachine ? AnimatorUsageType.StateMachine : AnimatorUsageType.State, needExpand, pathFromAsset, fileName, extension)); } if (path.ExtensionWithDot.EndsWith(UnityYamlFileExtensions.AssetFileExtensionWithDot)) { return(new AssetFindUsagesResult(needExpand, pathFromAsset, fileName, extension)); } if (path.IsAnimFile()) { return(new AnimationFindUsagesResult(needExpand, pathFromAsset, fileName, extension)); } var consumer = new UnityScenePathGameObjectConsumer(); assetDocumentHierarchy.ProcessSceneHierarchyFromComponentToRoot(location, consumer, true, true); return(new HierarchyFindUsagesResult(consumer.NameParts.ToArray(), consumer.RootIndexes.ToArray(), needExpand, pathFromAsset, fileName, extension)); }