Example #1
0
        private string GetReferenceName(ISolution solution, IPsiSourceFile file)
        {
            const string unknownResult = "...";

            var pathProvider = solution.GetComponent <UnitySceneDataLocalCache>();
            var consumer     = new UnityPathCachedSceneConsumer();

            var gameObjectFile = file;

            if (Reference.guid != null)
            {
                var module = file.PsiModule as UnityExternalFilesPsiModule;
                Assertion.Assert(module != null, "module != null");
                var guidCache = solution.GetComponent <MetaFileGuidCache>();
                var filePath  = guidCache.GetAssetFilePathsFromGuid(Reference.guid).FirstOrDefault(null);
                if (filePath == null)
                {
                    return(unknownResult);
                }

                if (!module.TryGetFileByPath(filePath, out gameObjectFile))
                {
                    return(unknownResult);
                }
            }


            pathProvider.ProcessSceneHierarchyFromComponentToRoot(gameObjectFile, Reference.fileID, consumer);

            var parts = consumer.NameParts;

            if (parts.Count == 0)
            {
                var cache = solution.GetComponent <UnityGameObjectNamesCache>();
                if (cache.Map.TryGetValue(gameObjectFile, out var anchorToName))
                {
                    if (anchorToName.TryGetValue(Reference.fileID, out var name))
                    {
                        return(name);
                    }
                }
                return("...");
            }

            return(parts[parts.Count - 1]);
        }
Example #2
0
        public virtual string GetOwnerPresentation(ISolution solution, IPsiSourceFile file)
        {
            const string unknownResult = "...";

            var pathProvider = solution.GetComponent <UnitySceneDataLocalCache>();
            var consumer     = new UnityPathCachedSceneConsumer();

            pathProvider.ProcessSceneHierarchyFromComponentToRoot(file, LocalGameObjectAnchor, consumer);
            var parts = consumer.NameParts;

            if (parts.Count == 0)
            {
                return(unknownResult);
            }


            return($"{StringUtil.DropMiddleIfLong(parts[parts.Count - 1], 30)}");
        }