Example #1
0
 public static bool IsTransform(IBuffer buffer) =>
 ourTransformSearcher.Find(buffer, 0, Math.Min(buffer.Length, 30)) >= 0 ||
 ourRectTransformSearcher.Find(buffer, 0, Math.Min(buffer.Length, 30)) >= 0;
Example #2
0
 public static bool IsGameObject(IBuffer buffer) =>
 ourGameObjectSearcher.Find(buffer, 0, Math.Min(buffer.Length, 30)) >= 0;
Example #3
0
 public static bool IsReferenceValue(IBuffer buffer) =>
 ourFileIdCheck.Find(buffer, 0, Math.Min(buffer.Length, 30)) >= 0;
Example #4
0
 public static bool IsPrefabModification(IBuffer buffer) =>
 ourPrefabModificationSearcher.Find(buffer, 0, Math.Min(buffer.Length, 30)) >= 0;
 public static bool CanContainReference(IBuffer bodyBuffer)
 {
     return(ourMonoBehaviourTagSearcher.Find(bodyBuffer, 0, Math.Min(100, bodyBuffer.Length)) >= 0 &&
            ourMethodNameSearcher.Find(bodyBuffer) >= 0);
 }
Example #6
0
 public static bool IsMonoBehaviourDocument(IBuffer buffer) =>
 ourMonoBehaviourCheck.Find(buffer, 0, Math.Min(buffer.Length, 20)) >= 0;
Example #7
0
 public static bool IsStripped(IBuffer buffer) =>
 ourStrippedSearcher.Find(buffer, 0, Math.Min(buffer.Length, 150)) >= 0;
