Пример #1
0
        private void ResponseLoader()
        {
            if (enableLog)
            {
                Debug.Log("[Stackeer] Start loading Response.");
            }

            if (onGetResponseLoadedAction != null)
            {
                onGetResponseLoadedAction.Invoke(File.ReadAllText(filePath + uniqueHash));
            }

            if (OnLoadedAction != null)
            {
                OnLoadedAction.Invoke();
            }

            if (enableLog)
            {
                Debug.Log("[Stackeer] Response has been loaded.");
            }

            success = true;
            Finish();
        }
Пример #2
0
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     Loaded -= OnLoaded;
     OnLoadedAction?.Invoke(this);
     if (Parent is Window window)
     {
         window.Close();
     }
 }
Пример #3
0
    private IEnumerator ImageLoader(Texture2D texture = null)
    {
        if (enableLog)
        {
            Debug.Log("[Davinci] Start loading image.");
        }

        if (texture == null)
        {
            byte[] fileData;
            fileData = File.ReadAllBytes(filePath + uniqueHash);
            texture  = new Texture2D(2, 2);
            //ImageConversion.LoadImage(texture, fileData);
            texture.LoadImage(fileData); //..this will auto-resize the texture dimensions.
        }

        Color color;

        if (targetObj != null)
        {
            switch (rendererType)
            {
            case RendererType.renderer:
                Renderer renderer = targetObj.GetComponent <Renderer>();

                if (renderer == null || renderer.material == null)
                {
                    break;
                }

                renderer.material.mainTexture = texture;
                float maxAlpha;

                if (fadeTime > 0 && renderer.material.HasProperty("_Color"))
                {
                    color    = renderer.material.color;
                    maxAlpha = color.a;

                    color.a = 0;

                    renderer.material.color = color;
                    float time = Time.time;
                    while (color.a < maxAlpha)
                    {
                        color.a = Mathf.Lerp(0, maxAlpha, (Time.time - time) / fadeTime);

                        if (renderer != null)
                        {
                            renderer.material.color = color;
                        }

                        yield return(null);
                    }
                }

                break;

            case RendererType.uiImage:
                Image image = targetObj.GetComponent <Image>();

                if (image == null)
                {
                    break;
                }

                Sprite sprite = Sprite.Create(texture,
                                              new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));

                image.sprite = sprite;
                color        = image.color;
                maxAlpha     = color.a;

                if (fadeTime > 0)
                {
                    color.a     = 0;
                    image.color = color;

                    float time = Time.time;
                    while (color.a < maxAlpha)
                    {
                        color.a = Mathf.Lerp(0, maxAlpha, (Time.time - time) / fadeTime);

                        if (image != null)
                        {
                            image.color = color;
                        }
                        yield return(null);
                    }
                }
                break;
            }
        }

        if (OnLoadedAction != null)
        {
            OnLoadedAction.Invoke();
        }

        if (enableLog)
        {
            Debug.Log("[Davinci] Image has been loaded.");
        }

        success = true;
        finish();
    }
Пример #4
0
        private void ImageLoader(Texture2D texture = null)
        {
            if (enableLog)
            {
                Debug.Log("[Stackeer] Start loading image.");
            }

            if (texture == null)
            {
                byte[] fileData;
                fileData = File.ReadAllBytes(filePath + uniqueHash);

                if (fileData == null)
                {
                    Error("[Stackeer] Failed to load image data.");
                }

                texture = new Texture2D(2, 2);
                texture.LoadImage(fileData);

                //Give name to texture for memory refrence
                texture.name = uniqueHash;
            }

            if (targetObj != null)
            {
                switch (rendererType)
                {
                case RENDERER_TYPE.RENDERER:
                    Renderer renderer = targetObj.GetComponent <Renderer>();

                    if (renderer == null || renderer.material == null)
                    {
                        break;
                    }

                    renderer.material.mainTexture = texture;
                    break;

                case RENDERER_TYPE.UI_IMAGE:
                    Image image = targetObj.GetComponent <Image>();

                    if (image == null)
                    {
                        break;
                    }

                    Sprite sprite = Sprite.Create(texture,
                                                  new Rect(0, 0, texture.width, texture.height), Vector2.zero);

                    image.sprite = sprite;
                    break;
                }
            }

            if (OnLoadedAction != null)
            {
                OnLoadedAction.Invoke();
            }

            if (enableLog)
            {
                Debug.Log("[Stackeer] Image has been loaded.");
            }

            success = true;
            Finish();
        }
 public void OnLoaded(string p0)
 {
     playerState = string.Format("LOADED %s", p0);
     OnLoadedAction?.Invoke(p0);
 }
