Esempio n. 1
0
        public void GetDependenciesForId(string assetId, List <Dependency> dependencies)
        {
            Progress.IncreaseProgress();
            string fileId = NodeDependencyLookupUtility.GetGuidFromAssetId(assetId);

            dependencies.Add(new Dependency(fileId, ResolvedType, "File", new [] { new PathSegment("File", PathSegmentType.Property) }));
        }
Esempio n. 2
0
        public bool NeedsUpdate(ProgressBase progress)
        {
            string[] assetIds           = NodeDependencyLookupUtility.GetAllAssetPathes(progress, true);
            long[]   timeStampsForFiles = NodeDependencyLookupUtility.GetTimeStampsForFiles(assetIds);

            return(GetNeedsUpdate(assetIds, timeStampsForFiles));
        }
Esempio n. 3
0
        private void GetDependenciesForAssetsInResolver(HashSet <string> changedAssets, IAssetDependencyResolver resolver, Dictionary <string, FileToAssetNode> resultList, ProgressBase progress)
        {
            string resolverId = resolver.GetId();

            foreach (string assetId in changedAssets)
            {
                string fileId = NodeDependencyLookupUtility.GetGuidFromAssetId(assetId);

                if (!resultList.ContainsKey(fileId))
                {
                    resultList.Add(fileId, new FileToAssetNode {
                        FileId = fileId
                    });
                }

                FileToAssetNode fileToAssetNode = resultList[fileId];
                AssetNode       assetNode       = fileToAssetNode.GetAssetNode(assetId);

                List <Dependency> dependencies = new List <Dependency>();

                resolver.GetDependenciesForId(assetId, dependencies);

                AssetNode.ResolverData resolverData = assetNode.GetResolverData(resolverId);

                resolverData.Dependencies = dependencies;

                fileToAssetNode.GetResolverTimeStamp(resolverId).TimeStamp =
                    NodeDependencyLookupUtility.GetTimeStampForFileId(fileId);
            }
        }
Esempio n. 4
0
        private FileToAssetsMapping[] GetDependenciesForAssets(FileToAssetsMapping[] fileToAssetsMappings,
                                                               CreatedDependencyCache createdDependencyCache, ProgressBase progress)
        {
            string[] pathes     = NodeDependencyLookupUtility.GetAllAssetPathes(progress, true);
            long[]   timestamps = NodeDependencyLookupUtility.GetTimeStampsForFiles(pathes);

            List <AssetResolverData> data = new List <AssetResolverData>();

            foreach (CreatedResolver resolverUsage in createdDependencyCache.ResolverUsages)
            {
                if (!(resolverUsage.Resolver is IAssetToFileDependencyResolver))
                {
                    continue;
                }

                IAssetToFileDependencyResolver resolver = (IAssetToFileDependencyResolver)resolverUsage.Resolver;

                HashSet <string> changedAssets = GetChangedAssetIds(pathes, timestamps, fileToAssetsMappings);
                data.Add(new AssetResolverData {
                    ChangedAssets = changedAssets, Resolver = resolver
                });

                resolver.Initialize(this, changedAssets, progress);
            }

            Dictionary <string, FileToAssetsMapping> nodeDict = RelationLookup.RelationLookupBuilder.ConvertToDictionary(fileToAssetsMappings);

            foreach (AssetResolverData resolverData in data)
            {
                GetDependenciesForAssetsInResolver(resolverData.ChangedAssets, resolverData.Resolver as IAssetToFileDependencyResolver, nodeDict, progress);
            }

            return(nodeDict.Values.ToArray());
        }