Example #8
0
 public static bool CanContainReference(IBuffer bodyBuffer)
 {
     return(ourMethodNameSearcher.Find(bodyBuffer) >= 0);
 }
        public IUnityAssetDataElement Build(SeldomInterruptChecker checker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument)
        {
            var buffer = assetDocument.Buffer;

            if (ourMethodNameSearcher.Find(buffer) < 0)
            {
                return(null);
            }

            var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer);

            if (!anchorRaw.HasValue)
            {
                return(null);
            }

            var anchor = anchorRaw.Value;

            var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries;

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

            var result = new List <AssetMethodData>();

            foreach (var entry in entries)
            {
                if (ourMethodNameSearcher.Find(entry.Content.GetTextAsBuffer()) >= 0)
                {
                    var rootMap            = entry.Content.Value as IBlockMappingNode;
                    var persistentCallsMap = rootMap.GetValue("m_PersistentCalls") as IBlockMappingNode;
                    var mCalls             = persistentCallsMap.GetValue("m_Calls") as IBlockSequenceNode;
                    if (mCalls == null)
                    {
                        return(null);
                    }

                    var eventTypeName = rootMap.GetValue("m_TypeName").GetPlainScalarText();

                    foreach (var call in mCalls.Entries)
                    {
                        var methodDescription = call.Value as IBlockMappingNode;
                        if (methodDescription == null)
                        {
                            continue;
                        }

                        var fileID = methodDescription.FindMapEntryBySimpleKey("m_Target")?.Content.Value.AsFileID();
                        if (fileID == null || fileID.IsNullReference)
                        {
                            continue;
                        }

                        var methodNameNode = methodDescription.GetValue("m_MethodName");
                        var methodName     = methodNameNode?.GetPlainScalarText();
                        if (methodName == null)
                        {
                            continue;
                        }

                        var methodNameRange = methodNameNode.GetTreeTextRange();

                        var arguments = methodDescription.GetValue("m_Arguments") as IBlockMappingNode;
                        var modeText  = methodDescription.GetValue("m_Mode")?.GetPlainScalarText();
                        var argMode   = EventHandlerArgumentMode.EventDefined;
                        if (int.TryParse(modeText, out var mode))
                        {
                            if (1 <= mode && mode <= 6)
                            {
                                argMode = (EventHandlerArgumentMode)mode;
                            }
                        }

                        var argumentTypeName = arguments.GetValue("m_ObjectArgumentAssemblyTypeName")?.GetPlainScalarText();

                        var type = argumentTypeName?.Split(',').FirstOrDefault();
                        if (argMode == EventHandlerArgumentMode.EventDefined)
                        {
                            type = eventTypeName?.Split(',').FirstOrDefault();
                        }
                        else if (argMode == EventHandlerArgumentMode.Void)
                        {
                            type = null;
                        }

                        var range = new TextRange(assetDocument.StartOffset + methodNameRange.StartOffset.Offset,
                                                  assetDocument.StartOffset + methodNameRange.EndOffset.Offset);

                        var target = fileID.ToReference(currentSourceFile);
                        if (target != null)
                        {
                            result.Add(new AssetMethodData(
                                           new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor), methodName,
                                           range,
                                           argMode, type, target));
                        }
                    }
                }
            }

            if (result.Count > 0)
            {
                return(new AssetMethodsDataElement(result));
            }
            return(null);
        }
 public static bool CanContainReference(IBuffer bodyBuffer)
 {
     return(ourScriptReferenceStringSearcher.Find(bodyBuffer) >= 0);
 }
        public static void ExtractSimpleAndReferenceValues(IBuffer buffer, Dictionary <string, string> simpleValues, Dictionary <string, FileID> referenceValues, OneToSetMap <string, FileID> eventHandlerToScriptTarget)
        {
            // special field for accessing anchor id
            simpleValues["&anchor"] = GetAnchorFromBuffer(buffer);

            var lexer = new YamlLexer(buffer, true, false);

            lexer.Start();

            TokenNodeType currentToken;
            bool          noColon = true;

            while ((currentToken = lexer.TokenType) != null)
            {
                if (noColon)
                {
                    if (currentToken == YamlTokenType.COLON)
                    {
                        noColon = false;
                    }

                    if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_OUT)
                    {
                        var key = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd));

                        // special filed for checking stripped documents
                        if (key.Equals("stripped"))
                        {
                            simpleValues["stripped"] = "1";
                        }
                    }
                }

                if (currentToken == YamlTokenType.INDENT)
                {
                    lexer.Advance();
                    currentToken = lexer.TokenType;
                    if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_IN)
                    {
                        var key = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd));

                        lexer.Advance();
                        SkipWhitespace(lexer);

                        currentToken = lexer.TokenType;
                        if (currentToken == YamlTokenType.COLON)
                        {
                            lexer.Advance();
                            SkipWhitespace(lexer);

                            currentToken = lexer.TokenType;
                            if (currentToken == YamlTokenType.LBRACE)
                            {
                                lexer.Advance();
                                var result = GetFileIdInner(buffer, lexer);
                                if (result != null)
                                {
                                    referenceValues[key] = result;
                                }
                            }
                            else if (YamlTokenType.CHAMELEON_BLOCK_MAPPING_ENTRY_CONTENT_WITH_ANY_INDENT.Equals(currentToken))
                            {
                                var chameleonBuffer = ProjectedBuffer.Create(buffer, new TextRange(lexer.TokenStart, lexer.TokenEnd));
                                if (ourStringSearcher.Find(chameleonBuffer, 0, Math.Min(chameleonBuffer.Length, 150)) > 0)
                                {
                                    FillTargetAndMethod(chameleonBuffer, eventHandlerToScriptTarget);
                                }
                                else
                                {
                                    // sometimes, FileId is multiline
                                    var result = GetFileId(chameleonBuffer);
                                    if (result != null)
                                    {
                                        referenceValues[key] = result;
                                    }
                                }
                            }
                            else
                            {
                                var result = GetPrimitiveValue(buffer, lexer);
                                if (result != null)
                                {
                                    simpleValues[key] = result;
                                }
                            }
                        }
                    }
                    else
                    {
                        FindNextIndent(lexer);
                    }
                }
                else
                {
                    lexer.Advance();
                }
            }
        }