Skip to content

Commit

Permalink
更新tabletool v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jarjin committed Feb 20, 2021
1 parent bcd8cd7 commit fcd0543
Show file tree
Hide file tree
Showing 11 changed files with 100,662 additions and 18 deletions.
2 changes: 1 addition & 1 deletion FirClient/Assets/Scripts/Lua/Common/ManagerCenter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function ManagerCenter:Initialize()

--C# Ext Manager--
self:AddManager(ManagerNames.Timer, self:GetExtManager("TimerManager"))
self:AddManager(ManagerNames.Table, self:GetExtManager("TableManager"))
self:AddManager(ManagerNames.Config, self:GetExtManager("ConfigManager"))

--Lua Manager--
Expand All @@ -19,6 +18,7 @@ function ManagerCenter:Initialize()
self:AddManager(ManagerNames.Map, require "Manager.MapManager", true)
self:AddManager(ManagerNames.Level, require "Manager.LevelManager", true)
self:AddManager(ManagerNames.Network, require "Manager.NetworkManager", true)
self:AddManager(ManagerNames.Table, require "Data.TableManager", true)
self:AddManager(ManagerNames.UI, require "Manager.UIManager", true)
self:AddManager(ManagerNames.Panel, require "Manager.PanelManager", true)
self:AddManager(ManagerNames.Component, require "Manager.ComponentManager", true)
Expand Down
2 changes: 1 addition & 1 deletion FirClient/Assets/Scripts/Lua/Module/HeroModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function HeroModule:Initialize()

while iter:MoveNext() do
local npcItem = iter.Current
if not npcItem.isMainCharacter and npcItem.country >= 1 and npcItem.country <= 3 then
if not npcItem.isMainCharacter then
local item = {
name = npcItem.name,
itemid = npcItem.itemid,
Expand Down
24 changes: 10 additions & 14 deletions FirClient/Assets/Scripts/Lua/UIController/UIHeroCtrl.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
local UIBaseCtrl = require "UIController/UIBaseCtrl"
local UIHeroCtrl = class("UIHeroCtrl", UIBaseCtrl)

local loopView = nil
local heroModule = nil
local panelMgr = nil

function UIHeroCtrl:Awake()
local moduleMgr = MgrCenter:GetManager(ManagerNames.Module)
heroModule = moduleMgr:GetModule(ModuleNames.Hero)
heroModule.Initialize()
self.heroModule = moduleMgr:GetModule(ModuleNames.Hero)
self.heroModule.Initialize()

panelMgr = MgrCenter:GetManager(ManagerNames.Panel)
panelMgr:CreatePanel(self, UILayer.Common, UiNames.Hero, self.OnCreateOK)
self.panelMgr = MgrCenter:GetManager(ManagerNames.Panel)
self.panelMgr:CreatePanel(self, UILayer.Common, UiNames.Hero, self.OnCreateOK)
logWarn("UIHeroCtrl.Awake--->>")
end

Expand All @@ -23,22 +19,22 @@ function UIHeroCtrl:OnCreateOK(behaviour)

local scrollView = self.gameObject.transform:Find("ScrollViewRoot")
if not isnil(scrollView) then
local totalCount = heroModule:GetDataListSize()
loopView = LuaUtil.GetComponent(scrollView.gameObject, ComponentNames.LoopListBox)
loopView:InitListView(self, totalCount, self.OnItemUpdate)
local totalCount = self.heroModule:GetDataListSize()
self.loopView = LuaUtil.GetComponent(scrollView.gameObject, ComponentNames.LoopListBox)
self.loopView:InitListView(self, totalCount, self.OnItemUpdate)
end
logWarn("OnCreateOK--->>"..self.gameObject.name)
end

function UIHeroCtrl:OnItemUpdate(index)
local item = loopView:NewListViewItem("ItemPrefab")
local item = self.loopView:NewListViewItem("ItemPrefab")
self:SetItemData(index, item.gameObject)
return item
end

function UIHeroCtrl:SetItemData(index, gameObj)
index = index + 1
local item = heroModule:GetDataByIndex(index)
local item = self.heroModule:GetDataByIndex(index)

local prefabVar = LuaUtil.GetComponent(gameObj, ComponentNames.ItemPrefabVar)
if prefabVar ~= nil then
Expand All @@ -59,7 +55,7 @@ end
--关闭事件--
function UIHeroCtrl:Close()
self:Dispose()
panelMgr:ClosePanel(UiNames.Skill)
self.panelMgr:ClosePanel(UiNames.Skill)
end

function UIHeroCtrl:Show(isShow)
Expand Down
3 changes: 2 additions & 1 deletion FirServer/FirSango/Common/GameBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FirServer;
using FirCommon.Data;
using FirServer;
using FirServer.Common;
using GameLibs.FirSango.Managers;

Expand Down
133 changes: 133 additions & 0 deletions FirServer/FirSango/Data/CommonClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;

namespace FirCommon.Data
{
public sealed class Vector2SerializationSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
Vector2 v = (Vector2)obj;
info.AddValue("x", v.x);
info.AddValue("y", v.y);
}

public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
Vector2 v = (Vector2)obj;
v.x = info.GetSingle("x");
v.y = info.GetSingle("y");
return (object)v;
}
}

