Esempio n. 1
0
        /**
         * Initialize the Kongregate SDK if it isn't already initialized.
         */
        void InitializeKongregate()
        {
            Debug.Log("KongregateManager.InitializeKongregate");
            if (KongregateAPI.GetAPI() != null)
            {
                Debug.Log("KongregateAPI already initialized");
                return;
            }

            ConfigureAPISettings();
            KongregateAPI kongregate = KongregateAPI.Initialize(kongregateGameID, kongregateAPIKey);

            if (eventInitializing != null)
            {
                // not an official Kongregate API event, but used here to notify other components that initialize
                // has been invoked.
                eventInitializing();
            }
            kongregate.SetEventBundleListener(gameObject, HandleKongregateEvent);
        }
    void OnEnable()
    {
        // Enable Web API integration
        KongregateAPI.Settings.WebEnabled = true;

        KongregateAPI.Settings.Debug = true;
        KongregateAPI.Settings.ButtonCalcScreenCoordinates = true; // if the SDK should handle recalculating the button coordinates for different screen sizes (based on 1024/768)
        KongregateAPI.Settings.ApiDomain = GetAPIDomain();         //this should default to m.kongregate.com, you can remove this line all together

        // You can use the following flag to enable/disable automatic starting of the
        // analytics system. False is the default, which means that the analytics
        // system is started automatically. If you set this to true, you need to
        // manually call KongregateAPI.Analytics.Start() after Initializing the SDK.
        // KongregateAPI.Settings.DeferAnalytics = true;

        // Optional to support swrve analytics tracking
        KongregateAPI.Settings.SwrveAppId  = GetSwrveAppId();
        KongregateAPI.Settings.SwrveApiKey = GetSwrveApiKey();

        // You may override SWRVE config options like so
        //  KongregateAPI.Settings.SwrveConfig = new Dictionary<string,object>() {
        //  { KongregateAPI.KONGREGATE_SWRVE_AUTO_DOWNLOAD, false },
        //  { KongregateAPI.KONGREGATE_SWRVE_LANGUAGE, "gb" },
        //  { KongregateAPI.KONGREGATE_SWRVE_APP_STORE, "amazon" }
        // };
        KongregateAPI.Settings.SwrveConfig = new Dictionary <string, object>()
        {
            { KongregateAPI.KONGREGATE_SWRVE_SENDER_ID, "648571852960" }
        };

        // Initialize Adjust Event Token map
        KongregateAPI.Settings.AdjustAppToken      = GetAdjustAppToken();
        KongregateAPI.Settings.AdjustEnvironment   = "sandbox"; // be sure to set to "production" for release builds
        KongregateAPI.Settings.AdjustEventTokenMap = GetAdjustEventTokenMap();

        // Optionally filter analytics events and properties
        // KongregateAPI.Settings.AutoAnalyticsFilter = Kongregate.Analytics.FIELD_IP_ADDRESS + "," + Kongregate.Analytics.EVENT_SESSION_START;

        // Other optional settings
        // KongregateAPI.Settings.WindowPausesSound = true;
        // KongregateAPI.Settings.WindowPausesUnity = false;
        // KongregateAPI.Settings.GuildChat = true;
        KongregateAPI.Settings.CrashlyticsLogging  = true;
        KongregateAPI.Settings.CrashlyticsUserKeys = true;

        // Uncomment any panel events your game supports.
        KongregateAPI.Settings.SupportedPanelEvents = new string[] {
            // Kongregate.Mobile.PANEL_EVENT_GO_TO_GUILDS
        };

        // Uncomment to specify a custom panel transition animation
        // KongregateAPI.Settings.DefaultPanelTransition = Kongregate.Mobile.PANEL_TRANSITION_SLIDE_FROM_LEFT;

        // Steam integration is provided by the SteamWorks.NET project.
        // We conditionally use it here to provide an example of how it works without
        // breaking projects that don't require Steam integration.
#if UNITY_STANDALONE && STEAMWORKS
        KongregateAPI.Settings.StandaloneEnabled = true;
        KongregateAPI.Settings.BundleID          = "com.kongregate.mobile.angrybots.steam";
        KongregateAPI.Settings.AppVersion        = "1.0.0";
        steamGameObject = new GameObject("SteamGameObject");
        steamGameObject.AddComponent(typeof(SteamManager));
#endif

        // by default, the API will be enabled on platforms that it supports
        // when using the API on platforms that it doesn't support, it will simply ignore calls to it to fail silently
        // therefore you can keep calls throughout your code in place such as 'kongregate.Stats.Submit("Wins", 1);'
        //
        // if for some reason you do not want Kongregate API to run on a platform that it does support, you can set
        // the following flag to false to have it behave as if it did not support it:
        //
        // KongregateAPI.Enabled = false;

        KongregateAPI kongregate = KongregateAPI.Initialize(GetGameId(), GetAPIKey());
        kongregate.SetEventBundleListener(gameObject, (string eventName, string eventJSON) => {
            Debug.Log("Kongregate API Event Bundle name: " + eventName + ", params: " + eventJSON);
            HandleKongregateEvent(eventName);
            if (KongregateAPI.KONGREGATE_EVENT_PROMO_AWARD.Equals(eventName))
            {
                Debug.Log("Award Promo Stuff: " + eventJSON);
                // TODO: Parse the promoId from the JSON and pass to the finishPromoAward method
                // Example includes are hard coded promoId so we don't add a dependency to a specific
                // JSON parser.
                kongregate.Analytics.FinishPromoAward("tpt_angry_promo");
            }
        });

        // Optional: set a listener to be notified when automatic analytic events are fired. Most games
        // won't need this. It's useful if you'd like to echo the analytics to your own system.
        kongregate.Analytics.SetAutoEventListener(gameObject, (string eventName, string fieldsJson) => {
            Debug.Log("Kongregate API auto event name: " + eventName);
        });

        // set the common properties evalutor callback
        // TODO: replace the fields below with information specific to your game
        kongregate.Analytics.SetCommonPropsCallback(() => {
            Dictionary <string, object> commonProps = new Dictionary <string, object>()
            {
                { "game_username", "joe" },
                { "server_version", "1.0.0.0" },
                { "custom_val", ++mCustomAnalyticValue }
                // ...
            };
            return(commonProps);
        });

        // Manually start the analytics subsystem. Has no effect if DeferAnalytics is false (default)
        //kongregate.Analytics.Start();

        // You can start adding analytic events after initializing our SDK. You
        // do not need to wait for KONGREGATE_EVENT_READY. If deferred analytics
        // is enabled, you can start adding analytic events after starting the
        // Analytics subsystem.
        // kongregate.Analytics.AddEvent("pre_ready_event",
        //   new Dictionary<string,object>() {{ "stub_field", 1}});

        //configure up our button
        kongregate.Mobile.ButtonSetNativeRendering(false); // true by default, false means render in Unity rather than native
        if (kongregate.Mobile.ButtonIsNativeRendering())
        {
            // Set position and show button. Only needed when using native rendering.
            kongregate.Mobile.ButtonSetX(10);
            kongregate.Mobile.ButtonSetY(10);
            kongregate.Mobile.ButtonSetSize(48);
            kongregate.Mobile.ButtonShow();
            // native rendering does not support the notificaiton count icon.
        }
        else
        {
            // Not using native rendering, so we load assets from here /Assets/Plugins/Kongregate/Resources and display the
            // button programmatically along with a notification icon. You may do the same, move the asset into the scene,
            // or manage however you wish. Be sure to also render the notification icon (see below).
            mKongButtonTexture = (Texture2D)Resources.Load("Kongregate/kongregate_button", typeof(Texture2D));
        }

        // this method demonstrates how to use Swrve in-app messages
        DemoSetupInAppMessageHandle();

        // this method demonstrates how to use our Analytics API with Prime31s IAP plugins
        DemoSetupPurchases();
    }