Update net Demo

Update net Demo
This commit is contained in:
ALEXTANG
2022-05-23 19:54:37 +08:00
parent d194b86c2d
commit 70d2d3aea5
19 changed files with 1934 additions and 25 deletions

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -19,7 +18,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>DEBUG;UNITY_EDITOR;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -27,7 +26,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;ASSETBUNDLE_ENABLE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -60,9 +59,12 @@
<Reference Include="protobuf-net">
<HintPath>UnityLib\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="protobuf-net">
<Reference Include="Google.Protobuf">
<HintPath>UnityLib\Google.Protobuf.dll</HintPath>
</Reference>
<Reference Include="UnityEditor">
<HintPath>UnityLib\UnityEditor.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
@@ -75,8 +77,8 @@
</ItemGroup>
<ItemGroup>
<Folder Include="src\GameLogic\" />
<Folder Include="src\Proto\" />
<Folder Include="src\TEngineCore\3rd\" />
<Folder Include="src\TEngineCore\Net\Demon\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

Binary file not shown.

View File

@@ -181,7 +181,7 @@ namespace TEngineCore
else
{
_stringBuilder.AppendFormat(
bColor ? "[TLogger][INFO][{0}] - <color=gray>{1}</color>" : "[TLogger][SUCCESSED][{0}] - {1}",
bColor ? "[TLogger][INFO][{0}] - <color=#00FF18>{1}</color>" : "[TLogger][SUCCESSED][{0}] - {1}",
System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"), logString);
}
break;

View File

@@ -47,9 +47,10 @@ namespace TEngineCore.Net
{
TLogger.LogError(e.Message);
TLogger.LogError("socket connect {0}:{1} failed", host, port);
//ChangeStateOnEnterFail();
return false;
}
TLogger.LogInfoSuccessd("connect server[{0}:{1}] success!!!", host, port);
m_Host = host;
m_Port = port;
return true;

View File

@@ -20,9 +20,26 @@ namespace TEngineCore.Net
return true;
}
public override void OnUpdate()
{
GameClient.Instance.OnUpdate();
var listModule = m_listModule;
for (int i = 0; i < listModule.Count; i++)
{
listModule[i].OnUpdate();
}
}
public override void OnDestroy()
{
GameClient.Instance.Shutdown();
base.OnDestroy();
}
private void RegCmdHandle()
{
var client = GameClient.Instance;
//client.RegActionHandle();
}
void InitModule()

View File

@@ -0,0 +1,57 @@
using TEngineCore;
using TEngineCore.Net;
using TEngineProto;
using UnityEngine;
using UnityEngine.UI;
namespace TEngineCore
{
public class TEngineLoginUI : UIWindow
{
#region
private Image m_imgbg;
private Text m_textTittle;
private Text m_textVer;
private Image m_imgLogo;
private GameObject m_goLoading;
private GameObject m_goLoginRoot;
private InputField m_inputName;
private InputField m_inputPassword;
private Button m_btnLogin;
protected override void ScriptGenerator()
{
m_imgbg = FindChildComponent<Image>("m_imgbg");
m_textTittle = FindChildComponent<Text>("m_textTittle");
m_textVer = FindChildComponent<Text>("m_textVer");
m_imgLogo = FindChildComponent<Image>("m_imgLogo");
m_goLoading = FindChild("m_goLoading").gameObject;
m_goLoginRoot = FindChild("m_goLoginRoot").gameObject;
m_inputName = FindChildComponent<InputField>("m_goLoginRoot/m_inputName");
m_inputPassword = FindChildComponent<InputField>("m_goLoginRoot/m_inputPassword");
m_btnLogin = FindChildComponent<Button>("m_goLoginRoot/m_btnLogin");
m_btnLogin.onClick.AddListener(OnClickLoginBtn);
}
#endregion
#region
private void OnClickLoginBtn()
{
var loginPack = new MainPack();
loginPack.Requestcode = RequestCode.User;
loginPack.Actioncode = ActionCode.Login;
loginPack.LoginPack = new LoginPack
{
Username = m_inputName.text,
Password = m_inputName.text,
};
GameClient.Instance.SendCsMsg(loginPack, CallBack);
}
private void CallBack(MainPack pack)
{
TLogger.LogInfoSuccessd("MainPack" + pack);
}
#endregion
}
}

View File

