Exemplo n.º 1
0
        void OnDestroy()
        {
            // We'll remove the invalid entries in settings. Can't have entries without IDs
            for (int i = 0; i < _settings.ADs.Count; i++)
            {
                Settings.Ad ad = _settings.ADs[i];

                if (string.IsNullOrEmpty(ad.Id))
                {
                    _settings.ADs.RemoveAt(i);
                    i--;
                    EditorUtility.SetDirty(_settings);

                    Debug.Log("Removing empty entry from Ads. Can't have empty IDs");
                }
            }

            for (int i = 0; i < _settings.IAPs.Count; i++)
            {
                Settings.InAppPurchase iap = _settings.IAPs[i];

                if (string.IsNullOrEmpty(iap.Id))
                {
                    _settings.IAPs.RemoveAt(i);
                    i--;
                    EditorUtility.SetDirty(_settings);

                    Debug.Log("Removing empty entry from IAPs. Can't have empty IDs");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ads Item Drawing for the Reorderable List
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="index"></param>
        /// <param name="isActive"></param>
        /// <param name="isFocused"></param>
        private void DrawAdsListItems(Rect rect, int index, bool isActive, bool isFocused)
        {
            Settings.Ad ad = _settings.ADs[index];

            float itemInputYOffset = ((_listItemHeight - EditorGUIUtility.singleLineHeight) / 2);

            Rect   idRect = new Rect(rect.x + 15f, rect.y + itemInputYOffset, rect.width * 0.7f, EditorGUIUtility.singleLineHeight);
            string newId  = (string)EditorUtils.TextFieldWithPlaceholder(idRect, ad.Id, "Placement ID");

            if (ad.Id != newId)
            {
                // We'll check first if this is not a duplicate ID
                bool duplicate = false;
                for (int i = 0; i < _settings.ADs.Count; i++)
                {
                    if (index == i)
                    {
                        continue;
                    }

                    if (newId == _settings.ADs[i].Id)
                    {
                        // Duplicate !
                        Debug.LogError("IDs must be unique.");
                        duplicate = true;
                        break;
                    }
                }

                if (!duplicate)
                {
                    ad.Id = newId;
                    _settings.ADs[index] = ad;

                    EditorUtility.SetDirty(_settings);
                }
            }

            Rect typeRect = new Rect(rect.x + idRect.width + 30f, rect.y + itemInputYOffset, rect.width * 0.3f - 45f, EditorGUIUtility.singleLineHeight);

            Settings.AdType type    = ad.Type;
            Settings.AdType newType = (Settings.AdType)EditorGUI.EnumPopup(typeRect, ad.Type);

            if (newType != ad.Type)
            {
                ad.Type = newType;
                _settings.ADs[index] = ad;

                EditorUtility.SetDirty(_settings);
            }
        }