Example #1
0
        public static void ShowPrivacyPolicy()
        {
            SpilLogging.Log("Opening Privacy Policy Screen");

            PrivacyPolicy = (GameObject)Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Spilgames/Editor/Prefabs/PrivacyPolicy.prefab"));
            PrivacyPolicy.SetActive(true);
        }
Example #2
0
        public static void ShowDailyBonus(JSONObject data, string url)
        {
            SpilLogging.Log("Opening URL: " + url + " With data: " + data.Print(false));

            SpilUnityImplementationBase.fireDailyBonusOpen();

            DailyBonus = (GameObject)Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Spilgames/Editor/Prefabs/DailyBonus.prefab"));
            DailyBonus.SetActive(true);
        }
Example #3
0
        public InventoryData InitInventory()
        {
            if (Inventory != null)
            {
                return(Inventory);
            }
            TempUserInfo temp;

            try {
                string playerData =
                    File.ReadAllText(Application.streamingAssetsPath + "/defaultPlayerData.json");
                temp = JsonHelper.getObjectFromJson <TempUserInfo>(playerData);
            }
            catch (FileNotFoundException e) {
                SpilLogging.Log("defaultPlayerData.json not found. Creating a placeholder! " + e);
                string placeholder =
                    "{\"wallet\":{\"currencies\":[],\"offset\": 0,\"logic\": \"CLIENT\"},\"inventory\":{\"items\":[],\"offset\":0,\"logic\": \"\"}}";
                temp = JsonHelper.getObjectFromJson <TempUserInfo>(placeholder);
            }

            // Currencies and items loaded from playerdata don't have fields like initialValue because those are defined in the gamedata. Add the missing information.
            // TODO: Should playerdata ever be used to access these fields or only gamedata? A. Check where these fields are being used (they shouldnt be? see SendUpdatePlayerDataEvent tho) and B. Consider maybe this is the wrong inheritance structure / we're exposing fields that shouldn't be exposed for playerdata items/currencies?
            // TODO: Make this prettier? Load both defaultPlayerData and defaultGameData.json and create/initialise wallet+inventory by combining data (instead of deserialising playerdata and adding missing data from gamedata afterwards)?
            if (temp != null && temp.inventory != null && temp.inventory.items != null)
            {
                if (SpilUnityEditorImplementation.gData == null)
                {
                    throw new NotImplementedException("GameData must be initialised before calling this method.");
                }

                foreach (PlayerItemData item in temp.inventory.items)
                {
                    SpilItemData gameDataItem = SpilUnityEditorImplementation.gData.items.FirstOrDefault(a => a.id == item.id);
                    if (gameDataItem != null)
                    {
                        item.content            = gameDataItem.content;
                        item.displayDescription = gameDataItem.displayDescription;
                        item.displayName        = gameDataItem.displayName;
                        item.imageUrl           = gameDataItem.imageUrl;
                        item.initialValue       = gameDataItem.initialValue;
                        item.isGacha            = gameDataItem.isGacha;
                        item.name = gameDataItem.name;
                        item.type = gameDataItem.type;
                    }
                    else
                    {
                        // TODO: Playerdata contains an item that is not defined in the gamedata, should this throw an exception?
                        // TODO: Remove the item from the list or keep it with missing data (as it is now)?
                    }
                }
            }

            return(temp.inventory);
        }
        public string GetGameData()
        {
            if (!updatedFromServer)
            {
                try {
                    string gameData = File.ReadAllText(Application.streamingAssetsPath + "/defaultGameData.json");
                    return(gameData);
                }
                catch (FileNotFoundException e) {
                    SpilLogging.Log("defaultGameData.json not found. Creating a placeholder!" + e.ToString());
                    string placeholder =
                        "{\"currencies\": [],\"promotions\": [],\"shop\": [],\"bundles\": [],\"items\": []}";
                    return(placeholder);
                }
            }

            return(JsonHelper.getJSONFromObject(this));
        }
        /// <summary>
        /// Sends an event to the native Spil SDK which will send a request to the back-end.
        /// Custom events may be tracked as follows:
        /// To track an simple custom event, simply call Spil.Instance.SendCustomEvent(String eventName); from anywhere in your code.
        /// To pass more information with the event create a &lt;String, String&gt; Dictionary and pass that as the second parameter like so:
        /// Dictionary&lt;String, String&gt; eventParams = new Dictionary&lt;String,String&gt;();
        /// eventParams.Add(“level”,levelName);
        /// Spil.Instance.SendCustomEvent(“PlayerDeath”, eventParams);
        /// See https://github.com/spilgames/spil_event_unity_plugin for more information on events.
        /// This method was previously called "TrackEvent".
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="dict"></param>
        public override void SendCustomEvent(string eventName, Dictionary <string, object> dict)
        {
            SpilLogging.Log("SpilSDK-Unity SendCustomEvent " + eventName);
            SpilEvent spilEvent = Spil.MonoInstance.gameObject.AddComponent <SpilEvent>();

            spilEvent.eventName = eventName;

            if (dict != null)
            {
                spilEvent.customData = JsonHelper.DictToJSONObject(dict);
                if (dict.ContainsKey("trackingOnly"))
                {
                    spilEvent.customData.RemoveField("trackingOnly");
                    spilEvent.customData.AddField("trackingOnly", true);
                    dict.Remove("trackingOnly");
                }
            }

            spilEvent.Send();
        }