public sealed class Vector3SerializationSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
Vector3 v = (Vector3)obj;
info.AddValue("x", v.x);
info.AddValue("y", v.y);
info.AddValue("z", v.z);
}

public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
Vector3 v = (Vector3)obj;
v.x = info.GetSingle("x");
v.y = info.GetSingle("y");
v.z = info.GetSingle("z");
return (object)v;
}
}

public sealed class ColorSerializationSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
Color v = (Color)obj;
info.AddValue("r", v.r);
info.AddValue("g", v.g);
info.AddValue("b", v.b);
info.AddValue("a", v.a);
}

public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
Color v = (Color)obj;
v.r = info.GetSingle("r");
v.g = info.GetSingle("g");
v.b = info.GetSingle("b");
v.a = info.GetSingle("a");
return (object)v;
}
}

public sealed class Color32SerializationSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
Color32 v = (Color32)obj;
info.AddValue("r", v.r);
info.AddValue("g", v.g);
info.AddValue("b", v.b);
info.AddValue("a", v.a);
}

public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
Color32 v = (Color32)obj;
v.r = info.GetByte("r");
v.g = info.GetByte("g");
v.b = info.GetByte("b");
v.a = info.GetByte("a");
return (object)v;
}
}

public class ClassTypeBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
return null;
}
}

public class SerializeUtil
{
public static void Serialize(string binraryPath, object instance)
{
IFormatter serializer = new BinaryFormatter();
SurrogateSelector selector = new SurrogateSelector();
var context = new StreamingContext(StreamingContextStates.All);
selector.AddSurrogate(typeof(Vector2), context, new Vector2SerializationSurrogate());
selector.AddSurrogate(typeof(Vector3), context, new Vector3SerializationSurrogate());
selector.AddSurrogate(typeof(Color), context, new ColorSerializationSurrogate());
selector.AddSurrogate(typeof(Color32), context, new Color32SerializationSurrogate());
serializer.SurrogateSelector = selector;
using (var saveFile = new FileStream(binraryPath, FileMode.Create, FileAccess.Write))
{
serializer.Serialize(saveFile, instance);
}
}

public static T Deserialize<T>(string fullPath) where T : class
{
IFormatter serializer = new BinaryFormatter();
SurrogateSelector selector = new SurrogateSelector();
var context = new StreamingContext(StreamingContextStates.All);
selector.AddSurrogate(typeof(Vector2), context, new Vector2SerializationSurrogate());
selector.AddSurrogate(typeof(Vector3), context, new Vector3SerializationSurrogate());
selector.AddSurrogate(typeof(Color), context, new ColorSerializationSurrogate());
selector.AddSurrogate(typeof(Color32), context, new Color32SerializationSurrogate());
serializer.SurrogateSelector = selector;
using (var loadFile = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
{
return serializer.Deserialize(loadFile) as T;
}
}
}
}
10 changes: 10 additions & 0 deletions FirServer/FirSango/Data/CommonEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FirCommon.Data
{
public enum CountryType : byte
{
NONE = 0, //主角
WEI = 1, //魏国
SHU = 2, //蜀国
WU = 3, //吴国
}
}
3 changes: 3 additions & 0 deletions FirServer/FirSango/FirSango.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
<Reference Include="Google.Protobuf">
<HintPath>..\..\..\..\firsango\FirServer\Libraries\Protobuf\Google.Protobuf.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\Libraries\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
6 changes: 5 additions & 1 deletion FirServer/FirSango/GameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void Initialize()
{
InitManager();
RegHandler();
TestTable();
//TestDBServer(); //需要安装Mongodb
}

Expand All @@ -33,12 +34,15 @@ void InitManager()
roomMgr.Initialize();
}

private async void TestDBServer()
void TestTable()
{
//Test Table
var item = tableMgr.globalConfigTable.GetItemByKey("CommonWhite");
logger.Info(string.Format("id={0} value={1}", item.id, item.value));
}

private async void TestDBServer()
{
///Open DB
dataMgr.Connect(GameConst.DB_URL);
//dataMgr.DropDB(GameConst.DB_NAME);
Expand Down
3 changes: 3 additions & 0 deletions FirServer/FirServer/FirServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
<Reference Include="Google.Protobuf">
<HintPath>..\..\..\..\firsango\FirServer\Libraries\Protobuf\Google.Protobuf.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\Libraries\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Binary file added FirServer/Libraries/UnityEngine.dll
Binary file not shown.
Loading

0 comments on commit fcd0543

Please sign in to comment.