@@ -112,6 +112,15 @@ namespace TEngineCore.Net
m_connectWatcher = new ClientConnectWatcher(this);
}
~GameClient()
{
if (m_connect != null)
{
m_connect.Close();
}
m_connect = null;
}
public bool Connect(string host, int port, bool reconnect = false)
{
ResetParam();
@@ -123,7 +132,7 @@ namespace TEngineCore.Net
m_lastHost = host;
m_lastPort = port;
Status = reconnect ? GameClientStatus.StatusReconnect : GameClientStatus.StatusInit;
TLogger.LogWarning("Start connect server {0}:{1} Reconnect:{2}", host, port, reconnect);
TLogger.LogInfo("Start connect server {0}:{1} Reconnect:{2}", host, port, reconnect);
return m_connect.Connect(host, port);
}
@@ -131,6 +140,7 @@ namespace TEngineCore.Net
{
m_connect.Close();
m_status = GameClientStatus.StatusInit;
TLogger.LogWarning("GameClient Shut Down");
}
#region
@@ -255,11 +265,14 @@ namespace TEngineCore.Net
if (listHandle != null)
{
if (listHandle.Contains(msgDelegate))
if (!listHandle.Contains(msgDelegate))
{
Debug.LogFormat("-------------repeat RegCmdHandle ActionCode:{0}-----------", (ActionCode)actionId);
listHandle.Add(msgDelegate);
}
else
{
//Debug.LogFormat("-------------repeat RegCmdHandle ActionCode:{0}-----------", (ActionCode)actionId);
}
listHandle.Add(msgDelegate);
}
}
/// <summary>
@@ -437,7 +450,7 @@ namespace TEngineCore.Net
uint hashIndex = actionCode % MAX_MSG_HANDLE;
if (m_aMsgHandles[hashIndex] != null)
{
NotifyTimeout(m_aMsgHandles[hashIndex]);
//NotifyTimeout(m_aMsgHandles[hashIndex]);
RmvCheckCsMsg((int)hashIndex);
}
m_aMsgHandles[hashIndex] = resHandler;
@@ -465,13 +478,16 @@ namespace TEngineCore.Net
{
var pack = queuepPacks.Peek();
handle(pack);
if (pack != null)
{
handle(pack);
UInt32 hashIndex = (uint)pack.Actioncode % MAX_MSG_HANDLE;
UInt32 hashIndex = (uint)pack.Actioncode % MAX_MSG_HANDLE;
m_aMsgHandles[hashIndex](null);
m_aMsgHandles[hashIndex](null);
RmvCheckCsMsg((int)hashIndex);
RmvCheckCsMsg((int)hashIndex);
}
}
queuepPacks.Dequeue();
}
@@ -493,6 +509,11 @@ namespace TEngineCore.Net
public override void Release()
{
if (m_connect != null)
{
m_connect.Close();
}
m_connect = null;
base.Release();
}

View File

@@ -0,0 +1,59 @@
using UnityEngine.UI;
namespace TEngineCore
{
public class TEngineUI : UIWindow
{
#region
private Image m_imgbg;
private Text m_textTittle;
private Text m_textVer;
protected override void ScriptGenerator()
{
m_imgbg = FindChildComponent<Image>("m_imgbg");
m_textTittle = FindChildComponent<Text>("m_textTittle");
m_textVer = FindChildComponent<Text>("m_textVer");
TLogger.LogInfo("TEngineUI ScriptGenerator");
}
#endregion
protected override void RegisterEvent()
{
GameEventMgr.Instance.AddEventListener<string>(2,((s) =>
{
TLogger.LogWarning("RegisterEvent");
}));
}
protected override void BindMemberProperty()
{
base.BindMemberProperty();
TLogger.LogInfo("TEngineUI BindMemberProperty");
}
protected override void OnCreate()
{
base.OnCreate();
TLogger.LogInfo("TEngineUI OnCreate");
}
protected override void OnVisible()
{
base.OnVisible();
TLogger.LogInfo("TEngineUI OnVisible");
}
protected override void OnUpdate()
{
}
#region
#endregion
}
}

View File

@@ -6,20 +6,19 @@ using UnityEngine.UI;
namespace TEngineCore
{
public static class TipsEvent
{
public static int Log = StringId.StringToHash("TipsEvent.Log");
}
public class MsgUI : UIWindow
{
protected override void RegisterEvent()
{
base.RegisterEvent();
GameEventMgr.Instance.AddEventListener<string>(TipsEvent.Log, TipsUI.Instance.Show);
}
}
public class TipsEvent
{
public static int Log = StringId.StringToHash("TipsEvent.Log");
}
public class TipsUI : MonoBehaviour
{
//单例