Ejemplo n.º 1
0
        public static void ShowWindow()
        {
            try
            {
                volatileFile = UE.ReadSerializableResource <AdsSettings>(PersistentFolderName, PersistentFileName, FormatLog);
                if (volatileFile == null)
                {
                    volatileFile = new AdsSettings();
                }
            }
            catch (System.Exception)
            {
                volatileFile = new AdsSettings();
            }


            GetWindow <UnityAdsEditorWindow>("Ad Units");
        }
Ejemplo n.º 2
0
        private void OnGUI()
        {
            GUILayout.Space(10);

            volatileFile.androidGameId       = EditorGUILayout.TextField("Android Game Id: ", volatileFile.androidGameId);
            volatileFile.iOSGameId           = EditorGUILayout.TextField("iOS Game Id: ", volatileFile.iOSGameId);
            volatileFile.initializationDelay = EditorGUILayout.FloatField("Initialization Delay: ", volatileFile.initializationDelay);
            volatileFile.testMode            = EditorGUILayout.Toggle("Test Mode", volatileFile.testMode);
            volatileFile.showLogs            = EditorGUILayout.Toggle("Show Logs", volatileFile.showLogs);
            volatileFile.inNoSuportedDevicesAdsMustSucced = EditorGUILayout.Toggle("Unsuported Succed", volatileFile.inNoSuportedDevicesAdsMustSucced);

            GUILayout.Space(15);
            GUILayout.Label("AdUnits");

            if (GUILayout.Button("Add"))  // Save data to the permanent file
            {
                volatileFile.adUnits.Add(new AdUnitSettings());
            }
            if (GUILayout.Button("Delete"))  // Save data to the permanent file
            {
                if (volatileFile.adUnits.Count <= 0)
                {
                    return;
                }

                volatileFile.adUnits.RemoveAt(volatileFile.adUnits.Count - 1);
            }

            EditorGUI.indentLevel++;
            for (int i = 0; i < volatileFile.adUnits.Count; i++)
            {
                GUILayout.Space(10);

                var e = volatileFile.adUnits[i];

                e.className       = EditorGUILayout.TextField($"{i}. Class Name:", e.className);
                e.adFormat        = (AdFormat)EditorGUILayout.EnumPopup($"{i}. Ad Format:", e.adFormat);
                e.androidAdUnitId = EditorGUILayout.TextField($"{i}. Android AdUnit Id: ", e.androidAdUnitId);
                e.iOSAdUnitId     = EditorGUILayout.TextField($"{i}. iOS AdUnit Id: ", e.iOSAdUnitId);
                if (e.adFormat == AdFormat.Banner)
                {
                    e.bannerPosition = (BannerPosition)EditorGUILayout.EnumPopup($"{i}. Banner Position:", e.bannerPosition);
                }
            }
            EditorGUI.indentLevel--;


            GUILayout.Space(10);
            GUILayout.Label("Settings");

            if (GUILayout.Button("Save"))  // Save data to the permanent file
            {
                SaveSettingsFile();

                // Compile
                AssetDatabase.Refresh();
            }

            if (GUILayout.Button("Reset"))  // Delete persistent info
            {
                DeleteSettingsFile();
                volatileFile = new AdsSettings();

                // Compile
                AssetDatabase.Refresh();
            }

            GUILayout.Space(10);
            GUILayout.Label("C# classes");

            if (GUILayout.Button("Create"))  // Create the classes with permanent file Info
            {
                // Delete old files
                DeleteAllFiles();

                CreateFile(InitializerFolderName, InitializerFileName, InitializerFile, FormatLog);           // Initializer file
                CreateFile(StartupFolderName, StartupFileName, StartupFile(volatileFile.adUnits), FormatLog); // Startup file
                CreateFile(SettingsFolderName, SettingsFileName, SettingsFile(volatileFile), FormatLog);      // Settings file

                foreach (var adUnit in volatileFile.adUnits)
                {
                    if (adUnit.adFormat == AdFormat.Banner)
                    {
                        CreateFile(AdUnitFolderName, AdUnitFileName(adUnit), AdUnitBannerFile(adUnit), FormatLog);                                      // Adunit file
                    }
                    else
                    {
                        CreateFile(AdUnitFolderName, AdUnitFileName(adUnit), AdUnitInterstitialOrRewardedFile(adUnit), FormatLog);   // Adunit file
                    }
                }

                // Close the window
                this.Close();

                // Compile
                AssetDatabase.Refresh();
            }

            if (GUILayout.Button("Delete"))  // Delete clases, but not the permanent file info
            {
                DeleteAllFiles();

                // Close the window
                this.Close();

                // Compile
                AssetDatabase.Refresh();
            }
        }
Ejemplo n.º 3
0
        private static string[] SettingsFile(AdsSettings settings)
        {
            var file = new List <string>();

            // FI1
            var fi1 = new string[]
            {
                "",
                "public static partial class Env",
                "{",
                "    public static partial class UnityAdsSettings",
                "    {",
                "",
                "        // AdUnit Class",
                "        public class AddUnit",
                "        {",
                "            public string androidAdUnitId { get; set; }",
                "            public string iOSAdUnitId { get; set; }",
                "            public UnityEngine.Advertisements.BannerPosition possitionIfIsBanner {get; set;}",
                "        }",
                "",
                "",
                "        public static string androidGameId => " + quote + "" + settings.androidGameId + "" + quote + ";",
                "        public static string iOSGameId => " + quote + "" + settings.iOSGameId + "" + quote + "; ",
                "        public static float initializationDelay => " + settings.initializationDelay + "f;",
                "        public static bool testMode => " + PrintBool(settings.testMode) + ";",
                "        public static bool showLogs => " + PrintBool(settings.showLogs) + ";",
                "        public static bool InNoSuportedDevicesAdsMustSucced => " + PrintBool(settings.inNoSuportedDevicesAdsMustSucced) + ";",
                "",
                "        // Suported platforms must be true",
                "#if UNITY_ANDROID || UNITY_IOS",
                "        public static bool IsSupported => true;",
                "#else",
                "        public static bool IsSupported => false;",
                "#endif",
                "",
                "",
                "",
            };

            foreach (var line in fi1)
            {
                file.Add(line);
            }

            // FI2
            foreach (var adUnit in settings.adUnits)
            {
                file.Add($"        public static AddUnit {adUnit.className}Settings => new AddUnit");
                file.Add("        {");
                file.Add("            androidAdUnitId = " + quote + "" + adUnit.androidAdUnitId + "" + quote + ", ");
                file.Add("            iOSAdUnitId = " + quote + "" + adUnit.iOSAdUnitId + "" + quote + ", ");
                if (adUnit.adFormat == AdFormat.Banner)
                {
                    file.Add($"            possitionIfIsBanner = UnityEngine.Advertisements.BannerPosition." + adUnit.bannerPosition + ",");
                }
                file.Add("        };");
                file.Add($"");
            }

            // FI3
            var fi3 = new string[]
            {
                "    }",
                "",
                "}",
            };

            foreach (var line in fi3)
            {
                file.Add(line);
            }

            // FILE
            return(file.ToArray());
        }