public void Merge(IPsiSourceFile currentAssetSourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElementPointer unityAssetDataElementPointer, IUnityAssetDataElement unityAssetDataElement)
        {
            myPointers[currentAssetSourceFile] = unityAssetDataElementPointer;

            var element = unityAssetDataElement as AssetInspectorValuesDataElement;


            foreach (var variableUsage in element.VariableUsages)
            {
                var scriptReference = variableUsage.ScriptReference;
                var guid            = scriptReference.ExternalAssetGuid;

                myNameToSourceFile.Add(variableUsage.Name, currentAssetSourceFile);

                var mbField = new MonoBehaviourField(guid, variableUsage.Name.GetPlatformIndependentHashCode());
                AddUniqueValue(mbField, variableUsage);
                myChangesInFiles.Add(mbField, currentAssetSourceFile);
                AddChangesPerFile(new MonoBehaviourField(guid, variableUsage.Name.GetPlatformIndependentHashCode(), currentAssetSourceFile), variableUsage);

                myNameHashToGuids.Add(variableUsage.Name.GetPlatformIndependentHashCode(), scriptReference.ExternalAssetGuid);
            }

            foreach (var(reference, _) in element.ImportedInspectorValues.Modifications)
            {
                myNamesInPrefabModifications.Add(reference.Name);
                myNameToSourceFile.Add(reference.Name, currentAssetSourceFile);
            }
        }
예제 #2
0
        public void Merge(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element         = unityAssetDataElement as AssetInspectorValuesDataElement;
            var inspectorUsages = new OneToListMap <string, InspectorVariableUsage>();

            foreach (var variableUsage in element.VariableUsages)
            {
                var guid = (variableUsage.ScriptReference as ExternalReference)?.ExternalAssetGuid;
                if (guid == null)
                {
                    continue;
                }

                myNameToSourceFile.Add(variableUsage.Name, sourceFile);

                var mbField = new MonoBehaviourField(guid, variableUsage.Name);
                myUniqueValuesCount.Add(mbField, variableUsage.Value);
                AddUniqueValue(mbField, variableUsage);
                myChangesInFiles.Add(mbField, sourceFile);
                AddChangesPerFile(new MonoBehaviourField(guid, variableUsage.Name, sourceFile), variableUsage);

                inspectorUsages.Add(variableUsage.Name, variableUsage);

                if (variableUsage.ScriptReference is ExternalReference externalReference)
                {
                    myNameToGuids.Add(variableUsage.Name, externalReference.ExternalAssetGuid);
                }
            }

            myPsiSourceFileToInspectorValues.Add(sourceFile, inspectorUsages);
        }
        public void Merge(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element      = (unityAssetDataElement as AssetMethodsDataElement).NotNull("element != null");
            var groupMethods = new OneToListMap <string, AssetMethodData>();

            foreach (var method in element.Methods)
            {
                myShortNameToScriptTarget.Add(method.MethodName, method);
                groupMethods.Add(method.MethodName, method);

                if (method.TargetScriptReference is ExternalReference)
                {
                    myExternalCount.Add(method.MethodName);
                }
                else if (method.TargetScriptReference is LocalReference localReference)
                {
                    if (assetDocumentHierarchyElement.GetHierarchyElement(null, localReference.LocalDocumentAnchor, null) is IScriptComponentHierarchy script)
                    {
                        if (script.IsStripped)
                        {
                            myExternalCount.Add(method.MethodName);
                        }
                        else
                        {
                            myLocalUsages.Add(method.MethodName, new AssetMethodData(LocalReference.Null,
                                                                                     method.MethodName, TextRange.InvalidRange,
                                                                                     method.Mode, method.Type, script.ScriptReference));
                        }
                    }
                }
            }

            myPsiSourceFileToMethods.Add(sourceFile, groupMethods);
        }
