| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using UnityEngine;
- using UnityEngine.Networking;
- namespace WildAttack
- {
- /// <summary>
- /// Global.csv表
- /// </summary>
- public class GameModule : Singleton<GameModule>, IModule
- {
- #region Member
- Dictionary<string, string> globalDataDic;
- #endregion
- #region Override
- public void SaveData(string[] lineArr)
- {
- globalDataDic = new Dictionary<string, string>();
- for (int i = 1; i < lineArr.Length; i++)
- {
- string[] data = lineArr[i].Split(',');
- globalDataDic[data[0]] = data[1];
- }
- }
- public IEnumerator LoadCSV(string fileName, Action callback)
- {
- //刻意延迟,避免过快加载完成,因为遇到过加载完了,但其它GameObject脚本的Start()还没执行
- yield return new WaitForSeconds(0.2f);
- string sPath = CSVUtils.GetStreamingAssetPath() + "/" + fileName;
- UnityWebRequest www = UnityWebRequest.Get(sPath);
- yield return www.SendWebRequest();
- File.WriteAllText(Application.persistentDataPath + "/" + fileName, www.downloadHandler.text, Encoding.GetEncoding("utf-8"));
- www.Dispose();
- SaveData(CSVUtils.GetInstance().LoadFile(Application.persistentDataPath, fileName));
- callback();
- }
- #endregion
- #region Functions
- /// <summary>
- /// string类型value
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- public float GetData(string key)
- {
- if (globalDataDic == null) return -1;
- if (globalDataDic.ContainsKey(key))
- {
- if (key == "startMonsterXZ")
- {
- return -1;
- }
- if (key.Contains("RGB"))
- {
- return -1;
- }
- return float.Parse(globalDataDic[key]);
- }
- else
- {
- return -1;
- }
- }
- /// <summary>
- /// 双参数
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- public Vector2 GetDoubleParams(string key)
- {
- if (globalDataDic.ContainsKey(key) && globalDataDic[key].Contains("|"))
- {
- string[] strs = globalDataDic[key].Split('|');
- return new Vector2(float.Parse(strs[0]), float.Parse(strs[1]));
- }
- else
- {
- return Vector2.zero;
- }
- }
- /// <summary>
- /// RGB值
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- public string GetRGB(string key)
- {
- if (globalDataDic.ContainsKey(key) && key.Contains("RGB"))
- {
- return globalDataDic[key];
- }
- else
- {
- return "";
- }
- }
- #endregion
- }
- }
|