Example #1
0
    void Start()
    {
        if (appInstallAd != null)
        {
            try
            {
                Sprite iconB = Resources.Load <Sprite>("Viguys/1c");
                if (this.text != null)
                {
                    this.text.text = "ICON B";
                }
                bool isPortraitScreen = Screen.orientation.Equals(ScreenOrientation.Portrait) | Screen.orientation.Equals(ScreenOrientation.PortraitUpsideDown);

                Image  iconBG            = transform.Find("IconBG").gameObject.GetComponent <Image>();
                Image  parentInterstials = transform.Find("InterstialsBG").gameObject.GetComponent <Image>();
                Image  interstialsBG     = transform.Find("Content").gameObject.GetComponent <Image>();
                Text   name        = transform.Find("Name").gameObject.GetComponent <Text>();
                Text   slogan      = transform.Find("Slogan").gameObject.GetComponent <Text>();
                Button play        = transform.Find("Play").gameObject.GetComponent <Button>();
                Image  adChoicesBG = transform.Find("AdChoicesBG").gameObject.GetComponent <Image>();
                if (this.text != null)
                {
                    this.text.text = "Get Component";
                }

                string    headlineText     = this.appInstallAd.GetHeadlineText();
                Texture2D iconTexture      = this.appInstallAd.GetIconTexture();
                Texture2D img              = appInstallAd.GetImageTextures()[0];
                string    callToActionText = this.appInstallAd.GetCallToActionText();

                Texture2D adchoices = null;
                try
                {
                    adchoices = appInstallAd.GetAdChoicesLogoTexture();
                }
                catch (Exception e)
                {
                    adchoices = null;
                }

                string bodyText = null;
                try
                {
                    bodyText = this.appInstallAd.GetBodyText();
                }
                catch (Exception e)
                {
                    bodyText = null;
                }

                string store = null;

                try
                {
                    store = this.appInstallAd.GetStore();
                }
                catch (Exception e)
                {
                    store = null;
                }

                //string price = this.appInstallAd.GetPrice();


                float     bounderInc = 20;
                Shader    unlit      = Resources.Load <Shader>("Viguys/Unlit-Alpha");
                Texture2D sprite     = Resources.Load <Texture2D>("Viguys/x");
                icon = GameObject.CreatePrimitive(PrimitiveType.Quad);
                icon.transform.position = new Vector3(iconBG.transform.position.x, iconBG.transform.position.y, -1);
                Material material = new Material(unlit);
                icon.GetComponent <Renderer>().material = material;
                sprite = iconTexture;
                material.mainTexture = sprite;
                standardlize(new Vector3(iconBG.rectTransform.sizeDelta.x - bounderInc, iconBG.rectTransform.sizeDelta.y - bounderInc), icon.GetComponent <Renderer>().bounds.size, sprite.width < sprite.height, isPortraitScreen, icon);


                appInstallAd.RegisterIconImageGameObject(icon);

                if (this.text != null)
                {
                    this.text.text = "ICON DONE";
                }

                boundIcon = new GameObject();
                boundIcon.AddComponent <SpriteRenderer>().sprite = iconB;
                if (this.text != null)
                {
                    this.text.text = "BOUND SPRITE 1";
                }
                boundIcon.transform.localScale = getLocalScale_(new Vector3(iconBG.rectTransform.sizeDelta.x, iconBG.rectTransform.sizeDelta.y), iconB.bounds.size);
                if (this.text != null)
                {
                    this.text.text = "BOUND SPRITE DONE";
                }



                bigImage = GameObject.CreatePrimitive(PrimitiveType.Quad);
                bigImage.transform.position = new Vector3(interstialsBG.transform.position.x, interstialsBG.transform.position.y, -1);
                material = new Material(unlit);
                bigImage.GetComponent <Renderer>().material = material;
                sprite = img;
                material.mainTexture = sprite;

                float bounderIN = 0;


                switch (type)
                {
                case 0:     // LL

                    break;

                case 1:     // LP
                    break;

                case 2:     // PP
                    break;

                case 3:     // PL
                    break;
                }

                float width  = interstialsBG.rectTransform.sizeDelta.x;
                float height = interstialsBG.rectTransform.sizeDelta.y;
                //float ratioI = img.width / img.height;
                //float ratioB = interstialsBG.rectTransform.sizeDelta.x / interstialsBG.rectTransform.sizeDelta.y;
                //if (ratioI < ratioB)
                //{
                //    width = height * ratioI;
                //}
                //else height = width / ratioI;
                //float scaleX = width / interstialsBG.rectTransform.sizeDelta.x;
                //float scaleY = height / interstialsBG.rectTransform.sizeDelta.y;

                if (interstialsBG.transform.rotation.z > 0)
                {
                    standardlize(new Vector3(width, height), bigImage.GetComponent <Renderer>().bounds.size, sprite.width < sprite.height, isPortraitScreen, bigImage);
                }

                else
                {
                    standardlize(new Vector3(width, height), bigImage.GetComponent <Renderer>().bounds.size, sprite.width < sprite.height, isPortraitScreen, bigImage);
                }
                //interstialsBG.transform.localScale = new Vector3(scaleX * interstialsBG.transform.localScale.x, scaleY * interstialsBG.transform.localScale.y);
                //parentInterstials.transform.localScale = new Vector3(scaleX * parentInterstials.transform.localScale.x, scaleY * parentInterstials.transform.localScale.y);

                List <GameObject> list = new List <GameObject>();
                list.Add(bigImage.gameObject);
                appInstallAd.RegisterImageGameObjects(list);



                if (adchoices != null)
                {
                    choices = GameObject.CreatePrimitive(PrimitiveType.Quad);
                    choices.transform.position = new Vector3(adChoicesBG.transform.position.x, adChoicesBG.transform.position.y, -1);
                    material = new Material(unlit);
                    choices.GetComponent <Renderer>().material = material;
                    sprite = adchoices;
                    material.mainTexture = sprite;
                    adChoicesBG.rectTransform.sizeDelta = new Vector2(adchoices.width, adchoices.height);
                    standardlize(new Vector3(adChoicesBG.rectTransform.sizeDelta.x, adChoicesBG.rectTransform.sizeDelta.y), choices.GetComponent <Renderer>().bounds.size, sprite.width < sprite.height, isPortraitScreen, choices);
                    appInstallAd.RegisterAdChoicesLogoGameObject(choices);
                }



                if (this.text != null)
                {
                    this.text.text = "LOGO ACHOICES DONE";
                }

                name.text = headlineText;


                try
                {
                    slogan.text = (bodyText == null || bodyText == "") ? "In " + store : bodyText;
                }
                catch (Exception e)
                {
                }


                Text text = transform.Find("Play").Find("Text").GetComponent <Text>();
                text.text = callToActionText;

                callToAction = new GameObject();
                callToAction.AddComponent <TextMesh>();
                callToAction.GetComponent <TextMesh>().characterSize = 0.25f;
                callToAction.GetComponent <TextMesh>().anchor        = TextAnchor.MiddleCenter;
                callToAction.GetComponent <TextMesh>().color         = new Color(1f, 1f, 1f, 0);
                callToAction.GetComponent <TextMesh>().text          = callToActionText;//"Nhi";
                callToAction.AddComponent <BoxCollider>().size       = ScreenToWorldSize2D(new Vector3(play.GetComponent <RectTransform>().sizeDelta.x, play.GetComponent <RectTransform>().sizeDelta.y));
                callToAction.transform.position = play.transform.position;
                appInstallAd.RegisterCallToActionGameObject(callToAction);

                if (text != null)
                {
                    text.text = width + " " + height;
                }
            }
            catch (Exception e)
            {
                if (text != null)
                {
                    text.text = e.Message;
                }
            }
        }
    }
