Esempio n. 1
0
        /// <summary>
        /// Loads the component's web view.
        /// </summary>
        protected IEnumerator LoadWebViewAsync()
        {
            Native native;

            native = Controller.Instance ? Controller.Instance.Native : null;

            while (native != null)
            {
                native.PreLoadPromoWebView();

                // error
                if (!string.IsNullOrEmpty(native.PromoWebViewError))
                {
                    this.Error = native.PromoWebViewError;
                    this.State = PromoState.Error;
                    yield break;
                }

                // success
                if (native.PromoWebViewReady)
                {
                    yield break;
                }

                // not supported
                if (!native.PromoWebViewSupported)
                {
                    yield break;
                }

                // wait
                yield return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the component asynchronously.
        /// </summary>
        protected IEnumerator LoadAsync()
        {
            this.State = PromoState.Loading;

            if (this.State != PromoState.Error)
            {
                yield return(this.StartCoroutine(this.LoadImageAsync()));
            }

            if (this.State != PromoState.Error)
            {
                yield return(this.StartCoroutine(this.LoadWebViewAsync()));
            }

            if (this.State != PromoState.Error)
            {
                this.State = PromoState.Complete;
                if (this.OnComplete != null)
                {
                    this.OnComplete(this);
                }
                yield break;
            }

            if (this.OnError != null)
            {
                this.OnError(this);
            }
            yield break;
        }
Esempio n. 3
0
        /// <summary>
        /// Loads the component's image asynchronously.
        /// </summary>
        protected IEnumerator LoadImageAsync()
        {
            WWW www;

            www = new WWW(this.ImageUrl);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                this.Error = string.Format("Could not download image: {0}", www.error);
                this.State = PromoState.Error;
                yield break;
            }

            try {
                this.Image = new Texture2D(www.texture.width, www.texture.height, www.texture.format, false);
                www.LoadImageIntoTexture(this.Image);
            } catch (System.Exception e) {
                Destroy(this.Image);
                this.Image = null;
                this.Error = string.Format("Could not load image into texture: {0}", e);
                this.State = PromoState.Error;
                yield break;
            }

            try {
                this.Sprite = Sprite.Create(
                    this.Image,
                    new Rect(0, 0, this.Image.width, this.Image.height),
                    Vector2.right,
                    1
                    );
            } catch (System.Exception e) {
                Destroy(this.Sprite);
                this.Sprite = null;
                this.Error  = string.Format("Could not create sprite: {0}", e);
                this.State  = PromoState.Error;
                yield break;
            }

            SpriteRenderer spriteRenderer;

            spriteRenderer        = this.Content.GetComponentInChildren <SpriteRenderer>();
            spriteRenderer.sprite = this.Sprite;

            switch (this.Content.State)
            {
            case ContentState.Unknown:
            case ContentState.Off:
            case ContentState.TurnOff:
                this.TurnContentOff(false);
                break;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Clears the component and resets it to the default state.
        /// </summary>
        public void Clear()
        {
            this.StopAllCoroutines();

            this.Content.Clear();
            Destroy(this.Image);
            Destroy(this.Sprite);

            this.Error  = null;
            this.Image  = null;
            this.Sprite = null;
            this.State  = PromoState.Unknown;
        }