public IEnumerable <UnityInspectorFindResult> GetAssetUsagesFor(IPsiSourceFile sourceFile, IField element)
        {
            myShellLocks.AssertReadAccessAllowed();


            var containingType = element?.GetContainingType();

            if (containingType == null)
            {
                yield break;
            }

            var names = AssetUtils.GetAllNamesFor(element).ToJetHashSet();

            foreach (var(usage, isPrefabModification) in GetUsages(sourceFile))
            {
                if (!names.Contains(usage.Name))
                {
                    continue;
                }
                var scriptReference = usage.ScriptReference;
                var guid            = scriptReference.ExternalAssetGuid;

                var typeElement = AssetUtils.GetTypeElementFromScriptAssetGuid(element.GetSolution(), guid);
                if (typeElement == null || !typeElement.IsDescendantOf(containingType))
                {
                    continue;
                }

                yield return(new UnityInspectorFindResult(sourceFile, element, usage, usage.Location, isPrefabModification));
            }
        }
Beispiel #2
0
        private IEnumerable <(LocalReference owningScriptLocation, AssetMethodUsages methodData)> GetImportedAssetMethodDataFor(IPsiSourceFile psiSourceFile)
        {
            if (myImportedUnityEventDatas.TryGetValue(psiSourceFile, out var importedUnityEventData))
            {
                foreach (var((location, unityEventName), modifiedEvents) in importedUnityEventData.UnityEventToModifiedIndex)
                {
                    var script = myAssetDocumentHierarchyElementContainer.GetHierarchyElement(location, true) as IScriptComponentHierarchy;
                    Assertion.Assert(script != null, "script != null");
                    var scriptType = AssetUtils.GetTypeElementFromScriptAssetGuid(mySolution, script.ScriptReference.ExternalAssetGuid);
                    var field      = scriptType?.GetMembers().FirstOrDefault(t => t is IField f && AssetUtils.GetAllNamesFor(f).Contains(unityEventName)) as IField;
                    if (field == null)
                    {
                        continue;
                    }

                    var names         = AssetUtils.GetAllNamesFor(field).ToJetHashSet();
                    var modifications = script.ImportUnityEventData(this, names);

                    foreach (var index in modifiedEvents)
                    {
                        Assertion.Assert(index < modifications.Count, "index < modifications.Count");
                        var result = AssetMethodUsages.TryCreateAssetMethodFromModifications(location, unityEventName, modifications[index]);
                        if (result != null)
                        {
                            yield return(location, result);
                        }
                    }
                }
            }
        }
        public LocalList <IPsiSourceFile> GetPossibleFilesWithUsage(IField element)
        {
            var result = new LocalList <IPsiSourceFile>();

            foreach (var name in AssetUtils.GetAllNamesFor(element))
            {
                foreach (var sourceFile in myNameToSourceFile.GetValues(name))
                {
                    result.Add(sourceFile);
                }
            }

            return(result);
        }
Beispiel #4
0
        public IEnumerable <InspectorVariableUsage> GetAssetUsagesFor(IPsiSourceFile sourceFile, IField element)
        {
            myShellLocks.AssertReadAccessAllowed();

            var containingType = element?.GetContainingType();

            if (containingType == null)
            {
                return(Enumerable.Empty <InspectorVariableUsage>());
            }

            var result = new List <InspectorVariableUsage>();

            if (!myPsiSourceFileToInspectorValues.TryGetValue(sourceFile, out var usages))
            {
                return(EmptyList <InspectorVariableUsage> .Enumerable);
            }

            foreach (var name in AssetUtils.GetAllNamesFor(element))
            {
                var usagesData = usages.GetValuesSafe(name);
                foreach (var usage in usagesData)
                {
                    var guid = (usage.ScriptReference as ExternalReference)?.ExternalAssetGuid;
                    if (guid == null)
                    {
                        continue;
                    }

                    var typeElement = AssetUtils.GetTypeElementFromScriptAssetGuid(element.GetSolution(), guid);
                    if (typeElement == null || !typeElement.IsDescendantOf(containingType))
                    {
                        continue;
                    }

                    result.Add(usage);
                }
            }

            return(result);
        }