Пример #6
0
    private IEnumerator ImageLoader(Sprite texture = null)
    {
        if (enableLog)
        {
            Debug.Log("[Azzy] Start loading image.");
        }

        if (texture == null)
        {
            byte[] fileData;
            fileData = File.ReadAllBytes(filePath + uniqueHash);

            Texture2D texture2d = new Texture2D(10, 10);
            texture2d.LoadImage(fileData);
            texture = Sprite.Create(texture2d,
                                    new Rect(0, 0, texture2d.width, texture2d.height), new Vector2(0.5f, 0.5f));
        }

        Color color;

        if (targetObj != null)
        {
            switch (rendererType)
            {
            case RendererType.renderer:
                Renderer renderer = targetObj.GetComponent <Renderer>();

                if (renderer == null || renderer.material == null)
                {
                    break;
                }


                // Update this
                //var texture2d = new Texture2D((int)texture.rect.width, (int)texture.rect.height);
                //var pixels = texture.texture.GetPixels(
                //    (int)texture.textureRect.x,
                //    (int)texture.textureRect.y,
                //    (int)texture.textureRect.width,
                //    (int)texture.textureRect.height
                //    );
                //texture2d.SetPixels(pixels);
                //texture2d.Apply();
                //renderer.material.mainTexture = texture2d;

                float maxAlpha;

                if (fadeTime > 0 && renderer.material.HasProperty("_Color"))
                {
                    color    = renderer.material.color;
                    maxAlpha = color.a;

                    color.a = 0;

                    renderer.material.color = color;
                    float time = Time.time;
                    while (color.a < maxAlpha)
                    {
                        color.a = Mathf.Lerp(0, maxAlpha, (Time.time - time) / fadeTime);

                        if (renderer != null)
                        {
                            renderer.material.color = color;
                        }

                        yield return(null);
                    }
                }
                break;

            case RendererType.uiImage:
                Image image = targetObj.GetComponent <Image>();

                if (image == null)
                {
                    break;
                }

                Sprite sprite = texture;

                image.sprite = sprite;
                color        = image.color;
                maxAlpha     = color.a;

                if (fadeTime > 0)
                {
                    color.a     = 0;
                    image.color = color;

                    float time = Time.time;
                    while (color.a < maxAlpha)
                    {
                        color.a = Mathf.Lerp(0, maxAlpha, (Time.time - time) / fadeTime);

                        if (image != null)
                        {
                            image.color = color;
                        }
                        yield return(null);
                    }
                }
                break;

            case RendererType.rawImage:
                RawImage rawImage = targetObj.GetComponent <RawImage>();

                if (rawImage == null)
                {
                    break;
                }

                var texture2d = new Texture2D((int)texture.rect.width, (int)texture.rect.height);
                var pixels    = texture.texture.GetPixels(
                    (int)texture.textureRect.x,
                    (int)texture.textureRect.y,
                    (int)texture.textureRect.width,
                    (int)texture.textureRect.height
                    );
                texture2d.SetPixels(pixels);
                texture2d.Apply();

                rawImage.texture = texture2d;

                color    = rawImage.color;
                maxAlpha = color.a;

                if (fadeTime > 0)
                {
                    color.a        = 0;
                    rawImage.color = color;

                    float time = Time.time;
                    while (color.a < maxAlpha)
                    {
                        color.a = Mathf.Lerp(0, maxAlpha, (Time.time - time) / fadeTime);

                        if (rawImage != null)
                        {
                            rawImage.color = color;
                        }
                        yield return(null);
                    }
                }
                break;
            }
        }

        if (OnLoadedAction != null)
        {
            OnLoadedAction.Invoke();
        }

        if (enableLog)
        {
            Debug.Log("[Azzy] Image has been loaded.");
        }

        success = true;
        finish();
    }
Пример #7
0
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     Loaded -= OnLoaded;
     OnLoadedAction?.Invoke(this);
     Close();
 }