Esempio n. 5
0
        public List <Dependency> GetDependenciesForId(string id)
        {
            if (NodeDependencyLookupUtility.IsResolverActive(_createdDependencyCache, AssetToFileDependencyResolver.Id, ConnectionType))
            {
                return(_fileNodesDict[id].Dependencies);
            }

            return(new List <Dependency>());
        }
            public Node GetNode(string id, string type)
            {
                string key = NodeDependencyLookupUtility.GetNodeKey(id, type);

                if (_lookup.ContainsKey(key))
                {
                    return(_lookup[key]);
                }

                return(null);
            }
        private void AddPrefabAsDependency(string id, Object obj, Stack <PathSegment> stack)
        {
            Object correspondingObjectFromSource = PrefabUtility.GetCorrespondingObjectFromSource(obj);
            string assetId   = NodeDependencyLookupUtility.GetAssetIdForAsset(correspondingObjectFromSource);
            string assetPath = AssetDatabase.GetAssetPath(correspondingObjectFromSource);
            string guid      = AssetDatabase.AssetPathToGUID(assetPath);

            if (guid != NodeDependencyLookupUtility.GetGuidFromAssetId(id))
            {
                AddDependency(id, new Dependency(assetId, ConnectionType, NodeType, stack.ToArray()));
            }
        }
Esempio n. 8
0
        public void Initialize(AssetDependencyCache cache, HashSet <string> changedAssets, ProgressBase progress)
        {
            TraverserSubSystem.Clear();

            foreach (string assetId in changedAssets)
            {
                string guid = NodeDependencyLookupUtility.GetGuidFromAssetId(assetId);
                if (!_inValidGuids.Contains(guid))
                {
                    cache._hierarchyTraverser.AddAssetId(assetId, TraverserSubSystem);
                }
            }
        }
            private static Node GetOrCreateNode(string id, string type, Dictionary <string, Node> nodeDictionary)
            {
                string key = NodeDependencyLookupUtility.GetNodeKey(id, type);

                if (!nodeDictionary.ContainsKey(key))
                {
                    nodeDictionary.Add(key, new Node {
                        Id = id, Type = type
                    });
                }

                return(nodeDictionary[key]);
            }
Esempio n. 10
0
        private HashSet <string> GetChangedAssetIdsForResolver(IAssetDependencyResolver resolver, string[] pathes, long[] timestamps, FileToAssetNode[] fileToAssetNodes)
        {
            HashSet <string> result = new HashSet <string>();
            Dictionary <string, FileToAssetNode> list = RelationLookup.RelationLookupBuilder.ConvertToDictionary(fileToAssetNodes);
            string id = resolver.GetId();
            string progressBarTitle = $"AssetDependencyCache: {id}";

            float lastDisplayedPercentage = 0;

            for (int i = 0; i < pathes.Length; ++i)
            {
                float progressPercentage = (float)i / pathes.Length;

                if (progressPercentage - lastDisplayedPercentage > 0.01f)
                {
                    EditorUtility.DisplayProgressBar(progressBarTitle, $"Finding changed assets {result.Count}", (float)i / pathes.Length);
                    lastDisplayedPercentage = progressPercentage;
                }

                string path = pathes[i];
                string guid = AssetDatabase.AssetPathToGUID(path);

                if (!resolver.IsGuidValid(guid))
                {
                    continue;
                }

                if (list.ContainsKey(guid))
                {
                    FileToAssetNode fileToAssetNode = list[guid];
                    foreach (AssetNode assetNode in fileToAssetNode.AssetNodes)
                    {
                        assetNode.Existing = true;
                    }

                    if (fileToAssetNode.GetResolverTimeStamp(id).TimeStamp != timestamps[i])
                    {
                        NodeDependencyLookupUtility.AddAssetsToList(result, path);
                    }
                }
                else
                {
                    NodeDependencyLookupUtility.AddAssetsToList(result, path);
                }
            }

            return(result);
        }
        public override Result GetDependency(Type objType, object obj, SerializedProperty property, string propertyPath, SerializedPropertyType type, Stack <PathSegment> stack)
        {
            if (type != SerializedPropertyType.ObjectReference)
            {
                return(null);
            }

            var value = property.objectReferenceValue;

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

            string assetPath = AssetDatabase.GetAssetPath(value);

            if (string.IsNullOrEmpty(assetPath))
            {
                return(null);
            }

            if (ExcludedProperties.Contains(propertyPath))
            {
                return(null);
            }

            if (ExcludedDependencies.Contains(Path.GetFileName(assetPath)))
            {
                return(null);
            }

            string assetId = NodeDependencyLookupUtility.GetAssetIdForAsset(value);
            string guid    = NodeDependencyLookupUtility.GetGuidFromAssetId(assetId);

            if (!(guid.StartsWith("0000000") || value is ScriptableObject || AssetDatabase.IsSubAsset(value) || AssetDatabase.IsMainAsset(value)))
            {
                return(null);
            }

            return(new Result {
                Id = assetId, ConnectionType = ConnectionType, NodeType = NodeType
            });
        }
