94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using UnityEngine;
|
|
|
|
namespace Touka
|
|
{
|
|
public class TKGLoadPlistConfig
|
|
{
|
|
static string resourcePath = Application.dataPath;
|
|
static string extraStr = ".plist";
|
|
|
|
public static PlayerPrefPair[] GetToukaConfig( string _configFile , string region)
|
|
{
|
|
return GetAllFromPlist(resourcePath + "/Configs/"+region+"/" + _configFile + extraStr);
|
|
}
|
|
|
|
public static PlayerPrefPair[] GetAllFromPlist(string _configPath)
|
|
{
|
|
if (File.Exists(_configPath))
|
|
{
|
|
object plist = TKGPlist.readPlist(_configPath);
|
|
Dictionary<string, object> parsed = plist as Dictionary<string, object>;
|
|
|
|
PlayerPrefPair[] tempPlayerPrefs = new PlayerPrefPair[parsed.Count];
|
|
int i = 0;
|
|
foreach (KeyValuePair<string, object> pair in parsed)
|
|
{
|
|
if (pair.Value.GetType() == typeof(double))
|
|
{
|
|
// Some float values may come back as double, so convert them back to floats
|
|
tempPlayerPrefs[i] = new PlayerPrefPair() { Key = pair.Key, Value = (float)(double)pair.Value };
|
|
}
|
|
else
|
|
{
|
|
tempPlayerPrefs[i] = new PlayerPrefPair() { Key = pair.Key, Value = pair.Value };
|
|
}
|
|
|
|
i++;
|
|
}
|
|
return tempPlayerPrefs;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError(_configPath + " Not Exist!");
|
|
return new PlayerPrefPair[0];
|
|
}
|
|
}
|
|
|
|
public static PlayerPrefPair[] GetAllFromXML(string _configPath)
|
|
{
|
|
if (File.Exists(resourcePath + _configPath + ".xml"))
|
|
{
|
|
TextAsset configText = (TextAsset)Resources.Load(_configPath);
|
|
|
|
object plist = TKGPlist.readPlistSource(configText.text);
|
|
Dictionary<string, object> parsed = plist as Dictionary<string, object>;
|
|
|
|
PlayerPrefPair[] tempPlayerPrefs = new PlayerPrefPair[parsed.Count];
|
|
int i = 0;
|
|
foreach (KeyValuePair<string, object> pair in parsed)
|
|
{
|
|
if (pair.Value.GetType() == typeof(double))
|
|
{
|
|
// Some float values may come back as double, so convert them back to floats
|
|
tempPlayerPrefs[i] = new PlayerPrefPair() { Key = pair.Key, Value = (float)(double)pair.Value };
|
|
}
|
|
else
|
|
{
|
|
tempPlayerPrefs[i] = new PlayerPrefPair() { Key = pair.Key, Value = pair.Value };
|
|
}
|
|
|
|
i++;
|
|
}
|
|
return tempPlayerPrefs;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError(_configPath + " Not Exist!");
|
|
return new PlayerPrefPair[0];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public struct PlayerPrefPair
|
|
{
|
|
public string Key { get; set; }
|
|
|
|
public object Value { get; set; }
|
|
}
|