public bool ProcessProjectItem <TResult>(IPsiSourceFile sourceFile, IFindResultConsumer <TResult> consumer)
        {
            if (!myDeferredCacheController.CompletedOnce.Value)
            {
                return(false);
            }

            foreach (var element in myElements)
            {
                if (element is IMethod || element is IProperty)
                {
                    var usages = myUnityEventsElementContainer.GetAssetUsagesFor(sourceFile, element);
                    foreach (var findResult in usages)
                    {
                        consumer.Accept(findResult);
                    }
                }

                if (element is ITypeElement typeElement)
                {
                    var usages = myAssetScriptUsagesElementContainer.GetAssetUsagesFor(sourceFile, typeElement);

                    foreach (var assetUsage in usages)
                    {
                        consumer.Accept(new UnityScriptsFindResults(sourceFile, element, assetUsage, assetUsage.Location));
                    }
                }

                if (element is IField field)
                {
                    if (UnityApi.IsDescendantOfUnityEvent(field.Type.GetTypeElement()))
                    {
                        foreach (var findResult in myUnityEventsElementContainer.GetMethodsForUnityEvent(sourceFile, field))
                        {
                            consumer.Accept(findResult);
                        }
                    }
                    else
                    {
                        var usages = myAssetInspectorValuesContainer.GetAssetUsagesFor(sourceFile, field);
                        foreach (var findResult in usages)
                        {
                            consumer.Accept(findResult);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        // Return a context object for the item being searched for, or null if the element isn't interesting.
        // CanContainReferences isn't called if we return null. Do the work once here, then use it multiple times for
        // each file in CanContainReferences
        public object GetElementId(IDeclaredElement element)
        {
            if (!UnityYamlUsageSearchFactory.IsInterestingElement(element))
            {
                return(null);
            }

            var set = new JetHashSet <IPsiSourceFile>();

            switch (element)
            {
            case IClass _class:
                foreach (var sourceFile in myAssetScriptUsagesElementContainer.GetPossibleFilesWithUsage(_class))
                {
                    set.Add(sourceFile);
                }
                break;

            case IProperty _:
            case IMethod _:
                foreach (var sourceFile in myUnityEventsElementContainer.GetPossibleFilesWithUsage(element))
                {
                    set.Add(sourceFile);
                }
                break;

            case IField field:
                if (UnityApi.IsDescendantOfUnityEvent(field.Type.GetTypeElement()))
                {
                    foreach (var sourceFile in myUnityEventsElementContainer.GetPossibleFilesWithUsage(element))
                    {
                        set.Add(sourceFile);
                    }
                }
                else
                {
                    foreach (var sourceFile in myInspectorValuesContainer.GetPossibleFilesWithUsage(field))
                    {
                        set.Add(sourceFile);
                    }
                }

                break;
            }

            return(new UnityYamlSearchGuruId(set));
        }
Exemplo n.º 3
0
        private UnityPresentationType GetUnityPresentationType(IType type)
        {
            if (UnityApi.IsDescendantOfUnityEvent(type.GetTypeElement()))
            {
                return(UnityPresentationType.UnityEvent);
            }

            if (UnityApi.IsDescendantOfScriptableObject(type.GetTypeElement()))
            {
                return(UnityPresentationType.ScriptableObject);
            }
            if (type.IsBool())
            {
                return(UnityPresentationType.Bool);
            }
            if (type.IsEnumType())
            {
                return(UnityPresentationType.Enum);
            }
            if (type.IsString())
            {
                return(UnityPresentationType.String);
            }

            if (type.IsSimplePredefined())
            {
                return(UnityPresentationType.OtherSimple);
            }

            if (type.IsValueType())
            {
                return(UnityPresentationType.ValueType);
            }

            if (IsSerializedViaFileId(type))
            {
                return(UnityPresentationType.FileId);
            }

            return(UnityPresentationType.Other);
        }