Exemplo n.º 1
0
        public override IDeclaredElement Analyze(IDeclaration element, IHighlightingConsumer consumer, DaemonProcessKind kind)
        {
            if (!(element is IFieldDeclaration field))
            {
                return(null);
            }

            var declaredElement = field.DeclaredElement;

            if (declaredElement == null)
            {
                return(null);
            }

            bool isSerializedField = myUnityApi.IsSerialisedField(declaredElement);

            if (isSerializedField)
            {
                const string displayText = "Serializable";
                const string baseTooltip = "This field is initialized from Inspector";
                if (myUnityApi.IsDescendantOfMonoBehaviour(declaredElement.GetContainingType()))
                {
                    AddMonoBehaviourHighlighting(consumer, field, displayText, baseTooltip, kind);
                    return(declaredElement);
                }
                else if (myUnityApi.IsDescendantOfScriptableObject(declaredElement.GetContainingType()))
                {
                    AddScriptableObjectHighlighting(consumer, field, displayText, baseTooltip, kind);
                    return(declaredElement);
                }
                else if (myUnityApi.IsInjectedField(declaredElement))
                {
                    AddECSHighlighting(consumer, field, displayText, "This field is injected by Unity", kind);
                    return(declaredElement);
                }
                else
                {
                    AddSerializableHighlighting(consumer, field, displayText, "This field is serialized by Unity", kind);
                }

                return(null);
            }

            return(null);
        }
Exemplo n.º 2
0
        public override bool AddDeclarationHighlighting(IDeclaration element, IHighlightingConsumer consumer, DaemonProcessKind kind)
        {
            if (!(element is IFieldDeclaration field))
            {
                return(false);
            }

            var declaredElement = field.DeclaredElement;

            if (declaredElement == null)
            {
                return(false);
            }

            bool isSerializedField = myUnityApi.IsSerialisedField(declaredElement);

            if (isSerializedField)
            {
                const string displayText    = "Serializable";
                const string baseTooltip    = "This field is initialized from Inspector";
                var          containingType = declaredElement.GetContainingType();
                if (containingType.DerivesFromMonoBehaviour() || containingType.DerivesFromScriptableObject())
                {
                    AddMonoBehaviourHighlighting(consumer, field, displayText, baseTooltip, kind);
                    return(true);
                }

                if (myUnityApi.IsInjectedField(declaredElement))
                {
                    AddECSHighlighting(consumer, field, displayText, "This field is injected by Unity", kind);
                    return(true);
                }

                AddSerializableHighlighting(consumer, field, displayText, "This field is serialized by Unity", kind);
                return(false);
            }

            return(false);
        }
Exemplo n.º 3
0
        public IDeclaredElement Analyze(IDeclaration element, IHighlightingConsumer consumer, DaemonProcessKind kind)
        {
            if (!(element is IFieldDeclaration field))
            {
                return(null);
            }

            var declaredElement = field.DeclaredElement;

            if (declaredElement == null)
            {
                return(null);
            }

            bool isSerializedField = myUnityApi.IsSerialisedField(declaredElement);

            if (isSerializedField && (
                    myUnityApi.IsDescendantOfMonoBehaviour(declaredElement.GetContainingType()) ||
                    myUnityApi.IsDescendantOfScriptableObject(declaredElement.GetContainingType())
                    ) ||
                myUnityApi.IsInjectedField(declaredElement))
            {
                myImplicitUsageHighlightingContributor.AddUnityImplicitFieldUsage(consumer, field,
                                                                                  "This field is initialised by Unity", "Set by Unity", kind);

                return(declaredElement);
            }

            if (isSerializedField && declaredElement.GetAttributeInstances(false)
                .All(t => !t.GetClrName().Equals(KnownTypes.SerializeField)))
            {
                myImplicitUsageHighlightingContributor.AddUnityImplicitFieldUsage(consumer, field,
                                                                                  "This field is serialized by Unity", "Serializable", kind);
                return(declaredElement);
            }

            return(null);
        }