Пример #1
0
 private static void SetVariable(string key, object var)
 {
     if (m_UserDataDic != null && !string.IsNullOrEmpty(key) && var != null)
     {
         UserVariable userVar = null;
         if (m_UserDataDic.ContainsKey(key))
         {
             userVar = m_UserDataDic[key];
         }
         if (var.GetType() == typeof(float))
         {
             if (userVar == null)
             {
                 userVar = UserVariable.BuildVariable(key, (float)var);
             }
             else
             {
                 userVar.FloatVar = (float)var;
             }
         }
         else if (var.GetType() == typeof(int))
         {
             if (userVar == null)
             {
                 userVar = UserVariable.BuildVariable(key, (int)var);
             }
             else
             {
                 userVar.IntVar = (int)var;
             }
         }
         else if (var.GetType() == typeof(string))
         {
             if (userVar == null)
             {
                 userVar = UserVariable.BuildVariable(key, (string)var);
             }
             else
             {
                 userVar.StrVar = (string)var;
             }
         }
         if (userVar != null)
         {
             m_UserDataDic[key] = userVar;
         }
     }
 }
Пример #2
0
        private static object GetVariable(string key, Type varType)
        {
            object var = null;

            if (m_UserDataDic != null && m_UserDataDic.ContainsKey(key))
            {
                UserVariable userVar = m_UserDataDic[key];
                if (varType == typeof(float))
                {
                    var = userVar.FloatVar;
                }
                else if (varType == typeof(int))
                {
                    var = userVar.IntVar;
                }
                else if (varType == typeof(string))
                {
                    var = userVar.StrVar;
                }
            }
            return(var);
        }
Пример #3
0
        private static void ReadData()
        {
            string   savePath     = GamePath.Instance.UserDataPath + GameConst.UserDataFileName;
            bool     isFileExists = Tools.FileManager.Instance.IsFileExists(savePath);
            UserData userData     = null;

            if (isFileExists)
            {
                string content = Tools.FileManager.Instance.ReadFileText(savePath, true);
                userData = Tools.Json.ToObject <UserData>(content);
            }
            if (userData != null && userData.UserDataList != null && m_UserDataDic != null)
            {
                for (int i = 0; i < userData.UserDataList.Count; i++)
                {
                    UserVariable userVariable = userData.UserDataList[i];
                    if (userVariable != null && !string.IsNullOrEmpty(userVariable.Key))
                    {
                        m_UserDataDic[userVariable.Key] = userVariable;
                    }
                }
            }
        }