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 InspectorVariableUsage(LocalReference location, ExternalReference scriptReference, string name, IAssetValue assetValue) { Assertion.Assert(name != null, "name != null"); Location = location; ScriptReference = scriptReference; Name = string.Intern(name); Value = assetValue; }
public int GetValueCount(Guid guid, IEnumerable <string> possibleNames, IAssetValue assetValue) { myShellLocks.AssertReadAccessAllowed(); var count = 0; foreach (var name in possibleNames) { var mbField = new MonoBehaviourField(guid, name.GetPlatformIndependentHashCode()); count += myUniqueValuesCount.GetCount(mbField, assetValue.GetHashCode()); } return(count); }
public bool TryGetInspectorValue(IPsiSourceFile owner, IContentNode node, out IAssetValue result) { result = null; if (node is IChameleonNode chameleonNode && !chameleonNode.IsOpened) { if (!IsInterestingChameleon(chameleonNode)) { return(false); } } result = DeserializeValue(owner, node); return(result != null); }
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 int GetAffectedFilesWithSpecificValue(Guid guid, IEnumerable <string> possibleNames, IAssetValue value) { myShellLocks.AssertReadAccessAllowed(); var result = 0; foreach (var possibleName in possibleNames) { result += myValuesWhichAreUniqueInWholeFile.GetCount(new MonoBehaviourFieldWithValue(new MonoBehaviourField(guid, possibleName.GetPlatformIndependentHashCode()), value.GetHashCode())); } return(result); }
public IAssetValue GetUniqueValueDifferTo(Guid guid, IEnumerable <string> possibleNames, IAssetValue assetValue) { myShellLocks.AssertReadAccessAllowed(); var result = new List <IAssetValue>(); foreach (var possibleName in possibleNames) { var mbField = new MonoBehaviourField(guid, possibleName.GetPlatformIndependentHashCode()); foreach (var value in myUniqueValuesInstances.GetValuesSafe(mbField)) { result.Add(value); } } Assertion.Assert(result.Count <= 2, "result.Count <= 2"); if (assetValue == null) { return(result.First()); } return(result.First(t => !t.Equals(assetValue))); }
public IUnityAssetDataElement Build(SeldomInterruptChecker checker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument) { var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer); if (!anchorRaw.HasValue) { return(null); } var anchor = anchorRaw.Value; var isStripped = AssetUtils.IsStripped(assetDocument.Buffer); var gameObject = AssetUtils.GetGameObject(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference; var prefabInstance = AssetUtils.GetPrefabInstance(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference; var correspondingSourceObject = AssetUtils.GetCorrespondingSourceObject(assetDocument.Buffer)?.ToReference(currentSourceFile) as ExternalReference; var location = new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor); if (AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer)) { var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries; if (entries == null) { return(null); } AssetDocumentReference documentReference = null; foreach (var entry in entries) { if (entry.Key.MatchesPlainScalarText(UnityYamlConstants.ScriptProperty)) { documentReference = entry.Content.Value.AsFileID(); break; } } var scriptAnchor = documentReference?.AnchorLong; var scriptGuid = documentReference?.ExternalAssetGuid; if (isStripped || scriptAnchor != null && scriptGuid != null) { return(new AssetDocumentHierarchyElement( new ScriptComponentHierarchy(location, isStripped ? null : new ExternalReference(scriptGuid, scriptAnchor.Value), gameObject, prefabInstance, correspondingSourceObject, isStripped ))); } } else if (AssetUtils.IsTransform(assetDocument.Buffer)) { var father = AssetUtils.GetTransformFather(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference; var rootIndex = AssetUtils.GetRootIndex(assetDocument.Buffer); return(new AssetDocumentHierarchyElement( new TransformHierarchy(location, gameObject, father, rootIndex, prefabInstance, correspondingSourceObject, isStripped))); } else if (AssetUtils.IsGameObject(assetDocument.Buffer)) { var name = AssetUtils.GetGameObjectName(assetDocument.Buffer); if (isStripped || name != null) { return(new AssetDocumentHierarchyElement(new GameObjectHierarchy(location, name, prefabInstance, correspondingSourceObject, isStripped))); } } else if (AssetUtils.IsPrefabModification(assetDocument.Buffer)) { var modification = AssetUtils.GetPrefabModification(assetDocument.Document); var parentTransform = modification?.GetValue("m_TransformParent")?.AsFileID()?.ToReference(currentSourceFile) as LocalReference; 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; if (map == null) { continue; } var target = map.GetValue("target").AsFileID()?.ToReference(currentSourceFile); 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(currentSourceFile, valueNode, out value)) { break; } } if (value == null) { continue; } result.Add(new PrefabModification(target, name, value)); } } var sourcePrefabGuid = AssetUtils.GetSourcePrefab(assetDocument.Buffer)?.ToReference(currentSourceFile) as ExternalReference; if (sourcePrefabGuid == null) { return(null); } return(new AssetDocumentHierarchyElement(new PrefabInstanceHierarchy(location, sourcePrefabGuid.ExternalAssetGuid, parentTransform, result))); } else // regular component { var name = AssetUtils.GetRawComponentName(assetDocument.Buffer); if (name == null) { return(null); } return(new AssetDocumentHierarchyElement( new ComponentHierarchy(name, location, gameObject, prefabInstance, correspondingSourceObject, isStripped))); } return(null); }
public MonoBehaviourFieldWithValue(MonoBehaviourField field, IAssetValue value) { myField = field; myValue = value; }
public PrefabModification(IHierarchyReference target, string propertyPath, IAssetValue value) { Target = target; PropertyPath = propertyPath; Value = value; }