/// <summary>
        /// Ensures that the sources of an <see cref="Asset"/> exist.
        /// </summary>
        /// <param name="result">The <see cref="AssetCompilerResult"/> in which to output log of potential errors.</param>
        /// <param name="assetItem">The asset to check.</param>
        /// <returns><c>true</c> if the source file exists, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">Any of the argument is <c>null</c>.</exception>
        private static bool EnsureSourcesExist(AssetCompilerResult result, AssetItem assetItem)
        {
            if (result == null) throw new ArgumentNullException(nameof(result));
            if (assetItem == null) throw new ArgumentNullException(nameof(assetItem));

            var collector = new SourceFilesCollector();
            var sourceMembers = collector.GetSourceMembers(assetItem.Asset);

            foreach (var member in sourceMembers)
            {
                if (string.IsNullOrEmpty(member.Value))
                {
                    result.Error($"Source is null for Asset [{assetItem}] in property [{member.Key}]");
                    return false;
                }

                // Get absolute path of asset source on disk
                var assetDirectory = assetItem.FullPath.GetParent();
                var assetSource = UPath.Combine(assetDirectory, member.Value);

                // Ensure the file exists
                if (!File.Exists(assetSource))
                {
                    result.Error($"Unable to find the source file '{assetSource}' for Asset [{assetItem}]");
                    return false;
                }
            }

            return true;
        }
Esempio n. 2
0
        private void UpdateAssetImportPathsTracked(bool isTracking)
        {
            if (isTracking)
            {
                var collector = new SourceFilesCollector();
                var newSourceFiles = collector.GetSourceFiles(clonedAsset);
                bool changed = false;
                bool needUpdate = false;
                // Untrack previous paths
                foreach (var sourceFile in sourceFiles)
                {
                    if (!newSourceFiles.ContainsKey(sourceFile.Key))
                    {
                        tracker.UnTrackAssetImportInput(AssetId, sourceFile.Key);
                        needUpdate = needUpdate || sourceFile.Value;
                        changed = true;
                    }
                }

                // Track new paths
                foreach (var sourceFile in newSourceFiles)
                {
                    if (!sourceFiles.ContainsKey(sourceFile.Key))
                    {
                        tracker.TrackAssetImportInput(AssetId, sourceFile.Key);
                        needUpdate = needUpdate || sourceFile.Value;
                        changed = true;
                    }
                }

                sourceFiles = newSourceFiles;

                if (changed)
                {
                    var files = sourceFiles.Where(x => x.Value).Select(x => x.Key).ToList();
                    tracker.SourceFileChanged.Post(new[] { new SourceFileChangedData(SourceFileChangeType.Asset, AssetId, files, needUpdate) });
                }
            }
            else
            {
                foreach (var sourceFile in sourceFiles.Keys)
                {
                    tracker.UnTrackAssetImportInput(AssetId, sourceFile);
                }
            }
        }
Esempio n. 3
0
        private void UpdateAssetImportPathsTracked(bool isTracking)
        {
            if (isTracking)
            {
                var  collector      = new SourceFilesCollector();
                var  newSourceFiles = collector.GetSourceFiles(clonedAsset);
                bool changed        = false;
                bool needUpdate     = false;
                // Untrack previous paths
                foreach (var sourceFile in sourceFiles)
                {
                    if (!newSourceFiles.ContainsKey(sourceFile.Key))
                    {
                        tracker.UnTrackAssetImportInput(AssetId, sourceFile.Key);
                        needUpdate = needUpdate || sourceFile.Value;
                        changed    = true;
                    }
                }

                // Track new paths
                foreach (var sourceFile in newSourceFiles)
                {
                    if (!sourceFiles.ContainsKey(sourceFile.Key))
                    {
                        tracker.TrackAssetImportInput(AssetId, sourceFile.Key);
                        needUpdate = needUpdate || sourceFile.Value;
                        changed    = true;
                    }
                }

                sourceFiles = newSourceFiles;

                if (changed)
                {
                    var files = sourceFiles.Where(x => x.Value).Select(x => x.Key).ToList();
                    tracker.SourceFileChanged.Post(new[] { new SourceFileChangedData(SourceFileChangeType.Asset, AssetId, files, needUpdate) });
                }
            }
            else
            {
                foreach (var sourceFile in sourceFiles.Keys)
                {
                    tracker.UnTrackAssetImportInput(AssetId, sourceFile);
                }
            }
        }