예제 #4
0
        public void Drop(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element = unityAssetDataElement as AssetInspectorValuesDataElement;

            foreach (var variableUsage in element.VariableUsages)
            {
                var guid = (variableUsage.ScriptReference as ExternalReference)?.ExternalAssetGuid;
                if (guid == null)
                {
                    continue;
                }

                myNameToSourceFile.Remove(variableUsage.Name, sourceFile);

                var mbField = new MonoBehaviourField(guid, variableUsage.Name);
                myUniqueValuesCount.Remove(mbField, variableUsage.Value);
                RemoveUniqueValue(mbField, variableUsage);
                myChangesInFiles.Remove(mbField, sourceFile);
                RemoveChangesPerFile(new MonoBehaviourField(guid, variableUsage.Name, sourceFile), variableUsage);

                if (variableUsage.ScriptReference is ExternalReference externalReference)
                {
                    myNameToGuids.Remove(variableUsage.Name, externalReference.ExternalAssetGuid);
                }
            }

            myPsiSourceFileToInspectorValues.Remove(sourceFile);
        }
        public void Merge(IPsiSourceFile currentAssetSourceFile,
                          AssetDocumentHierarchyElement assetDocumentHierarchyElement,
                          IUnityAssetDataElementPointer unityAssetDataElementPointer,
                          IUnityAssetDataElement unityAssetDataElement)
        {
            myPointers[currentAssetSourceFile] = unityAssetDataElementPointer;
            if (!(unityAssetDataElement is AnimatorUsagesDataElement animatorElement))
            {
                return;
            }
            foreach (var(guid, anchors) in animatorElement.GuidToAnchors)
            {
                if (anchors is null)
                {
                    continue;
                }
                // ReSharper disable once AssignNullToNotNullAttribute
                myUsagesCount.Add(guid, anchors.Count);
                myUsageToSourceFiles.Add(guid, currentAssetSourceFile);
            }

            var stateNames = animatorElement.StateNames;

            if (stateNames.Count == 0)
            {
                return;
            }
            foreach (var stateName in stateNames)
            {
                myStateNamesCount.Add(stateName);
            }
        }
        public void Drop(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element = unityAssetDataElement as AssetMethodsDataElement;

            foreach (var method in element.Methods)
            {
                myShortNameToScriptTarget.Remove(method.MethodName, method);

                if (method.TargetScriptReference is ExternalReference)
                {
                    myExternalCount.Remove(method.MethodName);
                }
                else if (method.TargetScriptReference is LocalReference localReference)
                {
                    if (assetDocumentHierarchyElement.GetHierarchyElement(null, localReference.LocalDocumentAnchor, null) is IScriptComponentHierarchy script)
                    {
                        if (script.IsStripped)
                        {
                            myExternalCount.Remove(method.MethodName);
                        }
                        else
                        {
                            myLocalUsages.Remove(method.MethodName, new AssetMethodData(LocalReference.Null,
                                                                                        method.MethodName, TextRange.InvalidRange,
                                                                                        method.Mode, method.Type, script.ScriptReference));
                        }
                    }
                }
            }

            myPsiSourceFileToMethods.Remove(sourceFile);
        }
        public void Drop(IPsiSourceFile currentAssetSourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element = unityAssetDataElement as AssetInspectorValuesDataElement;
            var usages  = element.VariableUsages;

            // inverted order is matter for Remove/AddUniqueValue
            for (int i = usages.Count - 1; i >= 0; i--)
            {
                var variableUsage   = usages[i];
                var scriptReference = variableUsage.ScriptReference;
                var guid            = scriptReference.ExternalAssetGuid;

                myNameToSourceFile.Remove(variableUsage.Name, currentAssetSourceFile);
                var mbField = new MonoBehaviourField(guid, variableUsage.Name.GetPlatformIndependentHashCode());

                RemoveUniqueValue(mbField, variableUsage);
                myChangesInFiles.Remove(mbField, currentAssetSourceFile);
                RemoveChangesPerFile(new MonoBehaviourField(guid, variableUsage.Name.GetPlatformIndependentHashCode(), currentAssetSourceFile), variableUsage);

                myNameHashToGuids.Remove(variableUsage.Name.GetPlatformIndependentHashCode(), scriptReference.ExternalAssetGuid);
            }

            foreach (var(reference, _) in element.ImportedInspectorValues.Modifications)
            {
                myNamesInPrefabModifications.Remove(reference.Name);
            }

            myPointers.Remove(currentAssetSourceFile);
        }
        public void Drop(IPsiSourceFile currentAssetSourceFile,
                         AssetDocumentHierarchyElement assetDocumentHierarchyElement,
                         IUnityAssetDataElement element)
        {
            if (!(element is AnimatorUsagesDataElement animatorElement))
            {
                return;
            }
            var usagesCount        = myUsagesCount;
            var usageToSourceFiles = myUsageToSourceFiles;

            foreach (var(guid, anchors) in animatorElement.GuidToAnchors)
            {
                if (anchors is null)
                {
                    continue;
                }
                var currentCount = usagesCount.GetCount(guid);
                var anchorsCount = anchors.Count;
                usagesCount.Add(guid, anchorsCount <= currentCount ? -anchorsCount : -currentCount);
                usageToSourceFiles.Remove(guid, currentAssetSourceFile);
            }

            myPointers.Remove(currentAssetSourceFile);
            foreach (var stateName in animatorElement.StateNames)
            {
                myStateNamesCount.Remove(stateName);
            }
        }
