Skip to content

Commit

Permalink
GameConfig配置,统一移动到GameConfig目录,文件名直接以+开头,简化配置的路径
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-kelly committed Aug 8, 2016
1 parent 8f5d633 commit abe109a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 50 deletions.
94 changes: 47 additions & 47 deletions KSFramework/Assets/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static IReloadableSettings[] SettingsList
{
_settingsList = new IReloadableSettings[]
{
GameConfigSettings.GetInstance(),
TestSettings.GetInstance(),
GameConfigSettings.GetInstance(),
};
}
return _settingsList;
Expand All @@ -74,17 +74,17 @@ public static void AllSettingsReload()


/// <summary>
/// Auto Generate for Tab File: "GameConfig+Base.bytes", "GameConfig+TSV.bytes"
/// Auto Generate for Tab File: "Test.bytes"
/// No use of generic and reflection, for better performance, less IL code generating
/// </summary>>
public partial class GameConfigSettings : IReloadableSettings
public partial class TestSettings : IReloadableSettings
{
public static readonly string[] TabFilePaths =
{
"GameConfig+Base.bytes", "GameConfig+TSV.bytes"
"Test.bytes"
};
static GameConfigSettings _instance;
Dictionary<string, GameConfigSetting> _dict = new Dictionary<string, GameConfigSetting>();
static TestSettings _instance;
Dictionary<string, TestSetting> _dict = new Dictionary<string, TestSetting>();

/// <summary>
/// Trigger delegate when reload the Settings
Expand All @@ -95,19 +95,19 @@ public partial class GameConfigSettings : IReloadableSettings
/// Constructor, just reload(init)
/// When Unity Editor mode, will watch the file modification and auto reload
/// </summary>
private GameConfigSettings()
private TestSettings()
{
}

/// <summary>
/// Get the singleton
/// </summary>
/// <returns></returns>
public static GameConfigSettings GetInstance()
public static TestSettings GetInstance()
{
if (_instance == null)
{
_instance = new GameConfigSettings();
_instance = new TestSettings();

_instance._ReloadAll(true);
#if UNITY_EDITOR
Expand Down Expand Up @@ -141,15 +141,15 @@ public int Count
}

/// <summary>
/// Do reload the setting file: GameConfig, no exception when duplicate primary key
/// Do reload the setting file: Test, no exception when duplicate primary key
/// </summary>
public void ReloadAll()
{
_ReloadAll(false);
}

/// <summary>
/// Do reload the setting file: GameConfig
/// Do reload the setting file: Test
/// </summary>
void _ReloadAll(bool throwWhenDuplicatePrimaryKey)
{
Expand All @@ -160,11 +160,11 @@ void _ReloadAll(bool throwWhenDuplicatePrimaryKey)
{
foreach (var row in tableFile)
{
var pk = GameConfigSetting.ParsePrimaryKey(row);
GameConfigSetting setting;
var pk = TestSetting.ParsePrimaryKey(row);
TestSetting setting;
if (!_dict.TryGetValue(pk, out setting))
{
setting = new GameConfigSetting(row);
setting = new TestSetting(row);
_dict[setting.Id] = setting;
}
else
Expand All @@ -183,7 +183,7 @@ void _ReloadAll(bool throwWhenDuplicatePrimaryKey)
}

/// <summary>
/// foreachable enumerable: GameConfig
/// foreachable enumerable: Test
/// </summary>
public static IEnumerable GetAll()
{
Expand All @@ -194,19 +194,19 @@ public static IEnumerable GetAll()
}

/// <summary>
/// GetEnumerator for `MoveNext`: GameConfig
/// GetEnumerator for `MoveNext`: Test
/// </summary>
public static IEnumerator GetEnumerator()
{
return GetInstance()._dict.Values.GetEnumerator();
}

/// <summary>
/// Get class by primary key: GameConfig
/// Get class by primary key: Test
/// </summary>
public static GameConfigSetting Get(string primaryKey)
public static TestSetting Get(string primaryKey)
{
GameConfigSetting setting;
TestSetting setting;
if (GetInstance()._dict.TryGetValue(primaryKey, out setting)) return setting;
return null;
}
Expand All @@ -217,10 +217,10 @@ public static GameConfigSetting Get(string primaryKey)
}

/// <summary>
/// Auto Generate for Tab File: "GameConfig+Base.bytes", "GameConfig+TSV.bytes"
/// Auto Generate for Tab File: "Test.bytes"
/// Singleton class for less memory use
/// </summary>
public partial class GameConfigSetting : TableRowParser
public partial class TestSetting : TableRowParser
{

/// <summary>
Expand All @@ -231,18 +231,18 @@ public partial class GameConfigSetting : TableRowParser
/// <summary>
/// Name/名字
/// </summary>
public string Value { get; private set;}
public I18N Value { get; private set;}


internal GameConfigSetting(TableRow row)
internal TestSetting(TableRow row)
{
Reload(row);
}

internal void Reload(TableRow row)
{
Id = row.Get_string(row.Values[0], "");
Value = row.Get_string(row.Values[1], "");
Value = row.Get_I18N(row.Values[1], "");
}

/// <summary>
Expand All @@ -258,17 +258,17 @@ public static string ParsePrimaryKey(TableRow row)
}

/// <summary>
/// Auto Generate for Tab File: "Test.bytes"
/// Auto Generate for Tab File: "GameConfig/+Base.bytes", "GameConfig/+TSV.bytes"
/// No use of generic and reflection, for better performance, less IL code generating
/// </summary>>
public partial class TestSettings : IReloadableSettings
public partial class GameConfigSettings : IReloadableSettings
{
public static readonly string[] TabFilePaths =
{
"Test.bytes"
"GameConfig/+Base.bytes", "GameConfig/+TSV.bytes"
};
static TestSettings _instance;
Dictionary<string, TestSetting> _dict = new Dictionary<string, TestSetting>();
static GameConfigSettings _instance;
Dictionary<string, GameConfigSetting> _dict = new Dictionary<string, GameConfigSetting>();

/// <summary>
/// Trigger delegate when reload the Settings
Expand All @@ -279,19 +279,19 @@ public partial class TestSettings : IReloadableSettings
/// Constructor, just reload(init)
/// When Unity Editor mode, will watch the file modification and auto reload
/// </summary>
private TestSettings()
private GameConfigSettings()
{
}

/// <summary>
/// Get the singleton
/// </summary>
/// <returns></returns>
public static TestSettings GetInstance()
public static GameConfigSettings GetInstance()
{
if (_instance == null)
{
_instance = new TestSettings();
_instance = new GameConfigSettings();

_instance._ReloadAll(true);
#if UNITY_EDITOR
Expand Down Expand Up @@ -325,15 +325,15 @@ public int Count
}

/// <summary>
/// Do reload the setting file: Test, no exception when duplicate primary key
/// Do reload the setting file: GameConfig, no exception when duplicate primary key
/// </summary>
public void ReloadAll()
{
_ReloadAll(false);
}

/// <summary>
/// Do reload the setting file: Test
/// Do reload the setting file: GameConfig
/// </summary>
void _ReloadAll(bool throwWhenDuplicatePrimaryKey)
{
Expand All @@ -344,11 +344,11 @@ void _ReloadAll(bool throwWhenDuplicatePrimaryKey)
{
foreach (var row in tableFile)
{
var pk = TestSetting.ParsePrimaryKey(row);
TestSetting setting;
var pk = GameConfigSetting.ParsePrimaryKey(row);
GameConfigSetting setting;
if (!_dict.TryGetValue(pk, out setting))
{
setting = new TestSetting(row);
setting = new GameConfigSetting(row);
_dict[setting.Id] = setting;
}
else
Expand All @@ -367,7 +367,7 @@ void _ReloadAll(bool throwWhenDuplicatePrimaryKey)
}

/// <summary>
/// foreachable enumerable: Test
/// foreachable enumerable: GameConfig
/// </summary>
public static IEnumerable GetAll()
{
Expand All @@ -378,19 +378,19 @@ public static IEnumerable GetAll()
}

/// <summary>
/// GetEnumerator for `MoveNext`: Test
/// GetEnumerator for `MoveNext`: GameConfig
/// </summary>
public static IEnumerator GetEnumerator()
{
return GetInstance()._dict.Values.GetEnumerator();
}

/// <summary>
/// Get class by primary key: Test
/// Get class by primary key: GameConfig
/// </summary>
public static TestSetting Get(string primaryKey)
public static GameConfigSetting Get(string primaryKey)
{
TestSetting setting;
GameConfigSetting setting;
if (GetInstance()._dict.TryGetValue(primaryKey, out setting)) return setting;
return null;
}
Expand All @@ -401,10 +401,10 @@ public static TestSetting Get(string primaryKey)
}

/// <summary>
/// Auto Generate for Tab File: "Test.bytes"
/// Auto Generate for Tab File: "GameConfig/+Base.bytes", "GameConfig/+TSV.bytes"
/// Singleton class for less memory use
/// </summary>
public partial class TestSetting : TableRowParser
public partial class GameConfigSetting : TableRowParser
{

/// <summary>
Expand All @@ -415,18 +415,18 @@ public partial class TestSetting : TableRowParser
/// <summary>
/// Name/名字
/// </summary>
public I18N Value { get; private set;}
public string Value { get; private set;}


internal TestSetting(TableRow row)
internal GameConfigSetting(TableRow row)
{
Reload(row);
}

internal void Reload(TableRow row)
{
Id = row.Get_string(row.Values[0], "");
Value = row.Get_I18N(row.Values[1], "");
Value = row.Get_string(row.Values[1], "");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,43 @@ public static void ReloadLuaCache()
}
}
}

[MenuItem("KSFramework/UI/Reload Lua + Reload UI AssetBundle")]
public static void ReloadUI()
{
if (!EditorApplication.isPlaying)
{
Log.LogError("Reload UI only when your editor is playing!");
return;
}
foreach (var kv in UIModule.Instance.UIWindows)
{
var luaController = kv.Value.UIWindow as LuaUIController;
if (luaController) // 只处理LuaUIController
{
var inOpenState = UIModule.Instance.IsOpen(kv.Key);
if (inOpenState)
UIModule.Instance.CloseWindow(kv.Key);

luaController.ReloadLua();
Log.LogWarning("Reload Lua - {0}", kv.Key);

UIModule.Instance.ReloadWindow(kv.Key, (args, err) =>
{
if (inOpenState)
UIModule.Instance.OpenWindow(kv.Key, luaController.LastOnOpenArgs);
});

}
}

}
/// <summary>
/// 找到所有的LuaUIController被进行Reload
/// 如果Reload时,UI正在打开,将对其进行关闭,并再次打开,来立刻看到效果
/// </summary>
[MenuItem("KSFramework/UI/Reload Lua + ReOpen UI #%&r")]
public static void ReloadUI()
public static void ReloadUILua()
{
if (!EditorApplication.isPlaying)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Id Value
string string
TestKey TestValue
I18NKey I am zh_CN
I18NKey I am zh_CN
I18NKey I am zh_TW

0 comments on commit abe109a

Please sign in to comment.