예제 #1
0
 /// <summary>
 /// Checks pixel transparency at given coordinates
 /// </summary>
 /// <param name="x">x-coordinate of pixel</param>
 /// <param name="y">y-coordinate of pixel</param>
 /// <returns></returns>
 public bool IsTransparentPixel(int x, int y)
 {
     if (OpacityMask != null)
     {
         int x1 = x * OpacityMask.Width / ImageSize.Width;
         int y1 = y * OpacityMask.Height / ImageSize.Height;
         if (TextureParams.WrapModeU == TextureWrapMode.Repeat)
         {
             x1 = Math.Abs(x1 % OpacityMask.Width);
         }
         else if (TextureParams.WrapModeU == TextureWrapMode.MirroredRepeat)
         {
             x1 = (x1 / OpacityMask.Width) % 2 == 0
                                         ? Math.Abs(x1 % OpacityMask.Width)
                                         : OpacityMask.Width - Math.Abs(x1 % OpacityMask.Width);
         }
         if (TextureParams.WrapModeV == TextureWrapMode.Repeat)
         {
             y1 = Math.Abs(y1 % OpacityMask.Height);
         }
         else if (TextureParams.WrapModeV == TextureWrapMode.MirroredRepeat)
         {
             y1 = (y1 / OpacityMask.Height) % 2 == 0
                                         ? Math.Abs(y1 % OpacityMask.Height)
                                         : OpacityMask.Height - Math.Abs(y1 % OpacityMask.Height);
         }
         return(!OpacityMask.TestPixel(x1, y1));
     }
     return(false);
 }
예제 #2
0
파일: Texture2D.cs 프로젝트: aologos/Citrus
 /// <summary>
 /// Checks pixel transparency at given coordinates
 /// </summary>
 /// <param name="x">x-coordinate of pixel</param>
 /// <param name="y">y-coordinate of pixel</param>
 /// <returns></returns>
 public bool IsTransparentPixel(int x, int y)
 {
     if (OpacityMask != null)
     {
         int x1 = x * OpacityMask.Width / ImageSize.Width;
         int y1 = y * OpacityMask.Height / ImageSize.Height;
         return(!OpacityMask.TestPixel(x1, y1));
     }
     return(false);
 }
예제 #3
0
        public void LoadImage(string path)
        {
            using (var stream = AssetBundle.Current.OpenFileLocalized(path)) {
                LoadImageHelper(stream, createReloader: false);
            }
            reloader = new TextureBundleReloader(path);
            var maskPath = Path.ChangeExtension(path, ".mask");

            if (AssetBundle.Current.FileExists(maskPath))
            {
                OpacityMask = new OpacityMask(maskPath);
            }
        }
예제 #4
0
파일: Texture2D.cs 프로젝트: aologos/Citrus
        public void LoadImage(string path, TextureMissingDelegate onTextureMissing = null)
        {
            IsStubTexture = false;

            try {
                foreach (string textureFileExtension in AffordableTextureFileExtensions)
                {
                    string tryPath = path + textureFileExtension;
                    if (!AssetBundle.Current.FileExists(tryPath))
                    {
                        continue;
                    }

                    Stream stream;
                    try {
                        stream = AssetBundle.Current.OpenFileLocalized(tryPath);
                    } catch (System.Exception e) {
                        Console.WriteLine("Can not open file '{0}':\n{1}", path, e);
                        continue;
                    }

                    using (stream) {
                        LoadImageHelper(stream, createReloader: false);
                    }

                    LoadTextureParams(path);

                    var maskPath = path + ".mask";
                    if (AssetBundle.Current.FileExists(maskPath))
                    {
                        OpacityMask = new OpacityMask(maskPath);
                    }

                    // Update audio buffers if the audio system performs in the main thread.
                    AudioSystem.Update();

                    return;
                }

                Console.WriteLine("Missing texture '{0}'", path);
                onTextureMissing?.Invoke(path);
                LoadStubImage();
            } finally {
                reloader = new TextureBundleReloader(path);
            }
        }
예제 #5
0
        public void LoadImage(string path, TextureMissingDelegate onTextureMissing = null)
        {
            IsStubTexture = false;

            foreach (string textureFileExtension in AffordableTextureFileExtensions)
            {
                string tryPath = path + textureFileExtension;
                if (!AssetBundle.Current.FileExists(tryPath))
                {
                    continue;
                }

                Stream stream;
                try {
                    stream = AssetBundle.Current.OpenFileLocalized(tryPath);
                } catch (System.Exception e) {
                    Console.WriteLine("Can not open file '{0}':\n{1}", path, e);
                    continue;
                }

                using (stream) {
                    LoadImageHelper(stream);
                }

                LoadTextureParams(path);

                var maskPath = path + ".mask";
                if (AssetBundle.Current.FileExists(maskPath))
                {
                    OpacityMask = new OpacityMask(maskPath);
                }

                if (Application.IsMain(Application.CurrentThread))
                {
                    AudioSystem.Update();
                }

                return;
            }

            Console.WriteLine("Missing texture '{0}'", path);
            onTextureMissing?.Invoke(path);
            LoadStubImage(IsStubTextureTransparent && !path.IsNullOrWhiteSpace());
        }