Skip to content

Commit

Permalink
ILRuntime模块代码整理。
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolige945 committed Mar 5, 2019
1 parent 2501b36 commit debd78e
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 59 deletions.
13 changes: 0 additions & 13 deletions Assets/Scene/King.unity
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ GameObject:
- component: {fileID: 1514884857}
- component: {fileID: 1514884854}
- component: {fileID: 1514884855}
- component: {fileID: 1514884856}
m_Layer: 0
m_Name: Main Object
m_TagString: Untagged
Expand Down Expand Up @@ -209,18 +208,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3e96d3d6f1474d34398e00281e7089f1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1514884856
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1514884849}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 870553841b8035a409c07e21850052fd, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1514884857
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
25 changes: 22 additions & 3 deletions Assets/Script/Main/CasinosContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace Casinos
{
using System;
//using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using XLua;
using FairyGUI;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Generated;

public enum _eProjectItemDisplayNameKey
{
Expand Down Expand Up @@ -55,6 +57,7 @@ public class CasinosContext
FTMgr FTMgr { get; set; }
HeadIconMgr HeadIconMgr { get; set; }
SoundMgr SoundMgr { get; set; }
CasinosILRuntime CsRuntime { get; set; }

//---------------------------------------------------------------------
public CasinosContext(bool is_editor_debug)
Expand Down Expand Up @@ -179,6 +182,11 @@ public void Update(float elapsed_tm)
LuaMgr.Update(elapsed_tm);
}

if (CsRuntime != null)
{
CsRuntime.Update();
}

if (TimerShaft != null)
{
TimerShaft.ProcessTimer((ulong)Stopwatch.ElapsedMilliseconds);
Expand Down Expand Up @@ -229,6 +237,12 @@ public void Close()
NativeAPIMsgReceiverListner = null;
}

if (CsRuntime != null)
{
CsRuntime.Destroy();
CsRuntime = null;
}

if (LuaMgr != null)
{
LuaMgr.Release();
Expand Down Expand Up @@ -272,11 +286,11 @@ public void Launch()

if (IsEditorDebug)
{
string p = Path.Combine(Environment.CurrentDirectory, "./DataOss/");
string p = Path.Combine(System.Environment.CurrentDirectory, "./DataOss/");
var di = new DirectoryInfo(p);
string p1 = di.FullName.Replace('\\', '/');

string lua_root = Environment.CurrentDirectory + "/Assets/Script.Lua/";
string lua_root = System.Environment.CurrentDirectory + "/Assets/Script.Lua/";
PathMgr.DirLuaRoot = lua_root.Replace('\\', '/');
PathMgr.DirRawRoot = p1 + "Common/Raw/";
PathMgr.DirAbRoot = p1 + Config.Platform + "/Resources.KingTexas/";
Expand All @@ -288,13 +302,18 @@ public void Launch()
PathMgr.DirAbRoot = PathMgr.CombinePersistentDataPath("Resources.KingTexas/");
}

PathMgr.DirCsRoot = PathMgr.CombinePersistentDataPath("Cs/");

PathMgr.DirAbUi = PathMgr.DirAbRoot + "Ui/";// "Resources.KingTexas/Ui/",需动态计算
PathMgr.DirAbCard = PathMgr.DirAbRoot + "Cards/";// "Resources.KingTexas/Cards/",需动态计算
PathMgr.DirAbAudio = PathMgr.DirAbRoot + "Audio/";// "Resources.KingTexas/Audio/",需动态计算
PathMgr.DirAbItem = PathMgr.DirAbRoot + "Item/";// "Resources.KingTexas/Item/",需动态计算
PathMgr.DirAbParticle = PathMgr.DirAbRoot + "Particle/";// "Resources.KingTexas/Particle/",需动态计算

LuaMgr.Launch(!version_persistent);

CsRuntime = new CasinosILRuntime();
CsRuntime.Create();
}

//-------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@
using System.IO;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Generated;
using UnityEngine;

public class MbILRuntime : MonoBehaviour
public class CasinosILRuntime
{
//-------------------------------------------------------------------------
// AppDomain是ILRuntime的入口,最好是在一个单例类中保存,整个游戏全局就一个,这里为了示例方便,每个例子里面都单独做了一个
// 大家在正式项目中请全局只创建一个AppDomain
// 全局只创建一个AppDomain
// 首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒
AppDomain AppDomain { get; set; } = new ILRuntime.Runtime.Enviorment.AppDomain();

//-------------------------------------------------------------------------
void Start()
public void Create()
{
//StartCoroutine(LoadHotFixAssembly());
LoadHotFixAssembly();
}
return;

//-------------------------------------------------------------------------
void LoadHotFixAssembly()
{
string s = Application.streamingAssetsPath;
s = s.Replace('\\', '/');
s = s.Replace("Assets/StreamingAssets", "");
s += "Script.CSharp/bin/Release/";
//string s = Application.streamingAssetsPath;
//s = s.Replace('\\', '/');
//s = s.Replace("Assets/StreamingAssets", "");
//s += "Script.CSharp/bin/Release/";

string s = Casinos.CasinosContext.Instance.PathMgr.DirCsRoot;

#if UNITY_EDITOR
// 检测Script.CSharp.dll是否存在,如不存在则给出提示
Expand All @@ -41,24 +37,29 @@ void LoadHotFixAssembly()
{
AppDomain.LoadAssembly(fs, p, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

InitializeILRuntime();
// 这里做一些ILRuntime的注册
LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);
CLRBindings.Initialize(AppDomain);

OnHotFixLoaded();
AppDomain.Invoke("CsMain", "Create", null, null);
}
}
}

//-------------------------------------------------------------------------
void InitializeILRuntime()
public void Destroy()
{
// 这里做一些ILRuntime的注册
LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);
CLRBindings.Initialize(AppDomain);
return;

AppDomain.Invoke("CsMain", "Destroy", null, null);
CLRBindings.Shutdown(AppDomain);
}

