Monetiza Videojuegos

¡Hola! Bienvenidos a este video donde les mostraré algo que me pedían desde hace mucho tiempo: cómo poner anuncios dentro de los juegos y monetizarlos y así ganar un poco de dinero con nuestro trabajo.

Clase AdService Utilizada en el tutorial

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Monetization;
using UnityEngine.Advertisements;
using ShowResult = UnityEngine.Monetization.ShowResult;
using UnityEngine.Analytics;


namespace GameServices
{
    public class AdService : MonoBehaviour, IService
    {
//private string iOSGameID = "IOS_ID"; private string placementID_NonRewarded = "video"; private string placementID_Rewarded = "rewardedVideo"; private string placementID_AR = "ARPlacement"; private string placementID_Banner = "Banner"; private PlacementContent arContent; private Dictionary<string,object> customEventParams = new Dictionary<string, object>(); //Here go the Android ID in Unity Ads Console
private string androidGameID = "Android_ID"; //here enable/disable the test mode
private bool testMode = true; public void Initialize() { //#if UNITY_IOS || UNITY_ANDROID Monetization.Initialize(androidGameID,testMode); Monetization.onPlacementContentReady += ContentReady; Advertisement.Initialize(androidGameID,testMode); StartCoroutine(WaitAndDisplayBanner()); //DisplayNonRewardedAd(); //#else //Debug.LogWarning("la plataforma actual no soporta unity monetization"); //#endif } public void DisplayNonRewardedAd() { if(!Monetization.IsReady(placementID_NonRewarded)) { Debug.LogWarningFormat("Placement <{0}> not ready to display",placementID_NonRewarded); return; } ShowAdPlacementContent adContent = Monetization.GetPlacementContent(placementID_NonRewarded) as ShowAdPlacementContent; if(adContent != null) adContent.Show(); else Debug.LogWarning("Placement content returned null."); } public IEnumerator WaitAndDisplayRewardedAd() { yield return new WaitUntil(() => Monetization.IsReady(placementID_Rewarded)); ShowAdPlacementContent adContent = Monetization.GetPlacementContent(placementID_Rewarded) as ShowAdPlacementContent; adContent.gamerSid = "[CALLBACK SERVER ID HERE]"; ShowAdCallbacks callbackOptions = new ShowAdCallbacks(); callbackOptions.finishCallback += RewardCallback; if(adContent != null) adContent.Show(callbackOptions); else Debug.LogWarning("Placement content returned null."); customEventParams.Add("ar_content",false); AnalyticsResult eventResult = AnalyticsEvent.AdStart(true,null,placementID_Rewarded, customEventParams); Debug.LogFormat("Event result {0}", eventResult); } public void DisplayRewardedAd() { StartCoroutine(WaitAndDisplayRewardedAd()); } private void RewardCallback (ShowResult result) { switch(result) { case ShowResult.Finished: Debug.Log("Rewards for everyone!."); break; case ShowResult.Skipped: Debug.Log("Ad SKIPPED, NO Rewards."); break; case ShowResult.Failed: Debug.Log("Ad failed to display."); break; } } public void DisplayARContent() { ShowAdPlacementContent adContent = arContent as ShowAdPlacementContent; if(adContent!=null) adContent.Show(); else Debug.LogWarning("AR placement returned null."); } private void ContentReady(object sender, PlacementContentReadyEventArgs e) { if(e.placementId == placementID_AR) { arContent = e.placementContent; Debug.Log("AR placement is Ready to go."); } } private IEnumerator WaitAndDisplayBanner() { yield return new WaitUntil(() => Advertisement.IsReady(placementID_Banner)); Advertisement.Banner.Show(placementID_Banner); } } }

Clase ServiceManager

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace GameServices
{
    public class ServiceManager : MonoBehaviour
    {
        public static ServiceManager instance = null;
        public static AdService Ads { get; private set;}
        //public static AnalyticService Analytics {get; private set;}
        private List<IService> _serviceManagers = new List<IService>();

        // inicia la llamada antes de la primera carga del frame
        void Start()
        {
            if (instance == null)
                instance = this;
            else if (instance != null)
                Destroy(gameObject);

            DontDestroyOnLoad(gameObject);
            InitializeServices();
        }

        private void InitializeServices()
        {

            Ads = GetComponent<AdService>();
            //Analytics = GetComponent<AnalyticService>();
            
            //_serviceManagers.Add(Analytics);
            _serviceManagers.Add(Ads);

            foreach (IService service in _serviceManagers)
            {
                service.Initialize();
            }
        }
    }
}

Interface IService

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace GameServices
{
    public interface IService
    {
        void Initialize();
    }
}

Clase CustomRemoteSettings

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CustomRemoteSettings : MonoBehaviour
{
    private string _colorHex = "";
    public string ColoerHex
    {
        get { return _colorHex;}
        set{
            Color parsedColor;
            if(ColorUtility.TryParseHtmlString(value, out parsedColor))
            {
                _colorHex = value;
                Renderer renderer = GetComponent<Renderer>();
                renderer.material.SetColor("_Color", parsedColor);
            }
        }
    }
}

¿Quieres publicar tus propios proyectos?. ¡Pues que esperas!

Suscríbete

Suscríbete a nuestro canal de YouTube

Síguenos en nuestro canal de YouTube dedicado a tecnología, marketplace de proyectos tecnológicos, cursos online y tutoriales de desarrollo de videojuegos. Ofrecemos consultoría en desarrollo de software, marketing online, servicios de TI, hosting web, dominios web y más.

Siguenos en Patreon

Si quieres contribuir con cualquier aporte o donación hacia nuestros proyectos y el canal puedes hacerlo a través de nuestra cuenta en Patreon.