예제 #9
0
        public void Merge(IPsiSourceFile currentAssetSourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElementPointer unityAssetDataElementPointer, IUnityAssetDataElement unityAssetDataElement)
        {
            myPointers[currentAssetSourceFile] = unityAssetDataElementPointer;
            var dataElement = unityAssetDataElement as AssetUsagesDataElement;

            foreach (var assetUsagePointer in dataElement.EnumerateAssetUsages())
            {
                var guid = assetUsagePointer.UsageTarget.ExternalAssetGuid;
                myUsagesCount.Add(guid);
                myUsageToSourceFiles.Add(guid, currentAssetSourceFile);
            }
        }
예제 #10
0
        public void Drop(IPsiSourceFile currentAssetSourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var dataElement = unityAssetDataElement as AssetUsagesDataElement;

            foreach (var assetUsagePointer in dataElement.EnumerateAssetUsages())
            {
                var guid = assetUsagePointer.UsageTarget.ExternalAssetGuid;
                myUsagesCount.Remove(guid);
                myUsageToSourceFiles.Remove(guid, currentAssetSourceFile);
            }

            myPointers.Remove(currentAssetSourceFile);
        }
예제 #11
0
 public void Merge(IPsiSourceFile currentAssetSourceFile,
                   AssetDocumentHierarchyElement assetDocumentHierarchyElement,
                   IUnityAssetDataElementPointer unityAssetDataElementPointer,
                   IUnityAssetDataElement unityAssetDataElement)
 {
     myPointers[currentAssetSourceFile] = unityAssetDataElementPointer;
     if (!(unityAssetDataElement is AnimationUsagesDataElement animationElement))
     {
         return;
     }
     foreach (var @event in animationElement.Events)
     {
         myNameToGuids.Add(@event.FunctionName, @event.Guid);
         myUsageToSourceFiles.Add(Pair.Of(@event.FunctionName, @event.Guid), currentAssetSourceFile);
     }
 }
예제 #12
0
        public void Remove(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement)
        {
            myShellLocks.AssertWriteAccessAllowed();
            var guid = myMetaFileGuidCache.GetAssetGuid(sourceFile);

            if (guid == null) // we have already clear content due to advice on GuidChanged in consructor
            {
                return;
            }

            var visited = new HashSet <string>();

            foreach (var deps in myDependencies.GetValuesSafe(guid))
            {
                InvalidateImportCache(deps, visited);
            }

            InvalidateImportCache(guid, visited);
        }
예제 #13
0
        public IDictionary <long, IHierarchyElement> GetImportedElementsFor(Guid ownerGuid,
                                                                            AssetDocumentHierarchyElement assetDocumentHierarchyElement)
        {
            myShellLocks.AssertReadAccessAllowed();
            if (!myCache.TryGetFromCache(ownerGuid, out var result))
            {
                lock (myLockObject)
                {
                    if (myCache.TryGetFromCache(ownerGuid, out result))
                    {
                        return(result);
                    }

                    result = DoImport(ownerGuid, assetDocumentHierarchyElement, new HashSet <Guid>());
                    StoreResult(ownerGuid, result);
                }
            }

            return(result);
        }
예제 #14
0
        public void Drop(IPsiSourceFile currentAssetSourceFile,
                         AssetDocumentHierarchyElement assetDocumentHierarchyElement,
                         IUnityAssetDataElement element)
        {
            if (!(element is AnimationUsagesDataElement animationElement))
            {
                return;
            }
            foreach (var @event in animationElement.Events)
            {
                var functionName = @event.FunctionName;
                var guid         = @event.Guid;
                var currentCount = myNameToGuids.GetCount(functionName, guid);
                if (currentCount != 0)
                {
                    myNameToGuids.Remove(functionName, guid);
                }
                myUsageToSourceFiles.Remove(Pair.Of(functionName, guid), currentAssetSourceFile);
            }

            myPointers.Remove(currentAssetSourceFile);
        }
        public void Drop(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var dataElement = unityAssetDataElement as AssetUsagesDataElement;

            foreach (var assetUsage in dataElement.AssetUsages)
            {
                foreach (var dependency in assetUsage.Dependencies)
                {
                    if (dependency is ExternalReference externalReference)
                    {
                        myAssetUsages.Remove(externalReference.ExternalAssetGuid, assetUsage);

                        var set = myAssetUsagesPerFile[sourceFile];
                        set.Remove(externalReference.ExternalAssetGuid, assetUsage);
                        if (set.Count == 0)
                        {
                            myAssetUsagesPerFile.Remove(sourceFile);
                        }
                    }
                }
            }
        }
        public void Merge(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var dataElement = unityAssetDataElement as AssetUsagesDataElement;

            foreach (var assetUsage in dataElement.AssetUsages)
            {
                foreach (var dependency in assetUsage.Dependencies)
                {
                    if (dependency is ExternalReference externalReference)
                    {
                        myAssetUsages.Add(externalReference.ExternalAssetGuid, assetUsage);

                        if (!myAssetUsagesPerFile.TryGetValue(sourceFile, out var set))
                        {
                            set = new OneToCompactCountingSet <string, AssetUsage>();
                            myAssetUsagesPerFile[sourceFile] = set;
                        }

                        set.Add(externalReference.ExternalAssetGuid, assetUsage);
                    }
                }
            }
        }
