void LoadData()
    {
        leaderboardData          = null;
        selectedLeaderboardIndex = -1;

        gameDB.InitLocalDB();
        allLeaderboards = gameDB.LoadConfig <LeaderboardConfigData>() as List <LeaderboardConfigData>;
        InitLeaderboardNames();
    }
    bool DrawLoadService()
    {
        contentColor    = GUI.contentColor;
        backgroundColor = GUI.backgroundColor;

        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = EditorHelpers.orangeColor;
        if (GUILayout.Button("Load", GUILayout.Width(60)))
        {
            LoadData();
        }

        GUI.backgroundColor = EditorHelpers.yellowColor;
        if (GUILayout.Button("New", GUILayout.Width(60)))
        {
            LeaderboardConfigData newData = new LeaderboardConfigData();
            newData.id = "New ID " + newLeaderboardNameSufix.ToString();
            ++newLeaderboardNameSufix;
            allLeaderboards.Insert(0, newData);
            InitLeaderboardNames();
            selectedLeaderboardIndex = 0;
            leaderboardData          = newData;
            ShowNotification(new GUIContent("New Leaderboard added."));
            dirty = true;
        }
        GUI.backgroundColor = EditorHelpers.greenColor;
        if (GUILayout.Button("Save", GUILayout.Width(60)))
        {
            Save();
        }
        GUI.backgroundColor = backgroundColor;
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        if (allLeaderboards == null)
        {
            EditorGUILayout.HelpBox("It seems that there is no data... try reopening the editor.", MessageType.Error);
            return(false);
        }
        if (allLeaderboards.Count > 0)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("iAPs:", GUILayout.Width(100));
            int oldIntValue = selectedLeaderboardIndex;
            selectedLeaderboardIndex = EditorGUILayout.Popup(oldIntValue, leaderboardNames, GUILayout.Width(250));
            if (oldIntValue != selectedLeaderboardIndex)
            {
                leaderboardData = allLeaderboards[selectedLeaderboardIndex];
            }
            if (leaderboardData != null)
            {
                GUI.backgroundColor = EditorHelpers.redColor;
                if (GUILayout.Button("Delete", GUILayout.Width(70)))
                {
                    if (EditorUtility.DisplayDialog("Deleting Leaderboard!", "Are you sure you want to delete Leaderboard'" + leaderboardData.id + "'?", "Yes, Delete it.", "No!"))
                    {
                        gameDB.DeleteConfig(leaderboardData.GetTableName(), leaderboardData.id);
                        allLeaderboards.Remove(leaderboardData);
                        InitLeaderboardNames();
                        selectedLeaderboardIndex = -1;
                        leaderboardData          = null;
                        ShowNotification(new GUIContent("Leaderboard deleted."));
                        return(false);
                    }
                }
                GUI.backgroundColor = backgroundColor;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        }

        return(leaderboardData != null);
    }
Пример #3
0
    private void ReadXml(string pAth)
    {
        if (string.IsNullOrEmpty(pAth))
        {
            m_Result = "文件路径不能为空";
            Debug.LogError(m_Result);
            return;
        }

        List <LeaderboardConfigData>  allLeaderboards = new List <LeaderboardConfigData>();
        List <AchievementsConfigData> allAchievements = new List <AchievementsConfigData>();
        string leaderboardTableName = new LeaderboardConfigData().GetTableName();
        string achievementTableName = new AchievementsConfigData().GetTableName();

        const string  leaderboard_perfix = "leaderboard";
        const string  achievement_perfix = "achievement";
        List <string> nodeNames          = new List <string>();

        //读取数据

        m_Xml = new XmlDocument();
        XmlReaderSettings set = new XmlReaderSettings {
            IgnoreComments = true
        };

        //这个设置是忽略xml注释文档的影响。有时候注释会影响到xml的读取
        try
        {
            m_Xml.Load(XmlReader.Create(pAth, set));
        }
        catch (IOException e)
        {
            m_Result = "IOException : \n" + e.Message;
            Debug.LogError(e.Message);
            return;
        }
        catch (XmlException e)
        {
            m_Result = "XmlException : \n" + e.Message;
            Debug.LogError(e.Message);
            return;
        }

        //解析数据
        XmlNodeList nodes = m_Xml.SelectSingleNode("resources").ChildNodes;

        foreach (XmlElement node in nodes)
        {
            string nodeName = node.GetAttribute("name");
            string prefix   = nodeName.Split('_')[0];
            if (prefix.Equals(leaderboard_perfix))
            {
                nodeNames.Add(nodeName);
                LeaderboardConfigData item_lb = new LeaderboardConfigData();
                item_lb.id    = item_lb.leaderboardId = node.InnerText;
                item_lb.name  = nodeName;
                item_lb.store = EditorHelpers.storeNames[0];
                allLeaderboards.Add(item_lb);
            }
            else if (prefix.Equals(achievement_perfix))
            {
                nodeNames.Add(nodeName);
                AchievementsConfigData item_ac = new AchievementsConfigData();
                item_ac.id       = item_ac.achievementId = node.InnerText;
                item_ac.name     = nodeName;
                item_ac.store    = EditorHelpers.storeNames[0];
                item_ac.progress = 0;
                allAchievements.Add(item_ac);
            }
        }

        //存储数据
        if (allLeaderboards.Count > 0 || allAchievements.Count > 0)
        {
            string             path = "data source=" + Application.streamingAssetsPath + "/DB/game.db";
            CocoSqliteDBHelper db   = new CocoSqliteDBHelper(path);

            if (allLeaderboards.Count > 0)
            {
                db.DeleteContents(leaderboardTableName);

                foreach (LeaderboardConfigData itemlb in allLeaderboards)
                {
                    db.InsertInto(leaderboardTableName, new[]
                    {
                        "'" + itemlb.GetId() + "'",
                        "'" + JsonMapper.ToJson(itemlb) + "'"
                    });
                }
            }
            if (allAchievements.Count > 0)
            {
                db.DeleteContents(achievementTableName);
                foreach (AchievementsConfigData itemac in allAchievements)
                {
                    db.InsertInto(achievementTableName, new[]
                    {
                        "'" + itemac.GetId() + "'",
                        "'" + JsonMapper.ToJson(itemac) + "'"
                    });
                }
            }

            m_Result = string.Format("Complete ! \nleaderboard : {0}\nachievement : {1}", allLeaderboards.Count,
                                     allAchievements.Count);
            Debug.LogError(m_Result.Replace("\n", ""));
            db.CloseSqlConnection();

            CreateProgam(nodeNames);

//			SetGPGSAndroid (xml.OuterXml);
        }
        else
        {
            m_Result = "未能读取到有效的数据";
            Debug.LogError(m_Result);
        }
    }