public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }


            // If YAML parsing is disabled, this will return null
            var file = sourceFile.GetDominantPsiFile <UnityYamlLanguage>() as IUnityYamlFile;

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

            var result = new Dictionary <string, string>();

            foreach (var document in file.Documents)
            {
                var buffer = document.GetTextAsBuffer();
                if (ourGameObjectReferenceStringSearcher.Find(buffer, 0, Math.Min(100, buffer.Length)) >= 0)
                {
                    var anchor = UnitySceneDataUtil.GetAnchorFromBuffer(buffer);
                    if (anchor == null)
                    {
                        continue;
                    }

                    var name = GetNameFromBuffer(buffer);
                    if (name == null)
                    {
                        continue;
                    }
                    result[anchor] = name;
                }
                else
                {
                    FillDictionary(result, buffer);
                }
            }

            foreach (var componentDocument in file.ComponentDocuments)
            {
                FillDictionary(result, componentDocument.GetTextAsBuffer());
            }

            if (result.Count == 0)
            {
                return(null);
            }
            return(result);
        }
Exemple #2
0
        public void ProcessSceneHierarchyFromComponentToRoot(IYamlDocument startComponent, IUnityCachedSceneProcessorConsumer consumer)
        {
            myShellLocks.AssertReadAccessAllowed();

            var sourceFile = startComponent.GetSourceFile();
            var anchor     = UnitySceneDataUtil.GetAnchorFromBuffer(startComponent.GetTextAsBuffer());

            if (sourceFile == null || anchor == null)
            {
                return;
            }

            ProcessSceneHierarchyFromComponentToRoot(sourceFile, new FileID(null, anchor), consumer);
        }
        private void FillDictionary(Dictionary <string, string> result, IBuffer buffer)
        {
            var anchor = UnitySceneDataUtil.GetAnchorFromBuffer(buffer);

            if (anchor == null)
            {
                return;
            }

            var name = GetComponentNameFromBuffer(buffer);

            if (name == null)
            {
                return;
            }

            result[anchor] = name;
        }
Exemple #4
0
        public void AddPrefabModification(IBuffer buffer)
        {
            var anchor = UnitySceneDataUtil.GetAnchorFromBuffer(buffer);

            if (anchor == null)
            {
                return;
            }

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

            lexer.Start();

            TokenNodeType currentToken;

            var transformParentId = FileID.Null;

            while ((currentToken = lexer.TokenType) != null)
            {
                if (currentToken == YamlTokenType.INDENT)
                {
                    var indentSize = lexer.TokenEnd - lexer.TokenStart;
                    lexer.Advance();
                    currentToken = lexer.TokenType;

                    if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_IN)
                    {
                        var text = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd));
                        if (text.Equals(UnityYamlConstants.TransformParentProperty))
                        {
                            lexer.Advance();
                            UnitySceneDataUtil.SkipWhitespace(lexer);
                            currentToken = lexer.TokenType;

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

                                var result = UnitySceneDataUtil.GetFileId(buffer, lexer);
                                if (result != null)
                                {
                                    transformParentId = result;
                                }
                            }
                        }
                        else if (text.Equals(UnityYamlConstants.ModificationsProperty))
                        {
                            var names       = new Dictionary <FileID, string>();
                            var rootIndexes = new Dictionary <FileID, int?>();
                            GetModifications(buffer, lexer, indentSize, names, rootIndexes);
                            var id = new FileID(null, anchor);
                            Elements.Add(id,
                                         new ModificationHierarchyElement(id, null, null, false, transformParentId, rootIndexes, names));
                            return;
                        }
                    }
                }
                else
                {
                    lexer.Advance();
                }
            }
        }