예제 #17
0
 public void Add(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement)
 {
     Remove(sourceFile, assetDocumentHierarchyElement);
 }
예제 #18
0
        private IDictionary <long, IHierarchyElement> DoImport(Guid ownerGuid, AssetDocumentHierarchyElement assetDocumentHierarchyElement, HashSet <Guid> visitedGuid)
        {
            var result = new Dictionary <long, IHierarchyElement>();

            foreach (var prefabInstanceHierarchy in assetDocumentHierarchyElement.GetPrefabInstanceHierarchies())
            {
                var guid           = prefabInstanceHierarchy.SourcePrefabGuid;
                var sourceFilePath = myMetaFileGuidCache.GetAssetFilePathsFromGuid(guid).FirstOrDefault();
                if (sourceFilePath == null)
                {
                    continue;
                }
                if (!myUnityExternalFilesPsiModule.TryGetFileByPath(sourceFilePath, out var sourceFile))
                {
                    continue;
                }

                var prefabHierarchy = assetDocumentHierarchyElement.AssetDocumentHierarchyElementContainer.GetAssetHierarchyFor(sourceFile);
                if (prefabHierarchy == null)
                {
                    continue;
                }

                if (!myCache.TryGetFromCache(guid, out var importedElements))
                {
                    if (!visitedGuid.Contains(guid)) // invalid assets with cycles in prefab imports
                    {
                        myDependencies.Add(guid, ownerGuid);
                        visitedGuid.Add(guid);
                        importedElements = DoImport(guid, prefabHierarchy, visitedGuid);
                        StoreResult(guid, importedElements);
                    }
                    else
                    {
                        importedElements = EmptyDictionary <long, IHierarchyElement> .Instance;
                    }
                }

                foreach (var element in prefabHierarchy.Elements())
                {
                    if (element is IStrippedHierarchyElement)
                    {
                        continue;
                    }

                    if (element is IPrefabInstanceHierarchy)
                    {
                        continue;
                    }

                    var imported = element.Import(prefabInstanceHierarchy);
                    if (imported == null)
                    {
                        continue;
                    }
                    result[imported.Location.LocalDocumentAnchor] = imported;
                }

                foreach (var element in importedElements.Values)
                {
                    Assertion.Assert(!(element is IStrippedHierarchyElement), "element should be imported");
                    Assertion.Assert(!(element is IPrefabInstanceHierarchy), "prefab should be imported");

                    var imported = element.Import(prefabInstanceHierarchy);
                    if (imported == null)
                    {
                        continue;
                    }

                    result[imported.Location.LocalDocumentAnchor] = imported;
                }
            }

            foreach (var value in result.Values)
            {
                var transform = value as ImportedTransformHierarchy;
                var reference = transform?.OwningGameObject;
                if (reference == null)
                {
                    continue;
                }

                var importedGameObject = result.GetValueSafe(reference.Value.LocalDocumentAnchor) as ImportedGameObjectHierarchy;
                if (importedGameObject == null)
                {
                    continue;
                }

                importedGameObject.TransformHierarchy = transform;
            }

            return(result);
        }
예제 #19
0
 public void OnHierarchyCreated(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement)
 {
     // Invalidate cache for all assets which depends on that hierarchy
     InvalidateCacheFor(sourceFile);
 }
 public ITransformHierarchy GetTransformHierarchy(AssetDocumentHierarchyElement owner)
 {
     return(TransformHierarchy);
 }
예제 #21
0
 public void OnHierarchyRemoved(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement)
 {
     InvalidateCacheFor(sourceFile);
 }