Example #6
0
    void VerifyAndroidSetup()
    {
        bool isEverythingCorrect = true;

        string androidFolder = "Assets/Plugins/Android/";

        if (Directory.Exists(androidFolder + "GooglePlayServices"))
        {
            SpilLogging.Error(
                "The contents of the GooglePlayServices folder should be copied into 'Assets/Plugins/Android/' and afterwards the folder should be removed");
            isEverythingCorrect = false;
        }

        string appManifestPath = androidFolder + "AndroidManifest.xml";

        // Let's open the app's AndroidManifest.xml file.
        XmlDocument manifestFile = new XmlDocument();

        manifestFile.Load(appManifestPath);

        XmlElement manifestRoot    = manifestFile.DocumentElement;
        XmlNode    applicationNode = null;

        foreach (XmlNode node in manifestRoot.ChildNodes)
        {
            if (node.Name == "application")
            {
                applicationNode = node;
                break;
            }
        }

        // If there's no applicatio node, something is really wrong with your AndroidManifest.xml.
        if (applicationNode == null)
        {
            SpilLogging.Error("Your app's AndroidManifest.xml file does not contain \"<application>\" node.");
            SpilLogging.Error("Unable to verify if the values were correct");

            return;
        }

        if (!applicationNode.Attributes["android:name"].Value.Equals("com.spilgames.spilsdk.activities.SpilSDKApplication"))
        {
            SpilLogging.Error("The application name from your \"AndroidManifest.xml\" file is set incorrectly. Please set it to either \"com.spilgames.spilsdk.activities.SpilSDKApplication\" if you want for the Spil SDK to function correctly");
            isEverythingCorrect = false;
        }

        if (applicationNode.Attributes["android:name"].Value.Equals("com.spilgames.spilsdk.activities.SpilSDKApplicationWithFabric"))
        {
            SpilLogging.Error("The application name found in your \"AndroidManifest.xml\" file is set incorrectly. The application name \"com.spilgames.spilsdk.activities.SpilSDKApplicationWithFabric\" has been removed from the Spil SDK. Please use the standard \"com.spilgames.spilsdk.activities.SpilSDKApplication\". The Fabric (Crashlytics functionality has been moved to this application name.");
            isEverythingCorrect = false;
        }

        bool isUnityRequestPermissionDisabled = false;

        foreach (XmlNode node in applicationNode.ChildNodes)
        {
            if (node.Name.Equals("activity"))
            {
                foreach (XmlNode subNode in node.ChildNodes)
                {
                    if (subNode.Name.Equals("intent-filter"))
                    {
                        foreach (XmlNode bottomNode in subNode.ChildNodes)
                        {
                            if (bottomNode.Name.Equals("action") && bottomNode.Attributes["android:name"].Value
                                .Equals("android.intent.action.MAIN"))
                            {
                                if (!(node.Attributes["android:name"].Value
                                      .Equals("com.spilgames.spilsdk.activities.SpilUnityActivity")) &&
                                    !(node.Attributes["android:name"].Value
                                      .Equals("com.spilgames.spilsdk.activities.SpilUnityActivityWithPrime")) &&
                                    !(node.Attributes["android:name"].Value
                                      .Equals("com.spilgames.spilsdk.activities.SpilUnityActivityWithAN")))
                                {
                                    SpilLogging.Error(
                                        "The Main Activity name from your \"AndroidManifest.xml\" file is set incorrectly. Please set it to either \"com.spilgames.spilsdk.activities.SpilUnityActivity\", \"com.spilgames.spilsdk.activities.SpilUnityActivityWithPrime\" (if you are using Prime31 Plugin) or \"com.spilgames.spilsdk.activities.SpilUnityActivityWithAN\" (if you are using Android Native Plugin) if you want for the Spil SDK to function correctly");
                                    isEverythingCorrect = false;
                                }
                            }
                        }
                    }
                }
            }

            if (node.Name.Equals("meta-data"))
            {
                if (node.Attributes["android:name"].Value.Equals("unityplayer.SkipPermissionsDialog") &&
                    node.Attributes["android:value"].Value.Equals("true"))
                {
                    isUnityRequestPermissionDisabled = true;
                    isEverythingCorrect = false;
                }
            }
        }

        if (!isUnityRequestPermissionDisabled)
        {
            SpilLogging.Error(
                "You did not disable the automatic Unity permission request. Please add the following line to your \"applicaiton\" tag: \"<meta-data android:name=\"unityplayer.SkipPermissionsDialog\" android:value=\"true\" />\". This is required in order to not have any problems with the Spil SDK's permission system. Keep in mind that all your dangerous permissions will be handled by the Spil SDK automatically");
        }

        if (!isEverythingCorrect)
        {
            SpilLogging.Log("Verification Complete! The Spil SDK for Android is configured correctly!");
        }
        else
        {
            SpilLogging.Error("Verification Complete! Something was not configured correctly!! Please check the logs");
        }
    }