Example #2
0
    void Update()
    {
        if (appInstallAdLoaded)
        {
            appInstallAdLoaded = false;
            // update o day
            isReadyToShow = true;
            try
            {
                if (iconObj != null)
                {
                    DestroyImmediate(iconObj);
                }
                if (adChoicesObj != null)
                {
                    DestroyImmediate(adChoicesObj);
                }
                if (headLineObj != null)
                {
                    DestroyImmediate(headLineObj);
                }
                if (priceObj != null)
                {
                    DestroyImmediate(priceObj);
                }
                if (storeObj != null)
                {
                    DestroyImmediate(storeObj);
                }
                if (calToActionObj != null)
                {
                    DestroyImmediate(calToActionObj);
                }
                if (log != null)
                {
                    log.text = "Destroy done";
                }

                string headlineText = this.appInstallAd.GetHeadlineText();
                if (log != null)
                {
                    log.text = "Fetch headline done";
                }
                Texture2D iconTexture = this.appInstallAd.GetIconTexture();
                if (log != null)
                {
                    log.text = "Fetch iconTexture done";
                }
                Texture2D img = appInstallAd.GetImageTextures()[0];
                if (log != null)
                {
                    log.text = "Fetch ImageTextures done";
                }
                string callToActionText = this.appInstallAd.GetCallToActionText();
                if (log != null)
                {
                    log.text = "Fetch CallToAction done";
                }
                Texture2D adchoices = null;
                try
                {
                    adchoices = appInstallAd.GetAdChoicesLogoTexture();
                }
                catch (Exception e)
                {
                    adchoices = null;
                }

                if (log != null)
                {
                    log.text = "Fetch AdChoices done";
                }
                string bodyText = null;
                try
                {
                    bodyText = this.appInstallAd.GetBodyText();
                }
                catch (Exception e)
                {
                    bodyText = null;
                }

                if (log != null)
                {
                    log.text = "Fetch BodyText done";
                }
                string price = null;
                try
                {
                    price = this.appInstallAd.GetPrice();
                }
                catch (Exception e)
                {
                    price = null;
                }

                if (log != null)
                {
                    log.text = "Fetch Price done";
                }
                string store = null;
                try
                {
                    store = this.appInstallAd.GetStore();
                }
                catch (Exception e)
                {
                    store = null;
                }



                if (log != null)
                {
                    log.text = "Fetch Store done";
                }

                Vector3 localS = transform.localScale;

                Image  icon    = transform.Find("Icon").gameObject.GetComponent <Image>();
                Image  choices = transform.Find("Adchoice").gameObject.GetComponent <Image>();
                Text   name    = transform.Find("Name").gameObject.GetComponent <Text>();
                Text   priceT  = transform.Find("Price").gameObject.GetComponent <Text>();
                Image  storeI  = transform.Find("Store").gameObject.GetComponent <Image>();
                Button play    = transform.Find("Button").gameObject.GetComponent <Button>();

                if (log != null)
                {
                    log.text = "Find Component done";
                }

                iconObj = GameObject.CreatePrimitive(PrimitiveType.Quad);
                iconObj.transform.position = new Vector3(icon.transform.position.x, icon.transform.position.y, -1);

                Material material = new Material(unlitShader);
                iconObj.GetComponent <Renderer>().material = material;
                material.mainTexture = iconTexture;
                standardlize(new Vector3(icon.rectTransform.sizeDelta.x, icon.rectTransform.sizeDelta.y), iconObj.GetComponent <Renderer>().bounds.size, iconObj, localS);
                appInstallAd.RegisterIconImageGameObject(iconObj);

                if (log != null)
                {
                    log.text = "Icon done";
                }

                name.text   = headlineText;
                headLineObj = new GameObject();
                TextMesh mesh = headLineObj.AddComponent <TextMesh>();
                mesh.characterSize = 0.25f;
                mesh.anchor        = TextAnchor.MiddleCenter;
                mesh.color         = new Color(1f, 1f, 1f, 0);
                mesh.text          = callToActionText;//"Nhi";
                headLineObj.AddComponent <BoxCollider>().size = ScreenToWorldSize2D(new Vector3(name.rectTransform.sizeDelta.x, name.rectTransform.sizeDelta.y));
                headLineObj.transform.localScale = localS;
                headLineObj.transform.position   = new Vector3(name.transform.position.x, name.transform.position.y, -1);
                appInstallAd.RegisterHeadlineTextGameObject(headLineObj);

                if (log != null)
                {
                    log.text = "HeadLine done";
                }
                if (price != null)
                {
                    priceT.text        = price;
                    priceObj           = new GameObject();
                    mesh               = priceObj.AddComponent <TextMesh>();
                    mesh.characterSize = 0.25f;
                    mesh.anchor        = TextAnchor.MiddleCenter;
                    mesh.color         = new Color(1f, 1f, 1f, 0);
                    mesh.text          = price;//"Nhi";
                    priceObj.AddComponent <BoxCollider>().size = ScreenToWorldSize2D(new Vector3(priceT.rectTransform.sizeDelta.x, priceT.rectTransform.sizeDelta.y));
                    priceObj.transform.localScale = localS;
                    priceObj.transform.position   = new Vector3(priceT.transform.position.x, priceT.transform.position.y, -1);;
                    appInstallAd.RegisterPriceGameObject(priceObj);
                }
                else
                {
                    priceT.text = "";
                }

                if (log != null)
                {
                    log.text = "Price done";
                }

                if (store != null)
                {
                    if (store == "Google Play")
                    {
                        storeI.sprite = Resources.Load <Sprite>("Viguys/appstore2");
                    }
                    else
                    {
                        storeI.sprite = Resources.Load <Sprite>("Viguys/appstore1");
                    }
                    storeObj           = new GameObject();
                    mesh               = storeObj.AddComponent <TextMesh>();
                    mesh.characterSize = 0.25f;
                    mesh.anchor        = TextAnchor.MiddleCenter;
                    mesh.color         = new Color(1f, 1f, 1f, 0);
                    mesh.text          = store;//"Nhi";
                    storeObj.AddComponent <BoxCollider>().size = ScreenToWorldSize2D(new Vector3(storeI.rectTransform.sizeDelta.x, storeI.rectTransform.sizeDelta.y));
                    storeObj.transform.localScale = localS;
                    storeObj.transform.position   = new Vector3(storeI.transform.position.x, storeI.transform.position.y, -1);;

                    appInstallAd.RegisterStoreGameObject(storeObj);
                }

                if (log != null)
                {
                    log.text = "Store done";
                }

                play.transform.Find("Text").gameObject.GetComponent <Text>().text = callToActionText;

                calToActionObj     = new GameObject();
                mesh               = calToActionObj.AddComponent <TextMesh>();
                mesh.characterSize = 0.25f;
                mesh.anchor        = TextAnchor.MiddleCenter;
                mesh.color         = new Color(1f, 1f, 1f, 0f);
                mesh.text          = callToActionText;//"Nhi";

                calToActionObj.AddComponent <BoxCollider>().size = ScreenToWorldSize2D(new Vector3(play.GetComponent <RectTransform>().sizeDelta.x, play.GetComponent <RectTransform>().sizeDelta.y));
                calToActionObj.transform.localScale = localS;
                calToActionObj.transform.position   = new Vector3(play.transform.position.x, play.transform.position.y, -1);// play.transform.position;
                appInstallAd.RegisterCallToActionGameObject(calToActionObj);
                if (log != null)
                {
                    log.text = "CallAction done";
                }

                if (adchoices != null)
                {
                    adChoicesObj = GameObject.CreatePrimitive(PrimitiveType.Quad);
                    adChoicesObj.transform.position = new Vector3(choices.transform.position.x, choices.transform.position.y, -1);// choices.transform.position;

                    material = new Material(unlitShader);
                    adChoicesObj.GetComponent <Renderer>().material = material;
                    material.mainTexture = adchoices;

                    standardlize(new Vector3(choices.rectTransform.sizeDelta.x, choices.rectTransform.sizeDelta.y), adChoicesObj.GetComponent <Renderer>().bounds.size, adChoicesObj, localS);
                    appInstallAd.RegisterAdChoicesLogoGameObject(adChoicesObj);
                }



                if (log != null)
                {
                    log.text = "Adchoice done";
                }

                if (canShow)
                {
                    Show();
                }
                else
                {
                    Hide();
                }
                if (log != null)
                {
                    log.text = "Finish done";
                }
            }
            catch (Exception e)
            {
                if (text != null)
                {
                    text.text = "" + e.Message;
                }
            }
        }
    }