Exemplo n.º 1
0
 public override void OnEnable()
 {
     base.OnEnable();
     RenderTask         = FlaxEngine.Object.New <CustomRenderTask>();
     RenderTask.Order   = Order;
     RenderTask.Render += OnRenderUpdate;
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override void OnInit()
        {
            // Create cache folder
            if (!Directory.Exists(_cacheFolder))
            {
                Directory.CreateDirectory(_cacheFolder);
            }

            // Find atlases in a Editor cache directory
            var files   = Directory.GetFiles(_cacheFolder, "cache_*.flax", SearchOption.TopDirectoryOnly);
            int atlases = 0;

            for (int i = 0; i < files.Length; i++)
            {
                // Load asset
                var asset = FlaxEngine.Content.LoadAsync(files[i]);
                if (asset == null)
                {
                    continue;
                }

                // Validate type
                if (asset is PreviewsCache atlas)
                {
                    // Cache atlas
                    atlases++;
                    _cache.Add(atlas);
                }
                else
                {
                    // Skip asset
                    Editor.LogWarning(string.Format("Asset \'{0}\' is inside Editor\'s private directory for Assets Thumbnails Cache. Please move it.", asset.Path));
                }
            }
            Editor.Log(string.Format("Previews cache count: {0} (capacity for {1} icons)", atlases, atlases * PreviewsCache.AssetIconsPerAtlas));

            // Prepare at least one atlas
            if (_cache.Count == 0)
            {
                GetValidAtlas();
            }

            // Create render task but disabled for now
            _output = GPUDevice.CreateTexture("ThumbnailsOutput");
            var desc = GPUTextureDescription.New2D(PreviewsCache.AssetIconSize, PreviewsCache.AssetIconSize, PreviewsCache.AssetIconsAtlasFormat);

            _output.Init(ref desc);
            _task         = Object.New <CustomRenderTask>();
            _task.Order   = 50; // Render this task later
            _task.Enabled = false;
            _task.Render += OnRender;
        }
Exemplo n.º 3
0
        protected override void OnEnable()
        {
            _context = new RenderingGraphContext
            {
                Size       = Size,
                StartIndex = (-Nodes?.Length ?? 0) - 1 // 0 = MainRenderTask
            };

            // The first render task, happens before everything else
            _firstRenderTask         = Object.New <CustomRenderTask>();
            _firstRenderTask.Order   = _context.StartIndex - 1;
            _firstRenderTask.Render += OnRenderUpdate;

            // Output node
            _outputNode = Nodes?.OfType <MainNode>().FirstOrDefault();

            // Set additional node data
            Nodes.ForEach(n => n.Context = _context);

            // Enable everything
            base.OnEnable();
        }