//-------------------------------------------------------------------------
void OnHotFixLoaded()
public void Update()
{
AppDomain.Invoke("CsMain", "Launch", null, null);
return;

AppDomain.Invoke("CsMain", "Update", null, null);
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions Assets/Script/Main/PathMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PathMgr
public DirType DirLaunchAbType { get; set; }// Resources.KingTexasLaunch目录类型,需动态计算
public string DirLuaRoot { get; set; }// Lua/目录,需动态计算
public string DirRawRoot { get; set; }// Raw/,需动态计算
public string DirCsRoot { get; set; }// Cs/,需动态计算
public string DirAbRoot { get; set; }// "Resources.KingTexas/",需动态计算
public string DirAbUi { get; set; }// "Resources.KingTexas/Ui/",需动态计算
public string DirAbCard { get; set; }// "Resources.KingTexas/Cards/",需动态计算
Expand Down
14 changes: 8 additions & 6 deletions DataOss/Common/CommonFileList.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Lua/Lua ED63824133B41E4FC8D681D7EB764E25
Lua/Lua.manifest C4DF85BB7C97D081835675D032D38044
Lua/lua_android.ab ED548D54A51DD909E5C3EFF3B36B0254
Lua/lua_android.ab.manifest 1693EC8A4B1F4AC31B55C05164F30E1A
Lua/lua_launch_android.ab F6700E372F5EB721121A80DA002FF628
Lua/lua_launch_android.ab.manifest C2B39FB6AAA03A871DF157B89408C7A5
Cs/Script.CSharp.dll C2B1F7678ABBBA901881B0177386EA03
Cs/Script.CSharp.pdb DD5C570E005400AF2CCF07C959341702
Lua/Lua 4713F2CCDDCCBA9C82B5267332849886
Lua/Lua.manifest 335511E4896930E28FF2B3917ACA0F0F
Lua/lua_android.ab 1ABCD92CEA32EF10F72FF74A0607B75A
Lua/lua_android.ab.manifest 93A280B4EF51E15E4965C1B1698D81A4
Lua/lua_launch_android.ab BE90531A349EA6640F4B86B1B3C73B73
Lua/lua_launch_android.ab.manifest 6950D45942E7AFAA6F9FAE3D4DFD1942
Raw/Icon/ShareIcon.png 22F237826CAE1FEB0825808D1277CB28
Raw/TbData/KingClient.db 444B8430FD358413060B67C208A39308
Raw/TbData/KingCommon.db 326C34DD7877B52C621A0EF9A687FF94
Expand Down
Binary file added DataOss/Common/Cs/Script.CSharp.dll
Binary file not shown.
Binary file added DataOss/Common/Cs/Script.CSharp.pdb
Binary file not shown.
Binary file modified DataOss/Common/Lua/Lua
Binary file not shown.
2 changes: 1 addition & 1 deletion DataOss/Common/Lua/Lua.manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ManifestFileVersion: 0
CRC: 763375712
CRC: 2640100318
AssetBundleManifest:
AssetBundleInfos:
Info_0:
Expand Down
Binary file modified DataOss/Common/Lua/lua_android.ab
Binary file not shown.
4 changes: 2 additions & 2 deletions DataOss/Common/Lua/lua_android.ab.manifest
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ManifestFileVersion: 0
CRC: 29388189
CRC: 1421441562
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: 98e6b18e15457c72cff063e5c2b829f8
Hash: 567d7e05bf8a73f62cee7d9aa6d7f1ac
TypeTreeHash:
serializedVersion: 2
Hash: 5ad585dd02dfb5016c0dad519eab8f49
Expand Down
Binary file modified DataOss/Common/Lua/lua_launch_android.ab
Binary file not shown.
4 changes: 2 additions & 2 deletions DataOss/Common/Lua/lua_launch_android.ab.manifest
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ManifestFileVersion: 0
CRC: 1432714325
CRC: 1634451464
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: e5f47bf29a7d7f0a1bb40f694043c9bc
Hash: 525dc3ea87c46d94e9661338d9dd94d4
TypeTreeHash:
serializedVersion: 2
Hash: 5ad585dd02dfb5016c0dad519eab8f49
Expand Down
1 change: 0 additions & 1 deletion ProjectSettings/GraphicsSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ GraphicsSettings:
- {fileID: 4800000, guid: deee23ab4aa38564ead2ac05e112c169, type: 3}
- {fileID: 4800000, guid: bd83c75f51f5e23498ae22ffcdfe92c3, type: 3}
- {fileID: 10720, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16002, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
Expand Down
20 changes: 16 additions & 4 deletions Script.CSharp/Main/CsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class CsContext
{
System.Action<string> TestActionDelegate;
int Count { get; set; }

//-------------------------------------------------------------------------
public static CsContext Instance { get; private set; }
Expand All @@ -13,15 +14,14 @@ public class CsContext
public CsContext()
{
Instance = this;
Debug.Log("CsContext.CsContext()");
}

//-------------------------------------------------------------------------
public void Create()
{
Debug.Log("CsContext.Create()");

TestActionDelegate = AA;
TestActionDelegate = Test;
TestActionDelegate("aaa");
}

Expand All @@ -32,8 +32,20 @@ public void Destroy()
}

//-------------------------------------------------------------------------
public void AA(string s)
public void Update()
{
Debug.Log("CsContext.AA() " + s);
Count++;
if (Count > 500)
{
Count = 0;

//Debug.Log("CsContext.Update() Count=" + Count);
}
}

//-------------------------------------------------------------------------
public void Test(string s)
{
Debug.Log("CsContext.Test() " + s);
}
}
15 changes: 12 additions & 3 deletions Script.CSharp/Main/CsMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ public class CsMain
static CsContext CsContext { get; set; }

//-------------------------------------------------------------------------
public static void Launch()
public static void Create()
{
Debug.Log("CsMain.Launch()");

CsContext = new CsContext();
CsContext.Create();
}

//-------------------------------------------------------------------------
public static void Destroy()
{
CsContext.Destroy();
}

//-------------------------------------------------------------------------
public static void Update()
{
CsContext.Update();
}
}
2 changes: 2 additions & 0 deletions Script.CSharp/PostBuild.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xcopy "D:\CasinosClientGithub\Script.CSharp\bin\Script.CSharp.dll" /y "D:\CasinosClientGithub\DataOss\Common\Cs\"
xcopy "D:\CasinosClientGithub\Script.CSharp\bin\Script.CSharp.pdb" /y "D:\CasinosClientGithub\DataOss\Common\Cs\"
8 changes: 6 additions & 2 deletions Script.CSharp/Script.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -52,4 +52,8 @@
<Content Include="UnityEngine.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

0 comments on commit debd78e

Please sign in to comment.