Example #7
0
    void CreateDefaultConfigFiles()
    {
        if (androidPackageName == "" || iosBundelId == "")
        {
            throw new UnityException("Bundle ID is Blank");
        }
        SpilLogging.Log("Getting Default Files for Android: " + androidPackageName + ", And iOS: " + iosBundelId);
        string streamingAssetsPath = Application.dataPath + "/StreamingAssets";

        if (!File.Exists(streamingAssetsPath))
        {
            Directory.CreateDirectory(streamingAssetsPath);
        }
        if (!File.Exists(streamingAssetsPath + "/defaultGameData.json"))
        {
            File.WriteAllText(streamingAssetsPath + "/defaultGameData.json", GetData("requestGameData"));
        }
        else
        {
            File.Delete(streamingAssetsPath + "/defaultGameData.json");
            File.WriteAllText(streamingAssetsPath + "/defaultGameData.json", GetData("requestGameData"));
        }

        if (!File.Exists(streamingAssetsPath + "/defaultGameConfig.json"))
        {
            string configResponse = GetData("requestConfig");
            File.WriteAllText(streamingAssetsPath + "/defaultGameConfig.json", configResponse);
            configJSON = new JSONObject(configResponse);

            android = null;
            ios     = null;
        }
        else
        {
            File.Delete(streamingAssetsPath + "/defaultGameConfig.json");
            string configResponse = GetData("requestConfig");
            File.WriteAllText(streamingAssetsPath + "/defaultGameConfig.json", configResponse);
            configJSON = new JSONObject(configResponse);

            android = null;
            ios     = null;
        }

        if (!File.Exists(streamingAssetsPath + "/defaultPlayerData.json"))
        {
            JSONObject gameData   = new JSONObject(GetData("requestGameData"));
            JSONObject playerData = new JSONObject(GetData("requestPlayerData"));

            for (int i = 0; i < gameData.GetField("currencies").Count; i++)
            {
                JSONObject currency = new JSONObject();
                currency.AddField("id", gameData.GetField("currencies").list[i].GetField("id"));
                currency.AddField("currentBalance", 0);
                currency.AddField("delta", 0);

                playerData.GetField("wallet").GetField("currencies").Add(currency);
            }

            playerData.GetField("wallet").RemoveField("offset");
            playerData.GetField("wallet").AddField("offset", 0);

            playerData.GetField("inventory").RemoveField("offset");
            playerData.GetField("inventory").AddField("offset", 0);

            File.WriteAllText(streamingAssetsPath + "/defaultPlayerData.json", playerData.Print(false));
        }
        else
        {
            File.Delete(streamingAssetsPath + "/defaultPlayerData.json");

            JSONObject gameData   = new JSONObject(GetData("requestGameData"));
            JSONObject playerData = new JSONObject(GetData("requestPlayerData"));

            for (int i = 0; i < gameData.GetField("currencies").Count; i++)
            {
                JSONObject currency = new JSONObject();
                currency.AddField("id", gameData.GetField("currencies").list[i].GetField("id"));
                currency.AddField("currentBalance", 0);
                currency.AddField("delta", 0);

                playerData.GetField("wallet").GetField("currencies").Add(currency);
            }

            playerData.GetField("wallet").RemoveField("offset");
            playerData.GetField("wallet").AddField("offset", 0);

            playerData.GetField("inventory").RemoveField("offset");
            playerData.GetField("inventory").AddField("offset", 0);

            File.WriteAllText(streamingAssetsPath + "/defaultPlayerData.json", playerData.Print(false));
        }

        if (retrievalError)
        {
            SpilLogging.Error("Error retrieving default files! Please check the logs!");
        }
        else
        {
            SpilLogging.Log("Default files succesfully retrieved!");
        }
        retrievalError = false;
    }
 public void SetStagingEnvironment()
 {
     SpilLogging.Log("Set environment: staging!");
 }
 public void SetProductionEnvironment()
 {
     SpilLogging.Log("Set environment: production!");
 }
 public void RequestDangerousPermission(string permission, string rationale)
 {
     SpilLogging.Log("Requested permission: " + permission);
 }
        public static void ProcessAdvertisementResponse(ResponseEvent response)
        {
            if (response.action.Equals("init"))
            {
                JSONObject provider = response.data.GetField("providers");

                if (provider.HasField("DFP"))
                {
                    AdvertisementManager.DFPEnabled = true;
                    SpilLogging.Log("DFP Enabled");
                }

                if (provider.HasField("Fyber"))
                {
                    AdvertisementManager.FyberEnabled = true;
                    SpilLogging.Log("Fyber Enabled");
                }

                if (provider.HasField("Chartboost") || provider.HasField("ChartBoost"))
                {
                    AdvertisementManager.ChartboostEnabled = true;
                    SpilLogging.Log("Chartboost Enabled");
                }
            }
            else if (response.action.Equals("show"))
            {
                int priv = Spil.Instance.GetPrivValue();

                if (priv < 2 && priv > -1)
                {
                    return;
                }

                string provider = response.data.GetField("provider").str;
                string adType   = response.data.GetField("adType").str;

                int  probability = Random.Range(0, 100);
                bool available   = probability > 20;

                if (provider.ToLower().Trim().Equals("dfp"))
                {
                    if (available)
                    {
                        SpilLogging.Log("DFP Show");
                        SpilUnityImplementationBase.fireAdAvailableEvent(adType);
                        AdvertisementManager.PlayInterstitial("DFP");
                    }
                    else
                    {
                        SpilLogging.Log("DFP Not Available");
                        SpilUnityImplementationBase.fireAdNotAvailableEvent(adType);
                    }
                }
                else if (provider.ToLower().Trim().Equals("fyber"))
                {
                    if (available)
                    {
                        SpilLogging.Log("Fyber Show");
                        SpilUnityImplementationBase.fireAdAvailableEvent(adType);
                    }
                    else
                    {
                        SpilLogging.Log("Fyber Not Available");
                        SpilUnityImplementationBase.fireAdNotAvailableEvent(adType);
                    }
                }
                else if (provider.ToLower().Trim().Equals("chartboost"))
                {
                    if (available)
                    {
                        SpilLogging.Log("Chartboost Show");
                        SpilUnityImplementationBase.fireAdAvailableEvent(adType);
                        AdvertisementManager.PlayInterstitial("Chartboost");
                    }
                    else
                    {
                        SpilLogging.Log("Chartboost Not Available");
                        SpilUnityImplementationBase.fireAdNotAvailableEvent(adType);
                    }
                }
            }
        }
 public static void ProcessDroppedResponse(string message)
 {
     SpilLogging.Log("Update event dropped. Message: " + message);
 }