Esempio n. 12
0
        public void Search()
        {
            for (int i = 0; i < 128; ++i)
            {
                ReflectionStack[i] = new ReflectionStackItem();
            }

            foreach (var pair in m_assetIdToResolver)
            {
                Object asset = NodeDependencyLookupUtility.GetAssetById(pair.Key);

                if (asset == null)
                {
                    continue;
                }

                Progress.IncreaseProgress();
                Progress.UpdateProgress("SerializedPropertySearcher", asset.name);
                Traverse(pair.Key, NodeDependencyLookupUtility.GetAssetById(pair.Key), new Stack <PathSegment>());
            }
        }
Esempio n. 13
0
        private HashSet <string> GetChangedAssetIds(string[] pathes, long[] timestamps, FileToAssetsMapping[] fileToAssetMappings)
        {
            HashSet <string> result = new HashSet <string>();
            Dictionary <string, FileToAssetsMapping> list = RelationLookup.RelationLookupBuilder.ConvertToDictionary(fileToAssetMappings);

            float lastDisplayedPercentage = 0;

            for (int i = 0; i < pathes.Length; ++i)
            {
                float progressPercentage = (float)i / pathes.Length;

                if (progressPercentage - lastDisplayedPercentage > 0.01f)
                {
                    EditorUtility.DisplayProgressBar("AssetToFileDependencyCache", $"Finding changed assets {result.Count}", (float)i / pathes.Length);
                    lastDisplayedPercentage = progressPercentage;
                }

                string path = pathes[i];
                string guid = AssetDatabase.AssetPathToGUID(path);

                if (list.ContainsKey(guid))
                {
                    FileToAssetsMapping fileToAssetsMapping = list[guid];
                    fileToAssetsMapping.SetExisting();

                    long timeStamp = timestamps[i];

                    if (fileToAssetsMapping.Timestamp != timeStamp)
                    {
                        NodeDependencyLookupUtility.AddAssetsToList(result, path);
                    }
                }
                else
                {
                    NodeDependencyLookupUtility.AddAssetsToList(result, path);
                }
            }

            return(result);
        }
Esempio n. 14
0
        private FileToAssetNode[] GetDependenciesForAssets(FileToAssetNode[] fileToAssetNodes,
                                                           CreatedDependencyCache createdDependencyCache, ProgressBase progress)
        {
            string[] pathes     = NodeDependencyLookupUtility.GetAllAssetPathes(progress, true);
            long[]   timestamps = NodeDependencyLookupUtility.GetTimeStampsForFiles(pathes);

            List <AssetResolverData> data = new List <AssetResolverData>();

            _hierarchyTraverser.Clear();

            foreach (CreatedResolver resolverUsage in createdDependencyCache.ResolverUsages)
            {
                if (!(resolverUsage.Resolver is IAssetDependencyResolver))
                {
                    continue;
                }

                IAssetDependencyResolver resolver = (IAssetDependencyResolver)resolverUsage.Resolver;

                HashSet <string> changedAssets = GetChangedAssetIdsForResolver(resolver, pathes, timestamps, _fileToAssetNodes);
                data.Add(new AssetResolverData {
                    ChangedAssets = changedAssets, Resolver = resolver
                });

                resolver.Initialize(this, changedAssets, progress);
            }

            // Execute the searcher for all registered subsystems here to find hierarchy and property pathes
            _hierarchyTraverser.Initialize(progress);
            _hierarchyTraverser.Search();

            Dictionary <string, FileToAssetNode> nodeDict = RelationLookup.RelationLookupBuilder.ConvertToDictionary(fileToAssetNodes);

            foreach (AssetResolverData resolverData in data)
            {
                GetDependenciesForAssetsInResolver(resolverData.ChangedAssets, resolverData.Resolver as IAssetDependencyResolver, nodeDict, progress);
            }

            return(nodeDict.Values.ToArray());
        }
