public IPsiSourceFile GetSourceFile(IHierarchyReference hierarchyReference, out Guid?guid) { guid = null; if (hierarchyReference == null) { return(null); } myShellLocks.AssertReadAccessAllowed(); switch (hierarchyReference) { case LocalReference localReference: var sourceFile = myManager[localReference.OwningPsiPersistentIndex]; guid = sourceFile != null?myMetaFileGuidCache.GetAssetGuid(sourceFile) : null; return(sourceFile); case ExternalReference externalReference: guid = externalReference.ExternalAssetGuid; var paths = myMetaFileGuidCache.GetAssetFilePathsFromGuid(guid.Value); if (paths.Count != 1) { return(null); } return(myPsiModule.TryGetFileByPath(paths[0], out var result) ? result : null); default: throw new InvalidOperationException(); } }
public InspectorVariableUsage(LocalReference location, IHierarchyReference scriptReference, string name, IAssetValue assetValue) { Location = location; ScriptReference = scriptReference; Name = name; Value = assetValue; }
public PrefabModification(IHierarchyReference target, string propertyPath, IAssetValue value, TextRange valueRange, IHierarchyReference objectReference) { Target = target; PropertyPath = propertyPath; Value = value; ValueRange = valueRange; ObjectReference = objectReference; }
public AssetMethodData(LocalReference location, string methodName, TextRange textRange, EventHandlerArgumentMode mode, string type, IHierarchyReference targetReference) { Location = location; MethodName = methodName; TextRange = textRange; Mode = mode; Type = type; TargetScriptReference = targetReference; }
public AssetMethodData(LocalReference location, string methodName, TextRange textRange, EventHandlerArgumentMode mode, string type, IHierarchyReference targetReference) { Assertion.Assert(location != null, "location != null"); Assertion.Assert(targetReference != null, "targetReference != null"); Assertion.Assert(methodName != null, "methodName != null"); Location = location; MethodName = methodName; TextRange = textRange; Mode = mode; Type = type; TargetScriptReference = targetReference; }
public AssetMethodUsages(string ownerName, string methodName, TextRange textRangeOwnerPsiPersistentIndex, OWORD textRangeOwner, EventHandlerArgumentMode mode, string type, IHierarchyReference targetReference) { Assertion.Assert(targetReference != null, "targetReference != null"); Assertion.Assert(methodName != null, "methodName != null"); OwnerName = ownerName; MethodName = methodName; TextRangeOwnerPsiPersistentIndex = textRangeOwnerPsiPersistentIndex; TextRangeOwner = textRangeOwner; Mode = mode; Type = type; TargetScriptReference = targetReference; }
public IHierarchyElement GetHierarchyElement(IHierarchyReference reference, bool prefabImport) { myShellLocks.AssertReadAccessAllowed(); var sourceFile = GetSourceFile(reference, out var guid); if (sourceFile == null || guid == null) { return(null); } return(myAssetDocumentsHierarchy[sourceFile].GetHierarchyElement(guid, reference.LocalDocumentAnchor, prefabImport ? myPrefabImportCache : null)); }
private static object Read(UnsafeReader reader) { var target = HierarchyReferenceUtil.ReadReferenceFrom(reader); var path = reader.ReadString(); var value = reader.ReadPolymorphic <IAssetValue>(); var range = new TextRange(reader.ReadInt(), reader.ReadInt()); IHierarchyReference objectReference = null; if (reader.ReadBool()) { objectReference = HierarchyReferenceUtil.ReadReferenceFrom(reader); } return(new PrefabModification(target, path, value, range, objectReference)); }
public static void WriteTo([NotNull] this IHierarchyReference reference, UnsafeWriter writer) { if (reference == null) { throw new ArgumentNullException(nameof(reference)); } if (reference is LocalReference localReference) { localReference.WriteTo(writer); } else if (reference is ExternalReference externalReference) { externalReference.WriteTo(writer); } else { throw new InvalidOperationException("Unexpected reference type"); } }
public object Build(SeldomInterruptChecker checker, IPsiSourceFile currentAssetSourceFile, AssetDocument assetDocument) { var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer); if (!anchorRaw.HasValue) { return(null); } var anchor = anchorRaw.Value; var isStripped = AssetUtils.IsStripped(assetDocument.Buffer); var location = new LocalReference(currentAssetSourceFile.PsiStorage.PersistentIndex.NotNull("owningPsiPersistentIndex != null"), anchor); if (isStripped) { var prefabInstance = AssetUtils.GetPrefabInstance(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?; var correspondingSourceObject = AssetUtils.GetCorrespondingSourceObject(currentAssetSourceFile, assetDocument.Buffer) as ExternalReference?; if (prefabInstance != null && correspondingSourceObject != null) { return(new StrippedHierarchyElement(location, prefabInstance.Value, correspondingSourceObject.Value)); } return(null); } var gameObject = AssetUtils.GetGameObjectReference(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?; if (gameObject != null && AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer)) { var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries; if (entries == null) { return(null); } IHierarchyReference documentReference = null; foreach (var entry in entries) { if (entry.Key.MatchesPlainScalarText(UnityYamlConstants.ScriptProperty)) { documentReference = entry.Content.Value.ToHierarchyReference(currentAssetSourceFile); break; } } if (documentReference is ExternalReference scriptReference) { return(new ScriptComponentHierarchy(location, gameObject.Value, scriptReference)); } } else if (gameObject != null && AssetUtils.IsTransform(assetDocument.Buffer)) { var father = AssetUtils.GetTransformFather(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?; if (father == null) { return(null); } var rootIndex = AssetUtils.GetRootIndex(assetDocument.Buffer); return(new TransformHierarchy(location, gameObject.Value, father.Value, rootIndex)); } else if (AssetUtils.IsGameObject(assetDocument.Buffer)) { var name = AssetUtils.GetGameObjectName(assetDocument.Buffer); if (name != null) { return(new GameObjectHierarchy(location, name)); } } else if (AssetUtils.IsPrefabModification(assetDocument.Buffer)) { var modification = AssetUtils.GetPrefabModification(assetDocument.Document); var parentTransform = modification?.GetValue("m_TransformParent")?.ToHierarchyReference(currentAssetSourceFile) as LocalReference? ?? LocalReference.Null; var modifications = modification?.GetValue("m_Modifications") as IBlockSequenceNode; var result = new List <PrefabModification>(); if (modifications != null) { foreach (var entry in modifications.Entries) { var map = entry.Value as IBlockMappingNode; var target = map?.GetValue("target").ToHierarchyReference(currentAssetSourceFile); if (target == null) { continue; } var name = map.GetValue("propertyPath").GetPlainScalarText(); if (name == null) { continue; } var valueNode = map.FindMapEntryBySimpleKey("value")?.Content; if (valueNode == null) { continue; } IAssetValue value = null; foreach (var assetInspectorValueDeserializer in myAssetInspectorValueDeserializers) { if (assetInspectorValueDeserializer.TryGetInspectorValue(currentAssetSourceFile, valueNode, out value)) { break; } } var objectReference = map.FindMapEntryBySimpleKey("objectReference")?.Content.Value.ToHierarchyReference(currentAssetSourceFile); var valueRange = valueNode.GetTreeTextRange(); result.Add(new PrefabModification(target, name, value, new TextRange(assetDocument.StartOffset + valueRange.StartOffset.Offset, assetDocument.StartOffset + valueRange.EndOffset.Offset), objectReference)); } } var sourcePrefabGuid = AssetUtils.GetSourcePrefab(currentAssetSourceFile, assetDocument.Buffer) as ExternalReference?; if (sourcePrefabGuid == null) { return(null); } return(new PrefabInstanceHierarchy(location, parentTransform, result, sourcePrefabGuid.Value.ExternalAssetGuid)); } else if (gameObject != null)// regular component { var name = AssetUtils.GetRawComponentName(assetDocument.Buffer); if (name == null) { return(null); } return(new ComponentHierarchy(location, gameObject.Value, name)); } return(null); }
public AssetReferenceValue(IHierarchyReference reference) { Assertion.Assert(reference != null, "reference != null"); Reference = reference; }
public PrefabModification(IHierarchyReference target, string propertyPath, IAssetValue value) { Target = target; PropertyPath = propertyPath; Value = value; }