Exemple #1
0
        /// <summary>
        /// Imports the effect log as an asset.
        /// </summary>
        private void ImportEffectLog(PackageViewModel package)
        {
            using (var transaction = session.UndoRedoService.CreateTransaction())
            {
                CheckEffectLogAsset(package);

                // Create asset (on first time)
                if (effectLogViewModel == null)
                {
                    var effectLogAsset = new EffectLogAsset();
                    var assetItem      = new AssetItem(EffectLogAsset.DefaultFile, effectLogAsset);

                    // Add created asset to project
                    effectLogViewModel = (EffectLogViewModel)package.CreateAsset(package.AssetMountPoint, assetItem, true, null);

                    CheckEffectLogAsset(package);
                }

                // Import shaders
                foreach (var effectCompilerResult in pendingEffects)
                {
                    if (!effectLogStore.Contains(effectCompilerResult))
                    {
                        effectLogStore[effectCompilerResult] = true;
                    }
                }

                // Reset current list of shaders to import
                var oldPendingEffects = pendingEffects;
                session.UndoRedoService.PushOperation(new AnonymousDirtyingOperation(Enumerable.Empty <IDirtiable>(),
                                                                                     () => { pendingEffects = oldPendingEffects; session.ImportEffectLogPendingCount = oldPendingEffects.Count; },
                                                                                     () => { pendingEffects = new HashSet <EffectCompileRequest>(); session.ImportEffectLogPendingCount = 0; }));

                pendingEffects = new HashSet <EffectCompileRequest>();
                session.ImportEffectLogPendingCount = 0;

                // Extract current asset data
                var effectLogData = effectLogStream.ToArray();

                // Update asset
                effectLogViewModel.Text = Encoding.UTF8.GetString(effectLogData, 0, effectLogData.Length);
                effectLogText           = effectLogViewModel.Text;

                // Select current asset
                session.ActiveAssetView.SelectAssets(new[] { effectLogViewModel });

                session.UndoRedoService.SetName(transaction, "Import effect log");
            }
        }
Exemple #2
0
        /// <summary>
        /// Checks if the effect log asset changed since last check.
        /// </summary>
        private void CheckEffectLogAsset(PackageViewModel package)
        {
            var newEffectLogViewModel = package.Assets.FirstOrDefault(x => x.Name == EffectLogAsset.DefaultFile) as EffectLogViewModel;
            var newEffectLogText      = newEffectLogViewModel?.Text;

            if (newEffectLogText != effectLogText || // Asset changed?
                effectLogStore == null)    // First run?
            {
                effectLogText      = newEffectLogText;
                effectLogViewModel = newEffectLogViewModel;

                // Asset changed, update with new data
                effectLogStream = new MemoryStream();

                if (effectLogText != null)
                {
                    var effectLogData = Encoding.UTF8.GetBytes(effectLogText);
                    effectLogStream.Write(effectLogData, 0, effectLogData.Length);
                    effectLogStream.Position = 0;
                }

                effectLogStore = new EffectLogStore(effectLogStream);
                effectLogStore.LoadNewValues();

                // Update pending effects count (against new asset)
                int importEffectLogPendingCount = 0;
                foreach (var effectCompilerResult in pendingEffects)
                {
                    if (!effectLogStore.Contains(effectCompilerResult))
                    {
                        importEffectLogPendingCount++;
                    }
                }

                UpdateImportEffectLogPendingCount(importEffectLogPendingCount);
            }
        }