Пример #1
0
        /// <summary>
        /// Leaderboard 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 DrawLeaderboardsListItems(Rect rect, int index, bool isActive, bool isFocused)
        {
            Settings.Leaderboard leaderboard = _settings.Leaderboards[index];

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

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

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

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

                if (!duplicate)
                {
                    leaderboard.Id = newId;
                    _settings.Leaderboards[index] = leaderboard;

                    EditorUtility.SetDirty(_settings);
                }
            }

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

            Kiln.Settings.LeaderboardType type    = leaderboard.Type;
            Kiln.Settings.LeaderboardType newType = (Kiln.Settings.LeaderboardType)EditorGUI.EnumPopup(typeRect, leaderboard.Type);

            if (newType != leaderboard.Type)
            {
                leaderboard.Type = newType;
                _settings.Leaderboards[index] = leaderboard;

                EditorUtility.SetDirty(_settings);
            }

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

            if (GUI.Button(resetButtonRect, "RESET"))
            {
                // Erase data file if it exists
                Leaderboard.Reset(leaderboard.Id);
                UnityEditor.AssetDatabase.Refresh();
            }
        }
Пример #2
0
        private void CheckInitialize()
        {
            if (!_initialized)
            {
                _initialized = true;

                // Ads list
                _ads = new ReorderableList(_settings.ADs, typeof(Settings.Ad), false, true, true, true);
                _ads.drawElementCallback = DrawAdsListItems;
                _ads.drawHeaderCallback  = (Rect rect) => {
                    string name = "Ad Placements Setup";
                    EditorGUI.LabelField(rect, name);
                };
                _ads.onRemoveCallback = (ReorderableList list) => {
                    _settings.ADs.RemoveAt(list.index);
                    EditorUtility.SetDirty(_settings);
                };
                _ads.onAddCallback = (ReorderableList list) => {
                    _settings.ADs.Add(new Settings.Ad());
                    EditorUtility.SetDirty(_settings);
                };
                _ads.elementHeight = _listItemHeight;

                // IAPs list
                _iaps = new ReorderableList(_settings.IAPs, typeof(Settings.InAppPurchase), false, true, true, true);
                _iaps.drawElementCallback = DrawIAPsListItems;
                _iaps.drawHeaderCallback  = (Rect rect) => {
                    string name = "In App Purchases Setup";
                    EditorGUI.LabelField(rect, name);
                    Rect resetButtonRect = new Rect(rect.x + rect.width - 60, rect.y, 100 - 35, EditorGUIUtility.singleLineHeight);
                    if (GUI.Button(resetButtonRect, "RESET"))
                    {
                        // Erase data file if it exists
                        InAppPurchases.Reset();
                        UnityEditor.AssetDatabase.Refresh();
                    }

                    // We'll setup a project wide selector for mocking the currency IAPs are going to use
                    Rect   currencyCodeRect = new Rect(rect.x + 200, rect.y, 100 - 35, EditorGUIUtility.singleLineHeight);
                    string label            = "Currency";
                    EditorGUI.LabelField(currencyCodeRect, label);
                    currencyCodeRect.x += 50;
                    CurrencyCode currencyCode    = _settings.CurrencyCode;
                    CurrencyCode newCurrencyCode = (CurrencyCode)EditorGUI.EnumPopup(currencyCodeRect, currencyCode);

                    if (newCurrencyCode != currencyCode)
                    {
                        _settings.CurrencyCode = newCurrencyCode;
                        EditorUtility.SetDirty(_settings);
                    }
                };
                _iaps.onRemoveCallback = (ReorderableList list) => {
                    _settings.IAPs.RemoveAt(list.index);
                    EditorUtility.SetDirty(_settings);
                };
                _iaps.onAddCallback = (ReorderableList list) => {
                    _settings.IAPs.Add(new Settings.InAppPurchase());
                    EditorUtility.SetDirty(_settings);
                };
                _iaps.elementHeight = _listItemHeight;

                // Leaderboard list
                _leaderboards = new ReorderableList(_settings.Leaderboards, typeof(Settings.Leaderboard), false, true, true, true);
                _leaderboards.drawElementCallback = DrawLeaderboardsListItems;
                _leaderboards.drawHeaderCallback  = (Rect rect) => {
                    string name = "Leaderboards Setup";
                    EditorGUI.LabelField(rect, name);
                };
                _leaderboards.onRemoveCallback = (ReorderableList list) =>
                {
                    // Erase data file if it exists
                    Leaderboard.Reset(_settings.Leaderboards[list.index].Id);
                    UnityEditor.AssetDatabase.Refresh();

                    _settings.Leaderboards.RemoveAt(list.index);
                    EditorUtility.SetDirty(_settings);
                };
                _leaderboards.onAddCallback = (ReorderableList list) => {
                    _settings.Leaderboards.Add(new Settings.Leaderboard());
                    EditorUtility.SetDirty(_settings);
                };
                _leaderboards.elementHeight = _listItemHeight;

                // Analytic Events list
                _analyticsEvents = new ReorderableList(_settings.AnalyticsEvents, typeof(string), false, true, true, true);
                _analyticsEvents.drawElementCallback = DrawAnalyticEventsListItems;
                _analyticsEvents.drawHeaderCallback  = (Rect rect) => {
                    string name = "Analytic Events";
                    EditorGUI.LabelField(rect, name);
                };
                _analyticsEvents.onRemoveCallback = (ReorderableList list) =>
                {
                    _settings.AnalyticsEvents.RemoveAt(list.index);
                    EditorUtility.SetDirty(_settings);
                };
                _analyticsEvents.onAddCallback = (ReorderableList list) => {
                    _settings.AnalyticsEvents.Add("");
                    EditorUtility.SetDirty(_settings);
                };
                _analyticsEvents.elementHeight = _listItemHeight;
            }
        }