public override void OnGetGraphic(ImagePackage package)
        {
            // Already resized?
            ResizedImage resized = ResizedImages.Get(package.location.Path);

            if (resized != null)
            {
                // Sure is!
                package.GotGraphic(resized.Image);

                return;
            }

            // Main thread only:
            Callback.MainThread(delegate(){
                // Try loading from resources:
                string resUrl = package.location.Directory + package.location.Filename;

                if (resUrl.Length > 0 && resUrl[0] == '/')
                {
                    resUrl = resUrl.Substring(1);
                }

                // Get the image:
                UnityEngine.Object resource = Resources.Load(resUrl);

                if (resource == null)
                {
                    // Note: the full file should be called something.bytes for this to work in Unity.
                    resource = Resources.Load(package.location.Path);
                }

                if (!package.Contents.LoadFromAsset(resource, package))
                {
                    return;
                }

                PictureFormat pict = package.Contents as PictureFormat;

                if (pict != null)
                {
                    // Resize the image:
                    resized = ResizedImages.Add(package.location.Path, pict.Image as Texture2D);

                    // Apply:
                    pict.Image = resized.Image;
                }

                // Great, stop there:
                package.Done();
            });
        }
예제 #2
0
        /// <summary>Assign the given image to this package.</summary>
        public void AssignImage(Texture image)
        {
            // Get the contents as a picture block:
            PictureFormat picture = Contents as PictureFormat;

            if (picture == null)
            {
                // Clear the package:
                Clear();

                // Get the picture format:
                Contents = ImageFormats.GetInstance("pict");

                // Update picture var:
                picture = Contents as PictureFormat;
            }

            // Apply the image:
            picture.Image = image;
        }
예제 #3
0
        public override bool OnAttributeChange(string property)
        {
            if (base.OnAttributeChange(property))
            {
                return(true);
            }

            if (property == "path")
            {
                // Go get the camera now!

                // Clear any existing one:
                Camera = null;

                Callback.MainThread(delegate(){
                    // Grab the path itself:
                    string path = this["path"];

                    // Get it:
                    GameObject gameObject = GameObject.Find(path);

                    if (gameObject != null)
                    {
                        // Grab the camera:
                        Camera = gameObject.GetComponent <Camera>();
                    }

                    if (Camera != null)
                    {
                        ComputedStyle computed = Style.Computed;

                        // Create RT if one is needed:
                        RenderTexture rt = Camera.targetTexture;

                        if (rt == null)
                        {
                            // Apply:
                            ApplyNewRenderTexture((int)computed.InnerWidth, (int)computed.InnerHeight);
                        }
                        else
                        {
                            // Apply to background:
                            image = rt;
                        }
                    }

                    ParentMask();
                });

                return(true);
            }
            else if (property == "noresize")
            {
                // Can't resize if noresize is not null:
                CanResize = (this["noresize"] == null);
            }
            else if (property == "mask")
            {
                // We've got a mask!

                // Grab the file path:
                string maskFile = this["mask"];

                if (maskFile == null)
                {
                    SetMask(null);
                }
                else
                {
                    // Create a package to get the mask:
                    ImagePackage package = new ImagePackage(maskFile, document.basepath);

                    package.onload = delegate(UIEvent e){
                        // Apply the mask:
                        PictureFormat pict = package.Contents as PictureFormat;

                        if (pict != null)
                        {
                            SetMask(pict.Image);
                        }
                    };

                    // Go get it:
                    package.send();
                }

                return(true);
            }

            return(false);
        }
예제 #4
0
 /// <summary>Adds an image to the cache. Texture2D or RenderTexture.</summary>
 /// <param name="address">The name to use to find your image.</param>
 /// <param name="image">The image to store in the cache.</param>
 public static void Add(string address, Texture image)
 {
     Lookup[address] = new PictureFormat(image);
 }