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); }
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; }
public static UnitySceneData Build(IUnityYamlFile file) { Assertion.Assert(file.IsValid(), "file.IsValid()"); Assertion.Assert(file.GetSolution().Locks.IsReadAccessAllowed(), "ReadLock is required"); var interruptChecker = new SeldomInterruptChecker(); var unityPropertyValueCacheItem = new OneToListMap <MonoBehaviourProperty, MonoBehaviourPropertyValue>(); var sceneHierarchy = new SceneHierarchy(); var anchorToEventHandler = new OneToSetMap <string, string>(); var scriptMapping = new OneToSetMap <string, string>(); var eventHandlerToScriptTarget = new OneToSetMap <string, FileID>(); foreach (var document in file.DocumentsEnumerable) { interruptChecker.CheckForInterrupt(); var buffer = document.GetTextAsBuffer(); if (ourPrefabModificationSearcher.Find(buffer, 0, Math.Min(buffer.Length, 100)) > 0) { sceneHierarchy.AddPrefabModification(buffer); } else { var simpleValues = new Dictionary <string, string>(); var referenceValues = new Dictionary <string, FileID>(); UnitySceneDataUtil.ExtractSimpleAndReferenceValues(buffer, simpleValues, referenceValues, eventHandlerToScriptTarget); FillProperties(simpleValues, referenceValues, unityPropertyValueCacheItem); FillScriptMapping(simpleValues, referenceValues, scriptMapping); sceneHierarchy.AddSceneHierarchyElement(simpleValues, referenceValues); } } if (unityPropertyValueCacheItem.Count == 0 && sceneHierarchy.Elements.Count == 0) { return(null); } return(new UnitySceneData(unityPropertyValueCacheItem, eventHandlerToScriptTarget, scriptMapping, sceneHierarchy)); }
/// <summary> /// This method skips m_Modifications entry in prefab document and stores modifications in dictionaries /// /// After this method is executed, lexer current token is null or indent of next entry (after m_Modifications) /// </summary> private void GetModifications(IBuffer buffer, YamlLexer lexer, int parentIndentSize, Dictionary <FileID, string> names, Dictionary <FileID, int?> rootIndexes) { FileID curTarget = null; string curPropertyPath = null; string curValue = null; // Each property modifications is flow node: // - target: .. // propertyPath: .. // value: // Minus token means that new modification description is started // There are several entries in description. We are interested only // in target, propertyPath and value while (UnitySceneDataUtil.FindNextIndent(lexer)) { var currentSize = lexer.TokenEnd - lexer.TokenStart; lexer.Advance(); var tokenType = lexer.TokenType; if (tokenType == YamlTokenType.MINUS) { currentSize++; AddData(); lexer.Advance(); } if (currentSize <= parentIndentSize) { break; } UnitySceneDataUtil.SkipWhitespace(lexer); tokenType = lexer.TokenType; if (tokenType == YamlTokenType.NS_PLAIN_ONE_LINE_IN) { var text = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd)); if (text.Equals(UnityYamlConstants.TargetProperty)) { lexer.Advance(); UnitySceneDataUtil.SkipWhitespace(lexer); lexer.Advance(); // skip column // [TODO] handle prefab in prefab curTarget = UnitySceneDataUtil.GetFileId(buffer, lexer).WithGuid(null); } else if (text.Equals(UnityYamlConstants.PropertyPathProperty)) { lexer.Advance(); UnitySceneDataUtil.SkipWhitespace(lexer); lexer.Advance(); curPropertyPath = UnitySceneDataUtil.GetPrimitiveValue(buffer, lexer); } else if (text.Equals(UnityYamlConstants.ValueProperty)) { lexer.Advance(); UnitySceneDataUtil.SkipWhitespace(lexer); lexer.Advance(); curValue = UnitySceneDataUtil.GetPrimitiveValue(buffer, lexer); } } } AddData(); void AddData() { if (curTarget != null) { if (curPropertyPath != null && curPropertyPath.Equals(UnityYamlConstants.NameProperty)) { names[curTarget] = curValue; } else if (curPropertyPath != null && curPropertyPath.Equals(UnityYamlConstants.RootOrderProperty)) { rootIndexes[curTarget] = int.TryParse(curValue, out var r) ? (int?)r : null; } curTarget = null; curPropertyPath = null; curValue = null; } } }
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(); } } }