Esempio n. 15
0
        public void UpdateFromDefinition(ResolverUsageDefinitionList definitionList)
        {
            ResetCacheUsages();

            foreach (ResolverUsageDefinitionList.Entry entry in definitionList.CacheUsages)
            {
                string cacheTypeFullName = entry.CacheType.FullName;

                if (!CreatedCaches.ContainsKey(cacheTypeFullName))
                {
                    IDependencyCache       cache        = NodeDependencyLookupUtility.InstantiateClass <IDependencyCache>(entry.CacheType);
                    CreatedDependencyCache createdCache = new CreatedDependencyCache(cache);

                    CreatedCaches.Add(cacheTypeFullName, createdCache);
                }

                CreatedCaches[cacheTypeFullName].AddResolver(entry.ResolverType, entry.ConnectionTypes);
            }

            ConnectionTypeLookup = new ConnectionTypeLookup(GetCaches());
            NodeHandlerLookup    = NodeDependencyLookupUtility.BuildNodeHandlerLookup();
        }
Esempio n. 16
0
        public void AddResolver(Type resolverType, List <string> connectionTypes)
        {
            string resolverTypeFullName = resolverType.FullName;

            if (!CreatedResolvers.ContainsKey(resolverTypeFullName))
            {
                IDependencyResolver dependencyResolver = NodeDependencyLookupUtility.InstantiateClass <IDependencyResolver>(resolverType);
                CreatedResolver     resolver           = new CreatedResolver(dependencyResolver);
                CreatedResolvers.Add(resolverTypeFullName, resolver);
            }

            CreatedResolver createdResolver = CreatedResolvers[resolverTypeFullName];

            string[] collection = connectionTypes != null?connectionTypes.ToArray() : createdResolver.Resolver.GetConnectionTypes();

            createdResolver.ConnectionTypes = new HashSet <string>(collection);

            ResolverUsages.Add(createdResolver);
            ResolverUsagesLookup.Add(createdResolver.Resolver.GetId(), createdResolver);

            createdResolver.IsActive = true;
        }
Esempio n. 17
0
        private void GetDependenciesForAssetsInResolver(HashSet <string> changedAssets, IAssetToFileDependencyResolver resolver, Dictionary <string, FileToAssetsMapping> resultList, ProgressBase progress)
        {
            foreach (string assetId in changedAssets)
            {
                string fileId = NodeDependencyLookupUtility.GetGuidFromAssetId(assetId);

                if (!resultList.ContainsKey(fileId))
                {
                    resultList.Add(fileId, new FileToAssetsMapping {
                        FileId = fileId
                    });
                }

                FileToAssetsMapping    fileToAssetsMapping    = resultList[fileId];
                FileToAssetMappingNode fileToAssetMappingNode = fileToAssetsMapping.GetFileNode(assetId);

                fileToAssetMappingNode.Dependencies.Clear();
                resolver.GetDependenciesForId(assetId, fileToAssetMappingNode.Dependencies);

                fileToAssetsMapping.Timestamp = NodeDependencyLookupUtility.GetTimeStampForFileId(fileId);
            }
        }
Esempio n. 18
0
        public bool NeedsUpdate(ProgressBase progress)
        {
            string[] assetIds           = NodeDependencyLookupUtility.GetAllAssetPathes(progress, true);
            long[]   timeStampsForFiles = NodeDependencyLookupUtility.GetTimeStampsForFiles(assetIds);

            foreach (CreatedResolver resolverUsage in _createdDependencyCache.ResolverUsages)
            {
                IAssetDependencyResolver assetDependencyResolver = resolverUsage.Resolver as IAssetDependencyResolver;
                assetDependencyResolver.SetValidGUIDs();
            }

            foreach (CreatedResolver resolverUsage in _createdDependencyCache.ResolverUsages)
            {
                IAssetDependencyResolver assetDependencyResolver = resolverUsage.Resolver as IAssetDependencyResolver;

                if (CheckNeedsUpdateForResolver(assetDependencyResolver, assetIds, timeStampsForFiles, _fileToAssetNodes))
                {
                    return(true);
                }
            }

            return(false);
        }
 public int GetOwnFileSize(string id, string type, NodeDependencyLookupContext stateContext)
 {
     return(NodeDependencyLookupUtility.GetPackedAssetSize(id));
 }