Esempio n. 1
0
        public static RenderTexture Copy(this RenderTexture texture)
        {
            var renderTexture = TextureUtility.CreateRenderTexture(texture.width, texture.height);

            new ComputeCopy(texture, renderTexture).Execute();
            return(renderTexture);
        }
Esempio n. 2
0
        protected void Cache()
        {
            Debug.Log(new StackTrace().ToString());
            try
            {
                if (Directory.Exists(Metadata.ResourceCacheDirectory))
                {
                    Directory.Delete(Metadata.ResourceCacheDirectory, true);
                }

                Directory.CreateDirectory(Metadata.ResourceCacheDirectory);

                var metadataJson = JsonConvert.SerializeObject(Metadata, Formatting.Indented);

                var metadataPath = Path.Combine(Metadata.ResourceCacheDirectory, "metadata.json");

                File.WriteAllText(metadataPath, metadataJson);

                var thumbnailPath = Path.Combine(Metadata.ResourceCacheDirectory, "thumbnail." + Metadata.TextureExtensionString);
                TextureUtility.SaveTexture2DToDisk(thumbnailPath, Thumbnail);

                CacheResourceSpecific();
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
        }
Esempio n. 3
0
        public override RenderTexture Execute()
        {
            var renderTexture = TextureUtility.CreateRenderTexture(resolution);

            shader.SetTexture(ShaderFunctionID, "Result", renderTexture);

            DispatchShader(renderTexture.width, renderTexture.height);
            return(renderTexture);
        }
        public override RenderTexture Execute()
        {
            var result = TextureUtility.CreateRenderTexture(adjustedTextureSize);

            shader.SetTexture(ShaderFunctionID, "Result", result);

            DispatchShader(adjustedTextureSize.x, adjustedTextureSize.y);

            return(result);
        }
Esempio n. 5
0
        private Texture2D LoadTextureFromCache()
        {
            var texturePath = Path.Combine(Metadata.ResourceCacheDirectory, "texture." + Metadata.TextureExtensionString);

            TextureUtility.TryLoadTexture2DFromDisk(texturePath, out var texture);
            if (texture == null)
            {
                NotifyFatalError();
            }
            return(texture);
        }
Esempio n. 6
0
        private Texture2D LoadOrGenerateThumbnail()
        {
            var thumbnailTexturePath = Path.Combine(Metadata.ResourceCacheDirectory, "thumbnail." + Metadata.TextureExtension);

            TextureUtility.TryLoadTexture2DFromDisk(thumbnailTexturePath, out var thumbnail);

            if (thumbnail == null)
            {
                return(GenerateThumbnail());
            }

            return(thumbnail);
        }
Esempio n. 7
0
        public ProviderTexture(ApplicationContext context, TextureProvider provider)
        {
            Assert.ArgumentNotNull(context, nameof(context));
            Assert.ArgumentNotNull(provider, nameof(provider));

            Assert.ArgumentTrue(ReferenceEquals(provider.resolution, context.TextureResolution), $"{nameof (provider)}.resolution is not {nameof (context)}.TextureResolution");

            Context       = context;
            this.provider = provider;

            RenderTexture = TextureUtility.CreateRenderTexture(context.TextureResolution.AsVector);

            provider.Changed += (s, e) => RenderTexture = provider.Texture;
        }
Esempio n. 8
0
        private ResourceImportResult ImportResource_Internal(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(new ResourceImportResult(false, "Path is null or emptry"));
            }

            if (!Path.HasExtension(path))
            {
                return(new ResourceImportResult(false, $"Path({path}) does not has any extension"));
            }

            if (!File.Exists(path))
            {
                return(new ResourceImportResult(false, $"File at ({path}) does not exists"));
            }

            try
            {
                var extension = Path.GetExtension(path);
                var name      = Path.GetFileNameWithoutExtension(path);

                if (extension == ".png" || extension == ".jpeg" || extension == ".jpg" || extension == ".tga")
                {
                    var texture = TextureUtility.LoadTexture2DFromDisk(path);

                    if (texture.width != texture.height)
                    {
                        var result = new ResourceImportResult(false, $"Texture({path}) is not square ({texture.width}, {texture.height})");
                        GameObject.DestroyImmediate(texture);
                        return(result);
                    }

                    if (!Mathf.IsPowerOfTwo(texture.width))
                    {
                        var result = new ResourceImportResult(false, $"Texture({path}) has not power of 2 size ({texture.width}, {texture.height})");
                        GameObject.DestroyImmediate(texture);
                        return(result);
                    }

                    var textureMinSize = 256;

                    if (texture.width < textureMinSize)
                    {
                        var result = new ResourceImportResult(false, $"Texture({path}) is too small({texture.width}, {texture.height})). Min size is {textureMinSize}");
                        GameObject.DestroyImmediate(texture);
                        return(result);
                    }

                    var metadata = new ResourceMetadata(Context, name, Context.CacheTextureResolution, ResourceType.Texture2D);

                    var resource = Texture2DResource.New(metadata, texture);
                    return(new ResourceImportResult(true, "", resource));
                }
                else
                {
                    return(new ResourceImportResult(false, $"Extension {extension} is not supported."));
                }
            }
            catch (Exception e)
            {
                return(new ResourceImportResult(false, "An exception was thrown when importing a resource! " + e.Message));
            }
        }
Esempio n. 9
0
        protected override void CacheResourceSpecific()
        {
            var texturePath = Path.Combine(Metadata.ResourceCacheDirectory, "texture." + Metadata.TextureExtension);

            TextureUtility.SaveTexture2DToDisk(texturePath, texture);
        }