summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/LuaEngine
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/LuaEngine
+scripts
Diffstat (limited to 'Client/Assets/Scripts/LuaEngine')
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core.meta5
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/DelManager.cs52
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/DelManager.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/Encryption.cs91
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/Encryption.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs106
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs33
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs293
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs291
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs410
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/Single.cs59
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/Single.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/Timer.cs142
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/Timer.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs271
-rw-r--r--Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/Hotfix.cs899
-rw-r--r--Client/Assets/Scripts/LuaEngine/Hotfix.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/HotfixManager.cs454
-rw-r--r--Client/Assets/Scripts/LuaEngine/HotfixManager.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/HotfixPatch.cs75
-rw-r--r--Client/Assets/Scripts/LuaEngine/HotfixPatch.cs.meta12
-rw-r--r--Client/Assets/Scripts/LuaEngine/LuaEngine.cs130
-rw-r--r--Client/Assets/Scripts/LuaEngine/LuaEngine.cs.meta8
-rw-r--r--Client/Assets/Scripts/LuaEngine/XLua.cs51
-rw-r--r--Client/Assets/Scripts/LuaEngine/XLua.cs.meta8
31 files changed, 3486 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/LuaEngine/Core.meta b/Client/Assets/Scripts/LuaEngine/Core.meta
new file mode 100644
index 00000000..615bb0e3
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core.meta
@@ -0,0 +1,5 @@
+fileFormatVersion: 2
+guid: 9dc069c0a1590cd48895fcd1d8e6f1ec
+folderAsset: yes
+DefaultImporter:
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/DelManager.cs b/Client/Assets/Scripts/LuaEngine/Core/DelManager.cs
new file mode 100644
index 00000000..9fdab099
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/DelManager.cs
@@ -0,0 +1,52 @@
+//
+// DelManager.cs
+// Created by huailiang.peng on 2016-3-11 18:10:39
+//
+
+
+using UnityEngine;
+using System.Collections;
+using UILib;
+
+
+public class DelManager
+{
+ public delegate void VoidDelegate();
+
+ public delegate void BoolDelegate(bool state);
+
+ public delegate void StringDelegate(string str);
+
+ public delegate void FloatDelegate(float delta);
+
+ public delegate void VectorDelegate(Vector2 delta);
+
+ public delegate void ObjectDelegate(GameObject obj);
+
+ public delegate void KeyCodeDelegate(KeyCode key);
+
+ public delegate void GameObjDelegate(GameObject go);
+
+ public delegate void BytesDelegate(byte[] bytes);
+
+ public delegate void BtnDelegate(XUIButton btn);
+
+ public delegate void SprDelegate(XUISprite spr);
+
+ public static GameObjDelegate onGoClick = null;
+
+ public static ButtonClickEventHandler fButtonDelegate = null;
+
+ public static ButtonClickEventHandler sButtonDelegate = null;
+
+ public static SpriteClickEventHandler sprClickEventHandler = null;
+
+ public static void Clear()
+ {
+ fButtonDelegate = null;
+ sButtonDelegate = null;
+ onGoClick = null;
+ sprClickEventHandler = null;
+ }
+
+} \ No newline at end of file
diff --git a/Client/Assets/Scripts/LuaEngine/Core/DelManager.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/DelManager.cs.meta
new file mode 100644
index 00000000..3f4528a5
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/DelManager.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 616b638dde85fea43bd7784e15561dd2
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/Encryption.cs b/Client/Assets/Scripts/LuaEngine/Core/Encryption.cs
new file mode 100644
index 00000000..16c675ff
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/Encryption.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Security.Cryptography;
+using System.IO;
+using System.Text;
+
+
+namespace LuaCore
+{
+
+ /// <summary>
+ /// Summary description for Encryption
+ /// </summary>
+ public class Encryption
+ {
+
+ /// <summary>
+ /// Default Key
+ /// </summary>
+ public const string Key = "bmc.1001";
+
+
+
+ public static string Encrypt(string pToEncrypt)
+ {
+ return Encrypt(pToEncrypt, Key);
+ }
+
+
+ /// <summary>
+ /// 加密方法
+ /// </summary>
+ public static string Encrypt(string pToEncrypt, string sKey)
+ {
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+
+ Encoding coding = new UTF8Encoding(false);
+
+ //把字符串放到byte数组中
+ byte[] inputByteArray = coding.GetBytes(pToEncrypt);
+
+ //建立加密对象的密钥和偏移量
+ //原文使用ASCIIEncoding.ASCII方法的GetBytes方法
+ //使得输入密码必须输入英文文本
+ des.Key = coding.GetBytes(sKey);// ASCIIEncoding.ASCII.GetBytes(sKey);
+ des.IV = coding.GetBytes(sKey);// ASCIIEncoding.ASCII.GetBytes(sKey);
+ //创建其支持存储区为内存的流
+ MemoryStream ms = new MemoryStream();
+ //将数据流链接到加密转换的流
+ CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
+ //Write the byte array into the crypto stream
+ //(It will end up in the memory stream)
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ //用缓冲区的当前状态更新基础数据源或储存库,随后清除缓冲区
+ cs.FlushFinalBlock();
+ //Get the data back from the memory stream, and into a string
+ byte[] EncryptData = (byte[])ms.ToArray();
+ return System.Convert.ToBase64String(EncryptData, 0, EncryptData.Length);
+ }
+
+
+ public static string Decrypt(string pToDecrypt)
+ {
+ return Decrypt(pToDecrypt, Key);
+ }
+
+
+ /// <summary>
+ /// 解密方法
+ /// </summary>
+ public static string Decrypt(string pToDecrypt, string sKey)
+ {
+ Encoding coding = new UTF8Encoding(false);
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
+ //Put the input string into the byte array
+ byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
+
+ //建立加密对象的密钥和偏移量,此值重要,不能修改
+ des.Key = coding.GetBytes(sKey);// ASCIIEncoding.ASCII.GetBytes(sKey);
+ des.IV = coding.GetBytes(sKey);// ASCIIEncoding.ASCII.GetBytes(sKey);
+ MemoryStream ms = new MemoryStream();
+ CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
+ //Flush the data through the crypto stream into the memory stream
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+ return coding.GetString(ms.ToArray());
+ }
+
+
+ }
+
+} \ No newline at end of file
diff --git a/Client/Assets/Scripts/LuaEngine/Core/Encryption.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/Encryption.cs.meta
new file mode 100644
index 00000000..74002f6d
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/Encryption.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: bb8d169276870284da5919e49f4a3d6b
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs b/Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs
new file mode 100644
index 00000000..8c141a25
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs
@@ -0,0 +1,106 @@
+using UnityEngine;
+using System.Collections;
+using LuaInterface;
+using System.Text;
+
+public class LuaDlg : MonoBehaviour
+{
+
+ private LuaScriptMgr mgr;
+
+ private string m_name
+ {
+ get { return name.Substring(0, 1).ToUpper() + name.Substring(1); }
+ }
+
+ private const string AWAKE = "Awake";
+ private const string START = "Start";
+ private const string ENABLE = "OnEnable";
+ private const string DISABLE = "OnDisable";
+ private const string HIDE = "OnHide";
+ private const string SHOW = "OnShow";
+ private const string DESTROY = "OnDestroy";
+
+ void Awake()
+ {
+ mgr = HotfixManager.Instance.GetLuaScriptMgr();
+ mgr.DoFile("Lua" + m_name + ".lua");
+ LuaFunction func = mgr.GetLuaFunction(StrAppend(AWAKE));
+ if (func != null) func.Call(gameObject);
+ }
+
+
+ void Start()
+ {
+ if (mgr != null)
+ {
+ LuaFunction func = mgr.GetLuaFunction(StrAppend(START));
+ if (func != null) func.Call();
+ }
+ }
+
+
+ void OnEnable()
+ {
+ if (mgr != null)
+ {
+ LuaFunction func = mgr.GetLuaFunction(StrAppend(ENABLE));
+ if (func != null) func.Call();
+ }
+ }
+
+
+
+ void OnDisable()
+ {
+ if (mgr != null)
+ {
+ LuaFunction func = mgr.GetLuaFunction(StrAppend(DISABLE));
+ if (func != null) func.Call();
+ }
+ }
+
+ public void OnHide()
+ {
+ if (mgr != null)
+ {
+ LuaFunction func = mgr.GetLuaFunction(StrAppend(HIDE));
+ if (func != null) func.Call();
+ }
+ }
+
+
+ public void OnDestroy()
+ {
+ if (mgr != null)
+ {
+ try
+ {
+ LuaFunction func = mgr.GetLuaFunction(StrAppend(DESTROY));
+ if (func != null) func.Call();
+ }
+ catch { };
+ }
+ }
+
+
+ public void OnShow()
+ {
+ if (mgr != null)
+ {
+ LuaFunction func = mgr.GetLuaFunction(StrAppend(SHOW));
+ if (func != null) func.Call();
+ }
+ }
+
+
+ private string StrAppend(string func)
+ {
+ StringBuilder sb = new StringBuilder("Lua");
+ sb.Append(m_name);
+ sb.Append(".");
+ sb.Append(func);
+ return sb.ToString();
+ }
+
+}
diff --git a/Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs.meta
new file mode 100644
index 00000000..7543a805
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/LuaDlg.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 0ddc1b356def76a49bb91125f9240449
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs b/Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs
new file mode 100644
index 00000000..336ce831
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs
@@ -0,0 +1,33 @@
+using System;
+using XUtliPoolLib;
+
+public class LuaGameInfo : ILuaGameInfo
+{
+ private static LuaGameInfo _single = null;
+ public static LuaGameInfo single
+ {
+ get
+ {
+ if (_single == null)
+ {
+ _single = new LuaGameInfo();
+ }
+ return _single;
+ }
+ }
+
+ public string name { get; set; }
+ public uint exp { get; set; }
+ public uint maxexp { get; set; }
+ public uint level { get; set; }
+ public int ppt { get; set; }
+
+
+ public uint coin { get; set; }
+ public uint dia { get; set; }
+ public uint energy { get; set; }
+
+ public uint draggon { get; set; }
+
+}
+
diff --git a/Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs.meta
new file mode 100644
index 00000000..5aa4a964
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/LuaGameInfo.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 3bff6a9f0c5f157419eeef2be877c182
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs b/Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs
new file mode 100644
index 00000000..b5633bcd
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs
@@ -0,0 +1,293 @@
+using UnityEngine;
+using System.Collections.Generic;
+using XUtliPoolLib;
+
+public struct LuaNode
+{
+ public uint id;
+ public string name;
+ public GameObject go;
+ public LuaDlg dlg;
+ public List<string> childs;
+};
+
+
+
+public class LuaUIManager : ILuaUIManager
+{
+ private Dictionary<uint, LuaNode> m_stask = new Dictionary<uint, LuaNode>();
+
+ private static LuaUIManager _single;
+ public static LuaUIManager Instance
+ {
+ get
+ {
+ if (_single == null) _single = new LuaUIManager();
+ return _single;
+ }
+ }
+
+
+ public bool IsUIShowed()
+ {
+ bool show = false;
+ foreach (var item in m_stask)
+ {
+ if (item.Value.go != null && item.Value.go.activeInHierarchy)
+ {
+ show = true;
+ break;
+ }
+ }
+ return show;
+ }
+
+
+ public bool Load(string name)
+ {
+ uint id = XCommon.singleton.XHash(name);
+ if (!Find(id))
+ {
+ GameObject root = UICamera.mainCamera.gameObject;
+ GameObject go = XResourceLoaderMgr.singleton.CreateFromPrefab(name) as GameObject;
+ go.transform.parent = UICamera.mainCamera.transform;
+ go.transform.localPosition = Vector3.zero;
+ go.transform.localRotation = Quaternion.identity;
+ go.transform.localScale = Vector3.one;
+ go.layer = root.layer;
+ go.name = name.Substring(name.LastIndexOf('/') + 1);
+ LuaNode node = AttachLuaDlg(go, name, id);
+ if (!m_stask.ContainsKey(id))
+ {
+ m_stask.Add(id, node);
+ node.dlg.OnShow();
+ }
+ return true;
+ }
+ else
+ {
+ m_stask[id].go.SetActive(true);
+ m_stask[id].dlg.OnShow();
+ }
+ return false;
+ }
+
+ private LuaNode AttachLuaDlg(GameObject go,string name,uint id)
+ {
+ LuaNode node = new LuaNode();
+ LuaDlg luadlg = go.AddComponent<LuaDlg>();
+ node.dlg = luadlg;
+ node.go = go;
+ node.name = name;
+ node.id = id;
+ return node;
+ }
+
+ private GameObject SetupChild(Transform parent, string child)
+ {
+ uint id = XCommon.singleton.XHash(child);
+ bool exist = Find(id);
+ GameObject go = exist ? m_stask[id].go : XResourceLoaderMgr.singleton.CreateFromPrefab(child) as GameObject;
+ go.transform.parent = parent;
+ go.transform.localPosition = Vector3.zero;
+ go.transform.localRotation = Quaternion.identity;
+ go.transform.localScale = Vector3.one;
+ if (!exist)
+ {
+ go.name = child.Substring(child.LastIndexOf('/') + 1);
+ LuaNode node = AttachLuaDlg(go, child, id);
+ if (!m_stask.ContainsKey(id))
+ {
+ m_stask.Add(id, node);
+ node.dlg.OnShow();
+ }
+ }
+ else
+ {
+ m_stask[id].go.SetActive(true);
+ m_stask[id].dlg.OnShow();
+ }
+ return go;
+ }
+
+
+ public GameObject AttachHandler(string root, string child)
+ {
+ uint root_id = XCommon.singleton.XHash(root);
+ if (m_stask.ContainsKey(root_id))
+ {
+ var childs = m_stask[root_id].childs;
+ if (childs == null) childs = new List<string>();
+ if (!childs.Contains(child)) childs.Add(child);
+ GameObject go = m_stask[root_id].go;
+ if (go != null)
+ {
+ Transform t = go.transform.Find("Bg/Handler");
+ if (t != null)
+ {
+ return SetupChild(t, child);
+ }
+ }
+ else
+ {
+ XDebug.singleton.AddErrorLog("cache task go is nil");
+ }
+ }
+ else
+ {
+ XDebug.singleton.AddErrorLog("There is no such root is stack ", root, " child: ", child);
+ }
+ return null;
+ }
+
+ public void AttachHandlers(string root, params string[] childs)
+ {
+ for (int i = 0; i < childs.Length; i++)
+ {
+ AttachHandler(root, childs[i]);
+ }
+ }
+
+
+ public void DestroyChilds(string root)
+ {
+ uint root_id = XCommon.singleton.XHash(root);
+ DestroyChilds(root_id);
+ }
+
+
+ private void DestroyChilds(uint root)
+ {
+ if (m_stask.ContainsKey(root))
+ {
+ var childs = m_stask[root].childs;
+ if (childs != null)
+ {
+ for (int i = 0; i < childs.Count; i++)
+ {
+ if (!string.IsNullOrEmpty(childs[i])) Destroy(childs[i]);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 遍历所有 效率较低
+ /// </summary>
+ public void DetchHandler(string child)
+ {
+ foreach (var item in m_stask)
+ {
+ if (item.Value.childs != null)
+ {
+ item.Value.childs.RemoveAll(x => x == child);
+ }
+ }
+ }
+
+ public void DetchHandler(string root, string child)
+ {
+ uint root_id = XCommon.singleton.XHash(root);
+ if (m_stask.ContainsKey(root_id))
+ {
+ var childs = m_stask[root_id].childs;
+ if (childs != null)
+ {
+ childs.RemoveAll(x => x == child);
+ }
+ }
+ }
+
+
+ public bool Hide(string name)
+ {
+ uint id = XCommon.singleton.XHash(name);
+ return IDHide(id);
+ }
+
+
+ public GameObject GetDlgObj(string name)
+ {
+ uint code = XCommon.singleton.XHash(name);
+ if (m_stask.ContainsKey(code))
+ {
+ return m_stask[code].go;
+ }
+ return null;
+ }
+
+ public bool IDHide(uint id)
+ {
+ if (m_stask.Count > 0 && Find(id))
+ {
+ LuaNode node = m_stask[id];
+ if (node.go != null)
+ node.go.SetActive(false);
+ node.dlg.OnHide();
+ return true;
+ }
+ return true;
+ }
+
+
+ public bool Destroy(string name)
+ {
+ uint id = XCommon.singleton.XHash(name);
+ return IDDestroy(id);
+ }
+
+ public bool IDDestroy(uint id)
+ {
+ if (m_stask.Count > 0 && Find(id))
+ {
+ LuaNode node = m_stask[id];
+ //先删子节点 再删自身
+ DestroyChilds(node.name);
+ MonoBehaviour.Destroy(node.go);
+ if (m_stask.ContainsKey(id)) m_stask.Remove(id);
+ return true;
+ }
+ return false;
+ }
+
+ private void DestroyWithoutChild(uint id)
+ {
+ if (m_stask.Count > 0 && Find(id))
+ {
+ LuaNode node = m_stask[id];
+ MonoBehaviour.Destroy(node.go);
+ }
+ }
+
+ public void Clear()
+ {
+ List<uint> list = new List<uint>(m_stask.Keys);
+ for (int i = 0; i < list.Count; i++)
+ {
+ DestroyWithoutChild(list[i]);
+ }
+ m_stask.Clear();
+ }
+
+
+
+ private bool Find(uint id)
+ {
+ if (m_stask.ContainsKey(id))
+ {
+ if (m_stask[id].go != null)
+ {
+ return true;
+ }
+ else
+ {
+ XDebug.singleton.AddGreenLog("remove id: "+id);
+ m_stask.Remove(id);
+ return false;
+ }
+ }
+ return false;
+ }
+
+
+}
diff --git a/Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs.meta
new file mode 100644
index 00000000..3749d325
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/LuaUIManager.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 04b7668aaaa8c4f40a6ea5323b0117ae
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs b/Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs
new file mode 100644
index 00000000..3ccd0d5a
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs
@@ -0,0 +1,291 @@
+//
+// PrivateExtensions.cs
+// Created by huailiang.peng on 2016/04/15 11:39:07
+//
+using UnityEngine;
+using System.Reflection;
+using System.Collections.Generic;
+using System;
+
+public static class PrivateExtensions
+{
+
+ // Invoke method
+ public static T CallPrivateMethodGeneric<T>(this object obj, string name, params object[] param)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ Type[] argTypes = new Type[param.Length];
+ for (int i=0; i<argTypes.Length; i++)
+ argTypes [i] = param [i].GetType ();
+ List<Type[]> argTypeList = PublicExtensions.CastNumberParameters (param, argTypes);
+ MethodInfo method = null;
+ try{
+ method = type.GetMethod (name, flags);
+ } catch {
+ for (int i=0; i<argTypeList.Count; i++) {
+ method = type.GetMethod (name, argTypeList [i]);
+ if (method != null)
+ break;
+ }
+ }
+ if (method == null)
+ return default (T);
+
+ ParameterInfo[] pars = method.GetParameters();
+ object[] convertedParameters = new object[pars.Length];
+ for (int i=0; i<pars.Length; i++)
+ {
+ if (pars[i].ParameterType != typeof(object))
+ convertedParameters[i] = Convert.ChangeType(param[i], pars[i].ParameterType);
+ else
+ convertedParameters[i] = param[i];
+ }
+ return (T)method.Invoke(obj, convertedParameters);
+ }
+
+ public static object CallPrivateMethod(this object obj, string name, params object[] param)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ Type[] argTypes = new Type[param.Length];
+ for (int i=0; i<argTypes.Length; i++)
+ argTypes [i] = param [i].GetType ();
+ List<Type[]> argTypeList = PublicExtensions.CastNumberParameters (param, argTypes);
+ MethodInfo method = null;
+ try{
+ method = type.GetMethod (name, flags);
+ } catch {
+ for (int i=0; i<argTypeList.Count; i++) {
+ method = type.GetMethod (name, argTypeList [i]);
+ if (method != null)
+ break;
+ }
+ }
+ if (method == null)
+ return null;
+
+ ParameterInfo[] pars = method.GetParameters();
+ object[] convertedParameters = new object[pars.Length];
+ for (int i=0; i<pars.Length; i++)
+ {
+ if (pars[i].ParameterType != typeof(object))
+ convertedParameters[i] = Convert.ChangeType(param[i], pars[i].ParameterType);
+ else
+ convertedParameters[i] = param[i];
+ }
+ return method.Invoke(obj, convertedParameters);
+ }
+
+ public static object CallStaticPrivateMethod(string typeName, string name, params object[] param)
+ {
+ BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy;
+ Type type = Type.GetType (typeName);
+ Type[] argTypes = new Type[param.Length];
+ for (int i=0; i<argTypes.Length; i++)
+ argTypes [i] = param [i].GetType ();
+ List<Type[]> argTypeList = PublicExtensions.CastNumberParameters (param, argTypes);
+ MethodInfo method = null;
+ try{
+ method = type.GetMethod (name, flags);
+ } catch {
+ for (int i=0; i<argTypeList.Count; i++) {
+ method = type.GetMethod (name, argTypeList [i]);
+ if (method != null)
+ break;
+ }
+ }
+ if (method == null)
+ return null;
+
+ ParameterInfo[] pars = method.GetParameters();
+ object[] convertedParameters = new object[pars.Length];
+ for (int i=0; i<pars.Length; i++)
+ {
+ if (pars[i].ParameterType != typeof(object))
+ convertedParameters[i] = Convert.ChangeType(param[i], pars[i].ParameterType);
+ else
+ convertedParameters[i] = param[i];
+ }
+ return method.Invoke(null, convertedParameters);
+ }
+
+ // Get feild, property
+ public static T GetPrivateFieldGeneric<T>(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ FieldInfo field = PublicExtensions.GetFieldInfo (type, name, flags);
+ if (field != null)
+ return (T)field.GetValue(obj);
+ else
+ return (T)default(T);
+ }
+ public static object GetPrivateField(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ FieldInfo field = PublicExtensions.GetFieldInfo (type, name, flags);
+ if (field != null)
+ return field.GetValue(obj);
+ else
+ return null;
+ }
+ public static object GetStaticPrivateField(string typeName, string name)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic;
+ Type type = Type.GetType (typeName);
+ FieldInfo field = PublicExtensions.GetFieldInfo (type, name, flags);
+ if (field != null)
+ return field.GetValue(null);
+ else
+ return null;
+ }
+
+ public static T GetPrivatePropertyGeneric<T>(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ PropertyInfo field = PublicExtensions.GetPropertyInfo(type, name, flags);
+ if (field != null)
+ return (T)field.GetGetMethod(true).Invoke (obj, null);
+ else
+ return default(T);
+ }
+ public static object GetPrivateProperty(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ PropertyInfo field = PublicExtensions.GetPropertyInfo(type, name, flags);
+ if (field != null)
+ return field.GetGetMethod(true).Invoke (obj, null);
+ else
+ return null;
+ }
+ public static object GetStaticPrivateProperty(string typeName, string name)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = Type.GetType (typeName);
+ PropertyInfo field = PublicExtensions.GetPropertyInfo(type, name, flags);
+ if (field != null)
+ return field.GetValue(null, null);
+ else
+ return null;
+ }
+
+ // Set field, propertry
+ public static void SetPrivateField(this object obj, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ FieldInfo field = PublicExtensions.GetFieldInfo(type, name, flags);
+ if (field != null) {
+ if (field.FieldType == typeof(int)){
+ var number = Convert.ToInt32 (value);
+ field.SetValue(obj, number);
+ return;
+ } else if (field.FieldType == typeof(float)) {
+ var number = Convert.ToSingle (value);
+ field.SetValue(obj, number);
+ return;
+ } else if (field.FieldType == typeof(long)) {
+ var number = Convert.ToInt64 (value);
+ field.SetValue(obj, number);
+ return;
+ }
+ else if (field.FieldType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(obj, number);
+ return;
+ }
+ field.SetValue (obj, value);
+ }
+ }
+ public static void SetStaticPrivateField(string typeName, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = Type.GetType(typeName);
+ FieldInfo field = PublicExtensions.GetFieldInfo(type, name, flags);
+ if (field != null) {
+ if (field.FieldType == typeof(int)){
+ var number = Convert.ToInt32 (value);
+ field.SetValue(null, number);
+ return;
+ } else if (field.FieldType == typeof(float)) {
+ var number = Convert.ToSingle (value);
+ field.SetValue(null, number);
+ return;
+ } else if (field.FieldType == typeof(long)) {
+ var number = Convert.ToInt64 (value);
+ field.SetValue(null, number);
+ return;
+ }
+ else if (field.FieldType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(null, number);
+ return;
+ }
+ field.SetValue (null, value);
+ }
+ }
+
+ public static void SetPrivateProperty(this object obj, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ PropertyInfo field = PublicExtensions.GetPropertyInfo (type, name, flags);
+ if (field != null) {
+ if (field.PropertyType == typeof(int)){
+ var number = Convert.ToInt32 (value);
+ field.SetValue(obj, number, null);
+ return;
+ } else if (field.PropertyType == typeof(float)) {
+ var number = Convert.ToSingle (value);
+ field.SetValue(obj, number, null);
+ return;
+ } else if (field.PropertyType == typeof(long)) {
+ var number = Convert.ToInt64 (value);
+ field.SetValue(obj, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(obj, number, null);
+ return;
+ }
+ field.SetValue (obj, value, null);
+ }
+ }
+ public static void SetStaticPrivateProperty(string typeName, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic;
+ Type type = Type.GetType (typeName);
+ PropertyInfo field = PublicExtensions.GetPropertyInfo (type, name, flags);
+ if (field != null) {
+ if (field.PropertyType == typeof(int)){
+ var number = Convert.ToInt32 (value);
+ field.SetValue(null, number, null);
+ return;
+ } else if (field.PropertyType == typeof(float)) {
+ var number = Convert.ToSingle (value);
+ field.SetValue(null, number, null);
+ return;
+ } else if (field.PropertyType == typeof(long)) {
+ var number = Convert.ToInt64 (value);
+ field.SetValue(null, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(null, number, null);
+ return;
+ }
+ field.SetValue (null, value, null);
+ }
+ }
+}
+
diff --git a/Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs.meta
new file mode 100644
index 00000000..005d95b5
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/PrivateExtensions.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: af458b6600eafbf45b6dc4bdd69d568c
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs b/Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs
new file mode 100644
index 00000000..0ab00930
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs
@@ -0,0 +1,410 @@
+//
+// PublicExtensions.cs
+// Created by huailiang.peng on 2016/02/15 10:39:00
+//
+using UnityEngine;
+using System.Collections.Generic;
+using System.Reflection;
+using System;
+
+//#if NLUA
+//using LuaTable = NLua.LuaTable;
+//#else
+//using LuaTable = LuaInterface.LuaTable;
+//#endif
+
+public static class PublicExtensions
+{
+ public static List<Type[]> CastNumberParameters(object[] param, Type[] paramTypes)
+ {
+ List<Type[]> result = new List<Type[]>();
+ int doubleTypeNum = 0;
+ for (int i = 0; i < paramTypes.Length; i++)
+ {
+ if (paramTypes[i] != null && paramTypes[i] == typeof(Double))
+ {
+ doubleTypeNum++;
+ var newParameters = new Type[paramTypes.Length];
+ for (int j = 0; j < newParameters.Length; j++)
+ {
+ if (i == j)
+ newParameters[j] = typeof(double);
+ else
+ newParameters[j] = paramTypes[j];
+ }
+ result.Add(newParameters);
+
+ newParameters = new Type[paramTypes.Length];
+ for (int j = 0; j < newParameters.Length; j++)
+ {
+ if (i == j)
+ newParameters[j] = typeof(float);
+ else
+ newParameters[j] = paramTypes[j];
+ }
+ result.Add(newParameters);
+
+ newParameters = new Type[paramTypes.Length];
+ for (int j = 0; j < newParameters.Length; j++)
+ {
+ if (i == j)
+ newParameters[j] = typeof(int);
+ else
+ newParameters[j] = paramTypes[j];
+ }
+ result.Add(newParameters);
+
+ newParameters = new Type[paramTypes.Length];
+ for (int j = 0; j < newParameters.Length; j++)
+ {
+ if (i == j)
+ newParameters[j] = typeof(uint);
+ else
+ newParameters[j] = paramTypes[j];
+ }
+ result.Add(newParameters);
+ }
+ }
+ if (doubleTypeNum == 0)
+ {
+ result.Add(paramTypes);
+ if (paramTypes.Length == 1 && paramTypes[0] == typeof(string))
+ result.Add(new Type[0]);
+ }
+
+ return result;
+ }
+
+ // Invoke method
+ public static T CallPublicMethodGeneric<T>(this object obj, string name, params object[] param)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ Type[] argTypes = new Type[param.Length];
+ for (int i = 0; i < argTypes.Length; i++)
+ argTypes[i] = param[i].GetType();
+ List<Type[]> argTypeList = CastNumberParameters(param, argTypes);
+ MethodInfo method = null;
+ try
+ {
+ method = type.GetMethod(name, flags);
+ }
+ catch
+ {
+ for (int i = 0; i < argTypeList.Count; i++)
+ {
+ method = type.GetMethod(name, argTypeList[i]);
+ if (method != null)
+ break;
+ }
+ }
+ if (method == null)
+ return default(T);
+
+ ParameterInfo[] pars = method.GetParameters();
+ object[] convertedParameters = new object[pars.Length];
+ for (int i = 0; i < pars.Length; i++)
+ {
+ if (pars[i].ParameterType != typeof(object))
+ convertedParameters[i] = Convert.ChangeType(param[i], pars[i].ParameterType);
+ else
+ convertedParameters[i] = param[i];
+ }
+ return (T)method.Invoke(obj, convertedParameters);
+ }
+
+ public static object CallPublicMethod(this object obj, string name, params object[] param)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ Type[] argTypes = new Type[param.Length];
+ for (int i = 0; i < argTypes.Length; i++)
+ argTypes[i] = param[i].GetType();
+ List<Type[]> argTypeList = CastNumberParameters(param, argTypes);
+ MethodInfo method = null;
+ try
+ {
+ method = type.GetMethod(name, flags);
+ }
+ catch
+ {
+ for (int i = 0; i < argTypeList.Count; i++)
+ {
+ method = type.GetMethod(name, argTypeList[i]);
+ if (method != null)
+ break;
+ }
+ }
+ if (method == null)
+ return null;
+
+ ParameterInfo[] pars = method.GetParameters();
+ object[] convertedParameters = new object[pars.Length];
+ for (int i = 0; i < pars.Length; i++)
+ {
+ if (pars[i].ParameterType != typeof(object))
+ convertedParameters[i] = Convert.ChangeType(param[i], pars[i].ParameterType);
+ else
+ convertedParameters[i] = param[i];
+ }
+ return method.Invoke(obj, convertedParameters);
+ }
+
+ public static object CallStaticPublicMethod(string typeName, string name, params object[] param)
+ {
+ BindingFlags flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
+ Type type = Type.GetType(typeName);
+ Type[] argTypes = new Type[param.Length];
+ for (int i = 0; i < argTypes.Length; i++)
+ argTypes[i] = param[i].GetType();
+ List<Type[]> argTypeList = CastNumberParameters(param, argTypes);
+ MethodInfo method = null;
+ try
+ {
+ method = type.GetMethod(name, flags);
+ }
+ catch
+ {
+ for (int i = 0; i < argTypeList.Count; i++)
+ {
+ method = type.GetMethod(name, argTypeList[i]);
+ if (method != null)
+ break;
+ }
+ }
+ if (method == null)
+ return null;
+
+ ParameterInfo[] pars = method.GetParameters();
+ object[] convertedParameters = new object[pars.Length];
+ for (int i = 0; i < pars.Length; i++)
+ {
+ if (pars[i].ParameterType != typeof(object))
+ convertedParameters[i] = Convert.ChangeType(param[i], pars[i].ParameterType);
+ else
+ convertedParameters[i] = param[i];
+ }
+ return method.Invoke(null, convertedParameters);
+ }
+
+ // Get feild, property
+ public static T GetPublicFieldGeneric<T>(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ FieldInfo field = GetFieldInfo(type, name, flags);
+ if (field != null)
+ return (T)field.GetValue(obj);
+ else
+ return default(T);
+ }
+ public static object GetPublicField(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ FieldInfo field = GetFieldInfo(type, name, flags);
+ if (field != null)
+ return field.GetValue(obj);
+ else
+ return null;
+ }
+ public static object GetStaticPublicField(string typeName, string name)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ Type type = Type.GetType(typeName);
+ FieldInfo field = GetFieldInfo(type, name, flags);
+ if (field != null)
+ return field.GetValue(null);
+ else
+ return null;
+ }
+ public static FieldInfo GetFieldInfo(Type type, string name, BindingFlags flags)
+ {
+ if (type == null)
+ return null;
+ FieldInfo field = type.GetField(name, flags);
+ if (field == null && type.BaseType != null)
+ return GetFieldInfo(type.BaseType, name, flags);
+ return field;
+ }
+
+ public static T GetPublicPropertyGeneric<T>(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ PropertyInfo field = GetPropertyInfo(type, name, flags);
+ if (field != null)
+ return (T)field.GetGetMethod(false).Invoke(obj, null);
+ else
+ return default(T);
+ }
+ public static object GetPublicProperty(this object obj, string name)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ PropertyInfo field = GetPropertyInfo(type, name, flags);
+ if (field != null)
+ return field.GetGetMethod(false).Invoke(obj, null);
+ else
+ return null;
+ }
+ public static object GetStaticPublicProperty(string typeName, string name)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = Type.GetType(typeName);
+ PropertyInfo field = GetPropertyInfo(type, name, flags);
+ if (field != null)
+ return field.GetValue(null, null);
+ return null;
+ }
+
+ public static PropertyInfo GetPropertyInfo(Type type, string name, BindingFlags flags)
+ {
+ if (type == null)
+ return null;
+ PropertyInfo property = type.GetProperty(name, flags);
+ if (property == null && type.BaseType != null)
+ return GetPropertyInfo(type.BaseType, name, flags);
+ return property;
+ }
+
+ // Set field, propertry
+ public static void SetPublicField(this object obj, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ FieldInfo field = GetFieldInfo(type, name, flags);
+ if (field != null)
+ {
+ if (field.FieldType == typeof(int))
+ {
+ var number = Convert.ToInt32(value);
+ field.SetValue(obj, number);
+ return;
+ }
+ else if (field.FieldType == typeof(float))
+ {
+ var number = Convert.ToSingle(value);
+ field.SetValue(obj, number);
+ return;
+ }
+ else if (field.FieldType == typeof(long))
+ {
+ var number = Convert.ToInt64(value);
+ field.SetValue(obj, number);
+ return;
+ }
+ else if (field.FieldType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(obj, number);
+ return;
+ }
+ field.SetValue(obj, value);
+ }
+ }
+ public static void SetStaticPublicField(string typeName, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = Type.GetType(typeName);
+ FieldInfo field = GetFieldInfo(type, name, flags);
+ if (field != null)
+ {
+ if (field.FieldType == typeof(int))
+ {
+ var number = Convert.ToInt32(value);
+ field.SetValue(null, number);
+ return;
+ }
+ else if (field.FieldType == typeof(float))
+ {
+ var number = Convert.ToSingle(value);
+ field.SetValue(null, number);
+ return;
+ }
+ else if (field.FieldType == typeof(long))
+ {
+ var number = Convert.ToInt64(value);
+ field.SetValue(null, number);
+ return;
+ }
+ else if (field.FieldType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(null, number);
+ return;
+ }
+ field.SetValue(null, value);
+ }
+ }
+
+ public static void SetPublicProperty(this object obj, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy;
+ Type type = obj.GetType();
+ PropertyInfo field = GetPropertyInfo(type, name, flags);
+ if (field != null)
+ {
+ if (field.PropertyType == typeof(int))
+ {
+ var number = Convert.ToInt32(value);
+ field.SetValue(obj, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(float))
+ {
+ var number = Convert.ToSingle(value);
+ field.SetValue(obj, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(long))
+ {
+ var number = Convert.ToInt64(value);
+ field.SetValue(obj, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(obj, number, null);
+ return;
+ }
+ field.SetValue(obj, value, null);
+ }
+ }
+ public static void SetStaticPublicProperty(string typeName, string name, object value)
+ {
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
+ Type type = Type.GetType(typeName);
+ PropertyInfo field = GetPropertyInfo(type, name, flags);
+ if (field != null)
+ {
+ if (field.PropertyType == typeof(int))
+ {
+ var number = Convert.ToInt32(value);
+ field.SetValue(null, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(float))
+ {
+ var number = Convert.ToSingle(value);
+ field.SetValue(null, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(long))
+ {
+ var number = Convert.ToInt64(value);
+ field.SetValue(null, number, null);
+ return;
+ }
+ else if (field.PropertyType == typeof(uint))
+ {
+ var number = Convert.ToUInt32(value);
+ field.SetValue(null, number, null);
+ return;
+ }
+ field.SetValue(null, value, null);
+ }
+ }
+}
+
diff --git a/Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs.meta
new file mode 100644
index 00000000..0b503f4d
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/PublicExtensions.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: b5f857ad8fb1f634ea0dcb09ba0129f0
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/Single.cs b/Client/Assets/Scripts/LuaEngine/Core/Single.cs
new file mode 100644
index 00000000..7286d44c
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/Single.cs
@@ -0,0 +1,59 @@
+using UnityEngine;
+using System.Collections;
+
+public class Single<T> where T : new()
+{
+ private static T s_instance;
+
+ public static T Instance
+ {
+ get { return GetInstance(); }
+ }
+
+ protected Single()
+ {
+ }
+
+ public static void CreateInstance()
+ {
+ if (s_instance == null)
+ {
+ s_instance = new T();
+
+ (s_instance as Single<T>).Init();
+ }
+ }
+
+ public static void DestroyInstance()
+ {
+ if (s_instance != null)
+ {
+ (s_instance as Single<T>).UnInit();
+ s_instance = default(T);
+ }
+ }
+
+ public static T GetInstance()
+ {
+ if (s_instance == null)
+ {
+ CreateInstance();
+ }
+ return s_instance;
+ }
+
+ public static bool HasInstance()
+ {
+ return (s_instance != null);
+ }
+
+ public virtual void Init()
+ {
+ }
+
+ public virtual void UnInit()
+ {
+ }
+
+
+}
diff --git a/Client/Assets/Scripts/LuaEngine/Core/Single.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/Single.cs.meta
new file mode 100644
index 00000000..eaba63db
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/Single.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: de7aedd10e52136478ad982d1b12e8e1
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/Timer.cs b/Client/Assets/Scripts/LuaEngine/Core/Timer.cs
new file mode 100644
index 00000000..c3aec93f
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/Timer.cs
@@ -0,0 +1,142 @@
+//
+// Timer.cs
+// Created by huailiang.peng on 2016/03/14 03:19:41
+//
+
+
+namespace LuaCore
+{
+
+ public class Timer
+ {
+ //delegate
+ public delegate void OnTimeUpHandler(int timerSequence);
+ private OnTimeUpHandler m_timeUpHandler;
+
+ //循环次数( < 0 表示无限循环)
+ private int m_loop = 1;
+
+ //计时(ms)
+ private int m_totalTime;
+ private int m_currentTime;
+
+ //是否完成
+ private bool m_isFinished;
+
+ //是否处于运行状态
+ private bool m_isRunning;
+
+ //序列号
+ private int m_sequence;
+
+
+ //--------------------------------------
+ /// 构造函数
+ //--------------------------------------
+ public Timer(int time, int loop, OnTimeUpHandler timeUpHandler, int sequence)
+ {
+ if (loop == 0)
+ {
+ loop = -1;
+ }
+
+ m_totalTime = time;
+ m_loop = loop;
+ m_timeUpHandler = timeUpHandler;
+ m_sequence = sequence;
+
+ m_currentTime = 0;
+ m_isRunning = true;
+ m_isFinished = false;
+ }
+
+
+ //--------------------------------------
+ /// Update
+ /// @deltaTime
+ //--------------------------------------
+ public void Update(int deltaTime)
+ {
+ if (m_isFinished || !m_isRunning)
+ {
+ return;
+ }
+
+ if (m_loop == 0)
+ {
+ m_isFinished = true;
+ }
+ else
+ {
+ m_currentTime += deltaTime;
+
+ if (m_currentTime >= m_totalTime)
+ {
+ if (m_timeUpHandler != null)
+ {
+ m_timeUpHandler(m_sequence);
+ }
+
+ m_currentTime = 0;
+ m_loop--;
+ }
+ }
+ }
+
+ //--------------------------------------
+ /// 是否完成
+ //--------------------------------------
+ public bool IsFinished()
+ {
+ return m_isFinished;
+ }
+
+ public int CurrentTime
+ {
+ get { return m_currentTime; }
+ }
+
+ //--------------------------------------
+ /// 暂停
+ //--------------------------------------
+ public void Pause()
+ {
+ m_isRunning = false;
+ }
+
+ //--------------------------------------
+ /// 恢复
+ //--------------------------------------
+ public void Resume()
+ {
+ m_isRunning = true;
+ }
+
+ //--------------------------------------
+ /// 重置
+ //--------------------------------------
+ public void Reset()
+ {
+ m_currentTime = 0;
+ }
+
+ //--------------------------------------
+ /// 检查sequence是否匹配
+ //--------------------------------------
+ public bool IsSequenceMatched(int sequence)
+ {
+ return (m_sequence == sequence);
+ }
+
+ //--------------------------------------
+ /// 检查delegate是否匹配
+ //--------------------------------------
+ public bool IsDelegateMatched(OnTimeUpHandler timeUpHandler)
+ {
+ return (m_timeUpHandler == timeUpHandler);
+ }
+
+ }
+
+
+}
diff --git a/Client/Assets/Scripts/LuaEngine/Core/Timer.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/Timer.cs.meta
new file mode 100644
index 00000000..bac5a8aa
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/Timer.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: c4b9ae24bc1c6b24f83bd6d5aecde5fe
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs b/Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs
new file mode 100644
index 00000000..3e5f05c9
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs
@@ -0,0 +1,271 @@
+//
+// TimerManager.cs
+// Created by huailiang.peng on 2016/03/14 03:19:41
+//
+
+
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace LuaCore
+{
+
+ public class TimerManager : Single<TimerManager>
+ {
+
+ //Timer类型
+ private enum enTimerType
+ {
+ Normal,
+ FrameSync,
+ };
+
+ //Timer List
+ private List<Timer>[] m_timers;
+ private int m_timerSequence;
+
+ //----------------------------------------------
+ /// 初始化
+ //----------------------------------------------
+ public override void Init()
+ {
+ m_timers = new List<Timer>[System.Enum.GetValues(typeof(enTimerType)).Length];
+
+ for (int i = 0; i < m_timers.Length; i++)
+ {
+ m_timers[i] = new List<Timer>();
+ }
+ m_timerSequence = 0;
+ }
+
+ //----------------------------------------------
+ /// Update
+ /// @这里只更新Normal类型的Timer
+ //----------------------------------------------
+ public void Update()
+ {
+ AdvanceTimer((int)(Time.deltaTime * 1000), enTimerType.Normal);
+ }
+
+ //----------------------------------------------
+ /// UpdateLogic
+ /// @这里只更新FrameSync类型的Timer
+ //----------------------------------------------
+ public void UpdateLogic(int delta)
+ {
+ AdvanceTimer(delta, enTimerType.FrameSync);
+ }
+
+ private void AdvanceTimer(int delta, enTimerType timerType)
+ {
+ List<Timer> timers = m_timers[(int)timerType];
+
+ for (int i = 0; i < timers.Count; )
+ {
+ if (timers[i].IsFinished())
+ {
+ timers.RemoveAt(i);
+ continue;
+ }
+
+ timers[i].Update(delta);
+ i++;
+ }
+ }
+
+ //----------------------------------------------
+ /// 添加Timer
+ /// @time : 计时时间(ms)
+ /// @loop : 循环次数
+ /// @onTimeUpHandler : 时间到时的回调函数
+ /// @return sequence of timer
+ //----------------------------------------------
+ public int AddTimer(int time, int loop, Timer.OnTimeUpHandler onTimeUpHandler)
+ {
+ return AddTimer(time, loop, onTimeUpHandler, false);
+ }
+
+ //----------------------------------------------
+ /// 添加Timer
+ /// @time : 计时时间(ms)
+ /// @loop : 循环次数
+ /// @onTimeUpHandler : 时间到时的回调函数
+ /// @useFrameSync : 是否使用桢同步
+ /// @return sequence of timer
+ //----------------------------------------------
+ public int AddTimer(int time, int loop, Timer.OnTimeUpHandler onTimeUpHandler, bool useFrameSync)
+ {
+ m_timerSequence++;
+ m_timers[(int)(useFrameSync ? enTimerType.FrameSync : enTimerType.Normal)].Add(new Timer(time, loop, onTimeUpHandler, m_timerSequence));
+
+ return m_timerSequence;
+ }
+
+ //----------------------------------------------
+ /// 移除Timer
+ /// @sequence
+ //----------------------------------------------
+ public void RemoveTimer(int sequence)
+ {
+ for (int i = 0; i < m_timers.Length; i++)
+ {
+ List<Timer> timers = m_timers[i];
+
+ for (int j = 0; j < timers.Count; )
+ {
+ if (timers[j].IsSequenceMatched(sequence))
+ {
+ timers.RemoveAt(j);
+ return;
+ }
+
+ j++;
+ }
+ }
+ }
+
+ //----------------------------------------------
+ /// 移除Timer
+ /// @sequence: ref,移除后清空
+ //----------------------------------------------
+ public void RemoveTimerSafely(ref int sequence)
+ {
+ if (sequence != 0)
+ {
+ RemoveTimer(sequence);
+ sequence = 0;
+ }
+ }
+
+ //----------------------------------------------
+ /// 暂停Timer
+ /// @sequence
+ //----------------------------------------------
+ public void PauseTimer(int sequence)
+ {
+ Timer timer = GetTimer(sequence);
+
+ if (timer != null)
+ {
+ timer.Pause();
+ }
+ }
+
+ //----------------------------------------------
+ /// 恢复Timer
+ /// @sequence
+ //----------------------------------------------
+ public void ResumeTimer(int sequence)
+ {
+ Timer timer = GetTimer(sequence);
+
+ if (timer != null)
+ {
+ timer.Resume();
+ }
+ }
+
+ //----------------------------------------------
+ /// 重置Timer
+ /// @sequence
+ //----------------------------------------------
+ public void ResetTimer(int sequence)
+ {
+ Timer timer = GetTimer(sequence);
+
+ if (timer != null)
+ {
+ timer.Reset();
+ }
+ }
+
+ //----------------------------------------------
+ /// 获取Timer的当前时间
+ /// @sequence
+ //----------------------------------------------
+ public int GetTimerCurrent(int sequence)
+ {
+ Timer timer = GetTimer(sequence);
+
+ if (timer != null)
+ {
+ return timer.CurrentTime;
+ }
+
+ return -1;
+ }
+
+ //----------------------------------------------
+ /// 返回指定sequence的Timer
+ //----------------------------------------------
+ private Timer GetTimer(int sequence)
+ {
+ for (int i = 0; i < m_timers.Length; i++)
+ {
+ List<Timer> timers = m_timers[i];
+
+ for (int j = 0; j < timers.Count; j++)
+ {
+ if (timers[j].IsSequenceMatched(sequence))
+ {
+ return timers[j];
+ }
+ }
+ }
+
+ return null;
+ }
+
+ //----------------------------------------------
+ /// 移除Timer
+ /// @onTimeUpHandler
+ //----------------------------------------------
+ public void RemoveTimer(Timer.OnTimeUpHandler onTimeUpHandler)
+ {
+ RemoveTimer(onTimeUpHandler, false);
+ }
+
+ //----------------------------------------------
+ /// 移除Timer
+ /// @onTimeUpHandler
+ /// @useFrameSync
+ //----------------------------------------------
+ public void RemoveTimer(Timer.OnTimeUpHandler onTimeUpHandler, bool useFrameSync)
+ {
+ List<Timer> timers = m_timers[(int)(useFrameSync ? enTimerType.FrameSync : enTimerType.Normal)];
+
+ for (int i = 0; i < timers.Count; )
+ {
+ if (timers[i].IsDelegateMatched(onTimeUpHandler))
+ {
+ timers.RemoveAt(i);
+ continue;
+ }
+
+ i++;
+ }
+ }
+
+ //----------------------------------------------
+ /// 移除所有Timer
+ /// @timerType
+ //----------------------------------------------
+ public void RemoveAllTimer(bool useFrameSync)
+ {
+ m_timers[(int)(useFrameSync ? enTimerType.FrameSync : enTimerType.Normal)].Clear();
+ }
+
+ //----------------------------------------------
+ /// 移除所有Timer
+ //----------------------------------------------
+ public void RemoveAllTimer()
+ {
+ for (int i = 0; i < m_timers.Length; i++)
+ {
+ m_timers[i].Clear();
+ }
+ }
+
+
+ }
+}
diff --git a/Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs.meta b/Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs.meta
new file mode 100644
index 00000000..ea59365f
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Core/TimerManager.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 276aee697cb983745aae05a258ee06d3
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/Hotfix.cs b/Client/Assets/Scripts/LuaEngine/Hotfix.cs
new file mode 100644
index 00000000..57c4f267
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Hotfix.cs
@@ -0,0 +1,899 @@
+//
+// Hotfix.cs
+// Created by huailiang.peng on 2016/03/14 11:39:07
+//
+using System.Text;
+using UnityEngine;
+using System.Collections.Generic;
+using LuaCore;
+using LuaInterface;
+using System.IO;
+using System;
+using XUtliPoolLib;
+using UILib;
+
+public class Hotfix
+{
+
+ static int localversion { get { return PlayerPrefs.GetInt("hotfixversion", 0); } }
+
+ static LuaStringBuffer sharedStringBuff0 = new LuaStringBuffer();
+ static LuaStringBuffer sharedStringBuff1 = new LuaStringBuffer();
+ //static DelLuaRespond _sendLuaByteRPCCb = null;
+
+ //static DelLuaError _sendLuaByteRPCErrorCb = null;
+
+ private static void InitNet()
+ {
+ if (m_network == null || m_network.Deprecated)
+ m_network = XInterfaceMgr.singleton.GetInterface<ILuaNetwork>(XCommon.singleton.XHash("ILUANET"));
+ }
+ public static void Init(Action finish)
+ {
+ if (finish != null) finish();
+ RegistNotifyID();
+ if(m_network!=null)
+ {
+ m_network.InitLua(1024);
+ }
+ // LuaEngine.Instance.StartCoroutine(LoadHotfix(finish));
+ }
+
+ public static int LuaWait(int delay, LuaFunction cb)
+ {
+ return TimerManager.Instance.AddTimer(delay, 1, (x) => { cb.Call(x); });
+ }
+
+ public static int LuaLoop(int delay, int loop, LuaFunction cb)
+ {
+ return TimerManager.Instance.AddTimer(delay, loop, (x) => { cb.Call(x); });
+ }
+
+ public static void RemoveTimer(int seq)
+ {
+ TimerManager.Instance.RemoveTimer(seq);
+ }
+
+ private static ILuaNetwork m_network;
+ public static bool SendLuaPtc(uint _type, LuaStringBuffer _data)
+ {
+ return SendLuaBytePtc(_type, _data.buffer);
+ }
+
+ public static bool SendLuaBytePtc(uint _type, byte[] _req)
+ {
+ InitNet();
+ if (m_network == null)
+ {
+ Debug.LogError("network is null");
+ return false;
+ }
+ else
+ {
+ return m_network.LuaSendPtc(_type, _req);
+ }
+ }
+
+ public static void RegistNotifyID()
+ {
+ InitNet();
+ object[] objs = XLua.FetchRegistID();
+ if (objs != null)
+ {
+ List<uint> list = new List<uint>();
+ for (int i = 0; i < objs.Length; i += 2)
+ {
+ uint type = Convert.ToUInt32(objs[i]);
+ uint sign = Convert.ToUInt32(objs[i + 1]);
+ if (sign == 2)
+ {
+ list.Add(type);
+ }
+ else
+ {
+ bool copyBuffer = sign == 1;
+ m_network.LuaRigsterPtc(type, copyBuffer);
+ }
+ }
+
+ if (list.Count > 0) m_network.LuaRegistDispacher(list);
+ }
+ }
+
+ public static void RegistPtc(uint type, bool copyBuffer)
+ {
+ InitNet();
+ m_network.LuaRigsterPtc(type, copyBuffer);
+ }
+ public static void RegisterLuaRPC(uint _type, bool copyBuffer, LuaFunction _res, LuaFunction _err)
+ {
+ InitNet();
+ if (m_network == null)
+ {
+ Debug.LogError("network is null");
+ }
+ else
+ {
+ m_network.LuaRigsterRPC(_type, copyBuffer,
+ (bytes, length) =>
+ {
+ if (bytes == null)
+ {
+ _res.Call(null, 0);
+ }
+ else
+ {
+ _res.Call(LuaProtoBuffer(bytes, length), length);
+ }
+
+ },
+ (errcode) =>
+ {
+ _err.Call(errcode);
+ });
+ }
+ }
+
+ public static void SendLuaRPC(uint _type, LuaStringBuffer _data, LuaFunction _res, LuaFunction _err)
+ {
+ _SendLuaRPC(_type, _data, _res, _err, false);
+ }
+
+ public static void SendLuaRPCWithReq(uint _type, LuaStringBuffer _data, LuaFunction _res, LuaFunction _err)
+ {
+ _SendLuaRPC(_type, _data, _res, _err, true);
+ }
+
+ static void _SendLuaRPC(uint _type, LuaStringBuffer _data, LuaFunction _res, LuaFunction _err, bool withReq)
+ {
+ //PrintBytes(_data.buffer);
+ _SendLuaByteRPC(_type, _data.buffer, _res, _err, withReq);
+ }
+
+ public static void SendLuaByteRPC(uint _type, byte[] _req, LuaFunction _res, LuaFunction _err)
+ {
+ _SendLuaByteRPC(_type, _req, _res, _err, false);
+ }
+
+ public static void SendLuaByteRPCWithReq(uint _type, byte[] _req, LuaFunction _res, LuaFunction _err)
+ {
+ _SendLuaByteRPC(_type, _req, _res, _err, true);
+ }
+
+
+ static void _SendLuaByteRPC(uint _type, byte[] _req, LuaFunction _res, LuaFunction _err, bool withReq)
+ {
+ InitNet();
+ if (m_network == null)
+ {
+ Debug.LogError("network is null");
+ }
+ else
+ {
+ //if (_sendLuaByteRPCCb == null)
+ // _sendLuaByteRPCCb = new DelLuaRespond(_SendLuaByteRPCRespond);
+ //if (_sendLuaByteRPCErrorCb == null)
+ // _sendLuaByteRPCErrorCb = new DelLuaError(_SendLuaByteRPCError);
+ m_network.LuaSendRPC(_type, _req,
+ (bytes, length) =>
+ {
+ if (withReq)
+ _res.Call(LuaProtoBuffer(_req, length), LuaProtoBuffer1(bytes, length), length);
+ else
+ {
+ _res.Call(LuaProtoBuffer(bytes, length), length);
+ }
+ },
+ (errcode) =>
+ {
+ _err.Call(errcode);
+ });
+ }
+ }
+
+ private static IModalDlg m_modalDlg;
+ public static void LuaMessageBoxConfirm(string str, LuaFunction okDel, LuaFunction cancelDel)
+ {
+ if (m_modalDlg == null || m_modalDlg.Deprecated)
+ m_modalDlg = XInterfaceMgr.singleton.GetInterface<IModalDlg>(XCommon.singleton.XHash("IModalDlg"));
+ if (m_modalDlg == null)
+ {
+ Debug.LogError("modal dlg is null!");
+ }
+ else
+ {
+ m_modalDlg.LuaShow(str,
+ (btn) =>
+ {
+ if (okDel != null) okDel.Call();
+ return true;
+ },
+ (btn) =>
+ {
+ if (cancelDel != null) cancelDel.Call();
+ return true;
+ });
+ }
+ }
+
+ public static IUiUtility m_uiUtility;
+ public static void LuaShowSystemTip(string text)
+ {
+ if (m_uiUtility == null || m_uiUtility.Deprecated)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+
+ if (m_uiUtility == null)
+ Debug.LogError("uiUtility is null!");
+ else
+ m_uiUtility.ShowSystemTip(text);
+ }
+ public static void LuaShowSystemTipErrCode(int errCode)
+ {
+ if (m_uiUtility == null || m_uiUtility.Deprecated)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+
+ if (m_uiUtility == null)
+ Debug.LogError("uiUtility is null!");
+ else
+ m_uiUtility.ShowSystemTip(errCode);
+ }
+ public static void LuaShowItemAccess(int itemID)
+ {
+ if (m_uiUtility == null || m_uiUtility.Deprecated)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+
+ if (m_uiUtility == null)
+ Debug.LogError("uiUtility is null!");
+ else
+ m_uiUtility.ShowItemAccess(itemID);
+ }
+ public static void LuaShowItemTooltipDialog(int itemID, GameObject icon)
+ {
+ if (m_uiUtility == null || m_uiUtility.Deprecated)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+
+ if (m_uiUtility == null)
+ Debug.LogError("uiUtility is null!");
+ else
+ m_uiUtility.ShowTooltipDialog(itemID, icon);
+ }
+
+ public static void LuaShowDetailTooltipDialog(int itemID, GameObject icon)
+ {
+ if (m_uiUtility == null || m_uiUtility.Deprecated)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+
+ if (m_uiUtility == null)
+ Debug.LogError("uiUtility is null!");
+ else
+ m_uiUtility.ShowDetailTooltip(itemID, icon);
+ }
+
+ public static void LuaShowItemTooltipDialogByUID(string strUID, GameObject icon)
+ {
+ if (m_uiUtility == null || m_uiUtility.Deprecated)
+ m_uiUtility = XInterfaceMgr.singleton.GetInterface<IUiUtility>(XCommon.singleton.XHash("IUiUtility"));
+
+ if (m_uiUtility == null)
+ Debug.LogError("uiUtility is null!");
+ else
+ m_uiUtility.ShowTooltipDialogByUID(strUID, icon);
+ }
+
+ private static ILuaExtion m_luaExtion = null;
+
+ public static ILuaExtion luaExtion
+ {
+ get
+ {
+ if (null == m_luaExtion || m_luaExtion.Deprecated)
+ m_luaExtion = XInterfaceMgr.singleton.GetInterface<ILuaExtion>(XCommon.singleton.XHash("ILuaExtion"));
+ return m_luaExtion;
+ }
+ }
+
+ public static void SetPlayer(string key, string value)
+ {
+ luaExtion.SetPlayerProprerty(key, value);
+ }
+
+ public static object GetPlayer(string key)
+ {
+ return luaExtion.GetPlayeProprerty(key);
+ }
+
+ public static object CallPlayerMethod(bool isPublic, string method, params object[] args)
+ {
+ return luaExtion.CallPlayerMethod(isPublic, method, args);
+ }
+
+ public static object GetDocument(string doc)
+ {
+ return luaExtion.GetDocument(doc);
+ }
+
+ public static void SetDocumentMember(string doc, string key, object value, bool isPublic, bool isField)
+ {
+ luaExtion.SetDocumentMember(doc, key, value, isPublic, isField);
+ }
+
+ public static object GetDocumentMember(string doc, string key, bool isPublic, bool isField)
+ {
+ return luaExtion.GetDocumentMember(doc, key, isPublic, isField);
+ }
+
+ public static string GetGetDocumentLongMember(string doc, string key, bool isPublic, bool isField)
+ {
+ return GetDocumentMember(doc, key, isPublic, isField).ToString();
+ }
+ public static object GetDocumentStaticMember(string doc, string key, bool isPublic, bool isField)
+ {
+ return luaExtion.GetDocumentStaticMember(doc, key, isPublic, isField);
+ }
+
+ public static object CallDocumentMethod(string doc, bool isPublic, string method, params object[] args)
+ {
+ return luaExtion.CallDocumentMethod(doc, isPublic, method, args);
+ }
+
+ public static string CallDocumentLongMethod(string doc, bool isPublic, string method, params object[] args)
+ {
+ return luaExtion.CallDocumentMethod(doc, isPublic, method, args).ToString();
+ }
+
+ public static object CallDocumentStaticMethod(string doc, bool isPublic, string method, params object[] args)
+ {
+ return luaExtion.CallDocumentStaticMethod(doc, isPublic, method, args);
+ }
+
+ public static object GetSingle(string className)
+ {
+ return luaExtion.GetSingle(className);
+ }
+
+ public static object GetSingleMember(string className, string key, bool isPublic, bool isField, bool isStatic)
+ {
+ return luaExtion.GetSingleMember(className, key, isPublic, isField, isStatic);
+ }
+
+ public static string GetSingleLongMember(string className, string key, bool isPublic, bool isField, bool isStatic)
+ {
+ return GetSingleMember(className, key, isPublic, isField, isStatic).ToString();
+ }
+
+ public static void SetSingleMember(string className, string key, object value, bool isPublic, bool isField, bool isStatic)
+ {
+ luaExtion.SetSingleMember(className, key, value, isPublic, isField, isStatic);
+ }
+
+ public static object CallSingleMethod(string className, bool isPublic, bool isStatic, string methodName, params object[] args)
+ {
+ return luaExtion.CallSingleMethod(className, isPublic, isStatic, methodName, args);
+ }
+
+ public static string CallSingleLongMethod(string className, bool isPublic, bool isStatic, string methodName, params object[] args)
+ {
+ return luaExtion.CallSingleMethod(className, isPublic, isStatic, methodName, args).ToString();
+ }
+
+ public static object GetEnumType(string classname, string value)
+ {
+ return luaExtion.GetEnumType(classname, value);
+ }
+
+ public static string GetStringTable(string key, params object[] args)
+ {
+ return luaExtion.GetStringTable(key, args);
+ }
+
+ public static string GetGlobalString(string key)
+ {
+ return luaExtion.GetGlobalString(key);
+ }
+
+ public static string GetObjectString(object o,string name)
+ {
+ return PublicExtensions.GetPublicField(o, name).ToString();
+ }
+
+ public static string GetObjectString(object o, string name, bool isPublic, bool isField)
+ {
+ if (isPublic)
+ {
+ if (isField)
+ return o.GetPublicField(name).ToString();
+ else
+ return PublicExtensions.GetPublicProperty(o, name).ToString();
+ }
+ else
+ {
+ if (isField)
+ return o.GetPrivateField(name).ToString();
+ else
+ return PrivateExtensions.GetPrivateProperty(o, name).ToString();
+ }
+ }
+
+ public static XLuaLong GetLuaLong(string str)
+ {
+ return luaExtion.Get(str);
+ }
+
+ public static void RefreshPlayerName()
+ {
+ luaExtion.RefreshPlayerName();
+ }
+
+ private static IGameSysMgr m_GameSysMgr = null;
+ public static IGameSysMgr GameSysMgr
+ {
+ get
+ {
+ if (null == m_GameSysMgr || m_GameSysMgr.Deprecated)
+ m_GameSysMgr = XInterfaceMgr.singleton.GetInterface<IGameSysMgr>(XCommon.singleton.XHash("IGameSysMgr"));
+ return m_GameSysMgr;
+ }
+ }
+
+ public static bool OpenSys(int sys)
+ {
+ GameSysMgr.OpenSystem(sys);
+ return GameSysMgr.IsSystemOpen(sys);
+ }
+
+ public static int onlineReTime
+ {
+ get { return (int)GameSysMgr.OnlineRewardRemainTime; }
+ }
+
+ public static void AttachSysRedPointRelative(int sys, int childSys, bool bImmCalculate)
+ {
+ GameSysMgr.AttachSysRedPointRelative(sys, childSys, bImmCalculate);
+ }
+
+ public static void AttachSysRedPointRelativeUI(int sys, GameObject go)
+ {
+ GameSysMgr.AttachSysRedPointRelativeUI(sys, go);
+ }
+
+ public static void DetachSysRedPointRelative(int sys)
+ {
+ GameSysMgr.DetachSysRedPointRelative(sys);
+ }
+
+ public static void DetachSysRedPointRelativeUI(int sys)
+ {
+ GameSysMgr.DetachSysRedPointRelativeUI(sys);
+ }
+
+ public static void ForceUpdateSysRedPointImmediately(int sys, bool redpoint)
+ {
+ GameSysMgr.ForceUpdateSysRedPointImmediately(sys, redpoint);
+ }
+
+ public static bool GetSysRedPointState(int sys)
+ {
+ return GameSysMgr.GetSysRedPointState(sys);
+ }
+
+
+ public static void LuaDoFile(string name)
+ {
+ LuaScriptMgr mgr = HotfixManager.Instance.GetLuaScriptMgr();
+ if (mgr != null)
+ {
+ mgr.DoFile(name);
+ }
+ }
+
+ public static LuaFunction LuaGetFunction(string func)
+ {
+ LuaScriptMgr mgr = HotfixManager.Instance.GetLuaScriptMgr();
+ if (mgr != null) return mgr.GetLuaFunction(func);
+ else
+ {
+ Debug.LogError("LuaScriptMgr is null");
+ return null;
+ }
+ }
+
+ public static string LuaTableBuffer(string location)
+ {
+ Stream stream = XResourceLoaderMgr.singleton.ReadText(location, ".bytes");
+ StreamReader reader = new StreamReader(stream);
+ return reader.ReadToEnd();
+ }
+
+ public static System.IO.BinaryReader LuaTableBin(string location)
+ {
+ Stream stream = XResourceLoaderMgr.singleton.ReadText(location, ".bytes");
+ System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
+ //int length = reader.ReadInt32();
+ return reader;
+ }
+ public static void ReturnableStream(System.IO.BinaryReader reader)
+ {
+ dataHandler.UnInit(true);
+ XResourceLoaderMgr.singleton.ClearStream(reader.BaseStream);
+ }
+
+ static int fileSize = 0;
+ public static void ReadFileSize(System.IO.BinaryReader reader)
+ {
+ fileSize = reader.ReadInt32();
+ }
+
+ public static void CheckFileSize(System.IO.BinaryReader reader, string tableName)
+ {
+ int pos = (int)reader.BaseStream.Position;
+ if (pos != fileSize)
+ {
+ XDebug.singleton.AddErrorLog2("read table error:{0} size:{1} read size:{2}", tableName, fileSize, pos);
+ }
+ }
+
+ static int rowSize = 0;
+ static int beforePos = 0;
+ public static void ReadRowSize(System.IO.BinaryReader reader)
+ {
+ rowSize = reader.ReadInt32();
+ beforePos = (int)reader.BaseStream.Position;
+ }
+
+ public static void CheckRowSize(System.IO.BinaryReader reader, string tableName, int lineno)
+ {
+ int afterPos = (int)reader.BaseStream.Position;
+ int delta = afterPos - beforePos;
+ if (rowSize > delta)
+ {
+ reader.BaseStream.Seek(rowSize - delta, SeekOrigin.Current);
+ }
+ else if (rowSize < delta)
+ {
+ XDebug.singleton.AddErrorLog2("read table error:{0} line:{1}", tableName, lineno);
+ }
+ }
+ static DataHandler dataHandler = new DataHandler();
+ public static void ReadDataHandle(System.IO.BinaryReader reader)
+ {
+ dataHandler.Init(reader);
+ }
+
+
+
+ public static ushort startOffset;
+ public static byte count;
+ public static byte allSameMask;
+ public static void ReadSeqHead(System.IO.BinaryReader reader)
+ {
+ startOffset = reader.ReadUInt16();
+ }
+ public static int ReadSeqListHead(System.IO.BinaryReader reader)
+ {
+ count = reader.ReadByte();
+ allSameMask = 0;
+ startOffset = 0;
+ if (count > 0)
+ {
+ allSameMask = reader.ReadByte();
+ startOffset = reader.ReadUInt16();
+ }
+ return count;
+ }
+
+ public static int ReadInt(int key)
+ {
+ return dataHandler.intBuffer[startOffset+key];
+ }
+ public static int ReadInt(int index, int key)
+ {
+ int[] buffer = dataHandler.intBuffer;
+ return allSameMask == 1 ? (buffer[startOffset + key]) : buffer[dataHandler.indexBuffer[startOffset + index] + key];
+ }
+ public static uint ReadUInt(int key)
+ {
+ return dataHandler.uintBuffer[startOffset + key];
+ }
+ public static uint ReadUInt(int index, int key)
+ {
+ uint[] buffer = dataHandler.uintBuffer;
+ return allSameMask == 1 ? (buffer[startOffset + key]) : buffer[dataHandler.indexBuffer[startOffset + index] + key];
+ }
+ public static string ReadLong(System.IO.BinaryReader reader)
+ {
+ return reader.ReadInt64().ToString();
+ }
+ public static string ReadLong(int key)
+ {
+ return dataHandler.longBuffer[startOffset + key].ToString();
+ }
+
+ public static string ReadLong(int index, int key)
+ {
+ long[] buffer = dataHandler.longBuffer;
+ return allSameMask == 1 ? (buffer[startOffset + key]).ToString() : buffer[dataHandler.indexBuffer[startOffset + index] + key].ToString();
+ }
+
+ public static float ReadFloat(int key)
+ {
+ return dataHandler.floatBuffer[startOffset + key];
+ }
+ public static float ReadFloat(int index, int key)
+ {
+ float[] buffer = dataHandler.floatBuffer;
+ return allSameMask == 1 ? (buffer[startOffset + key]) : buffer[dataHandler.indexBuffer[startOffset + index] + key];
+ }
+ public static double ReadDouble(int key)
+ {
+ return dataHandler.doubleBuffer[startOffset + key];
+ }
+ public static double ReadDouble(int index, int key)
+ {
+ double[] buffer = dataHandler.doubleBuffer;
+ return allSameMask == 1 ? (buffer[startOffset + key]) : buffer[dataHandler.indexBuffer[startOffset + index] + key];
+ }
+ public static string ReadString(int key)
+ {
+ return dataHandler.stringBuffer[startOffset + key];
+ }
+ public static string ReadString(int index, int key)
+ {
+ string[] buffer = dataHandler.stringBuffer;
+ return allSameMask == 1 ? (buffer[startOffset + key]) : buffer[dataHandler.indexBuffer[startOffset + index] + key];
+ }
+ public static string ReadString(System.IO.BinaryReader reader)
+ {
+ return dataHandler.ReadString(reader);
+ }
+ //public static LuaStringBuffer LuaProtoBuffer(byte[] bytes)
+ //{
+ // sharedStringBuff0.Set(bytes);
+ // return sharedStringBuff0;;
+ // //return new LuaStringBuffer(bytes);
+ //}
+
+ public static LuaStringBuffer LuaProtoBuffer(byte[] bytes,int length)
+ {
+ sharedStringBuff0.Copy(bytes, length);
+ return sharedStringBuff0; ;
+ //return new LuaStringBuffer(bytes);
+ }
+ //public static LuaStringBuffer LuaProtoBuffer1(byte[] bytes)
+ //{
+ // sharedStringBuff1.Set(bytes);
+ // return sharedStringBuff1;// new LuaStringBuffer(bytes);
+ //}
+ public static LuaStringBuffer LuaProtoBuffer1(byte[] bytes, int length)
+ {
+ sharedStringBuff1.Copy(bytes, length);
+ return sharedStringBuff1;// new LuaStringBuffer(bytes);
+ }
+
+ public static void SetClickCallback(GameObject go, LuaFunction cb)
+ {
+ UIEventListener.Get(go).onClick = (g) => { cb.Call(go); };
+ }
+
+ public static void SetPressCallback(GameObject go,LuaFunction cb)
+ {
+ UIEventListener.Get(go).onPress = (g, press) => { cb.Call(g, press); };
+ }
+
+ public static void SetDragCallback(GameObject go, LuaFunction cb)
+ {
+ UIEventListener.Get(go).onDrag = (g, delta) => { cb.Call(g,delta.x,delta.y); };
+ }
+
+ public static void SetSubmmitCallback(GameObject go,LuaFunction cb)
+ {
+ UIEventListener.Get(go).onSubmit = (g) => { cb.Call(g); };
+ }
+
+
+ public static void InitWrapContent(GameObject goWrapContent, LuaFunction cb)
+ {
+ IXUIWrapContent _wrapContent = goWrapContent.GetComponent("XUIWrapContent") as IXUIWrapContent;
+ _wrapContent.RegisterItemUpdateEventHandler((t, index) => { cb.Call(t, index); });
+ }
+
+ public static void SetWrapContentCount(GameObject goWrapContent, int wrapCount, bool bResetPosition)
+ {
+ IXUIWrapContent _wrapContent = goWrapContent.GetComponent("XUIWrapContent") as IXUIWrapContent;
+ _wrapContent.SetContentCount(wrapCount);
+
+ if (bResetPosition)
+ {
+ IXUIScrollView _scrollView = goWrapContent.transform.parent.GetComponent("XUIScrollView") as IXUIScrollView;
+ _scrollView.ResetPosition();
+ }
+ }
+
+ public static XUIPool SetupPool(GameObject parent, GameObject tpl, uint Count)
+ {
+ XUIPool pool = new XUIPool(null);
+ pool.SetupPool(parent, tpl, Count, false);
+ return pool;
+ }
+
+ private static IXNormalItemDrawer m_itemDrawer;
+ public static void DrawItemView(GameObject goItemView, int itemID, int count, bool showCount)
+ {
+ if (m_itemDrawer == null || m_itemDrawer.Deprecated)
+ m_itemDrawer = XInterfaceMgr.singleton.GetInterface<IXNormalItemDrawer>(XCommon.singleton.XHash("IXNormalItemDrawer"));
+
+ if (m_itemDrawer == null)
+ Debug.LogError("IXNormalItemDrawer is null");
+ else
+ m_itemDrawer.DrawItem(goItemView, itemID, count, showCount);
+ }
+
+ public static void SetTexture(UITexture text, string localtion, bool makepiexl)
+ {
+ text.SetTexture(localtion);
+ //text.mainTexture = XResourceLoaderMgr.singleton.GetSharedResource<Texture>(localtion, ".png");
+ if (makepiexl) text.MakePixelPerfect();
+ }
+
+ public static void DestoryTexture(UITexture uitex, string location)
+ {
+ if (uitex != null)
+ {
+ uitex.SetTexture("");
+ //Texture tex = uitex.mainTexture;
+ //if (tex != null)
+ //{
+ // uitex.mainTexture = null;
+ // //XResourceLoaderMgr.singleton.DestroyShareResource(location, tex);
+ //}
+ }
+ }
+
+ private static IX3DAvatarMgr m_avatarMgr;
+ public static void EnableMainDummy(bool enable, UIDummy snapShot)
+ {
+ if (m_avatarMgr == null || m_avatarMgr.Deprecated)
+ m_avatarMgr = XInterfaceMgr.singleton.GetInterface<IX3DAvatarMgr>(XCommon.singleton.XHash("IX3DAvatarMgr"));
+ m_avatarMgr.EnableMainDummy(enable, snapShot);
+ }
+
+ public static void SetMainDummy(bool ui)
+ {
+ if (m_avatarMgr == null || m_avatarMgr.Deprecated)
+ m_avatarMgr = XInterfaceMgr.singleton.GetInterface<IX3DAvatarMgr>(XCommon.singleton.XHash("IX3DAvatarMgr"));
+ m_avatarMgr.SetMainDummy(ui);
+ }
+
+ public static void ResetMainAnimation()
+ {
+ if (m_avatarMgr == null || m_avatarMgr.Deprecated)
+ m_avatarMgr = XInterfaceMgr.singleton.GetInterface<IX3DAvatarMgr>(XCommon.singleton.XHash("IX3DAvatarMgr"));
+ m_avatarMgr.ResetMainAnimation();
+ }
+
+
+ public static string CreateCommonDummy(int dummyPool, uint presentID, IUIDummy snapShot, float scale)
+ {
+ if (m_avatarMgr == null || m_avatarMgr.Deprecated)
+ m_avatarMgr = XInterfaceMgr.singleton.GetInterface<IX3DAvatarMgr>(XCommon.singleton.XHash("IX3DAvatarMgr"));
+ return m_avatarMgr.CreateCommonDummy(dummyPool,presentID, snapShot, null, scale);
+ }
+
+
+ public void SetDummyAnim(int dummyPool, string idStr, string anim)
+ {
+ if (m_avatarMgr == null || m_avatarMgr.Deprecated)
+ m_avatarMgr = XInterfaceMgr.singleton.GetInterface<IX3DAvatarMgr>(XCommon.singleton.XHash("IX3DAvatarMgr"));
+ m_avatarMgr.SetDummyAnim(dummyPool, idStr, anim);
+ }
+
+ public void SetMainDummyAnim(string anim)
+ {
+ if (m_avatarMgr == null || m_avatarMgr.Deprecated)
+ m_avatarMgr = XInterfaceMgr.singleton.GetInterface<IX3DAvatarMgr>(XCommon.singleton.XHash("IX3DAvatarMgr"));
+ m_avatarMgr.SetMainDummyAnim(anim);
+ }
+
+ public static void DestroyDummy(int dummyPool, string idStr)
+ {
+ if (m_avatarMgr == null || m_avatarMgr.Deprecated)
+ m_avatarMgr = XInterfaceMgr.singleton.GetInterface<IX3DAvatarMgr>(XCommon.singleton.XHash("IX3DAvatarMgr"));
+ m_avatarMgr.DestroyDummy(dummyPool, idStr);
+ }
+
+ public static int ParseIntSeqList(object obj, int index, int key)
+ {
+ ISeqListRef<int> var = (ISeqListRef<int>)obj;
+ return var[index, key];
+ }
+
+ public static uint ParseUIntSeqList(object obj, int index, int key)
+ {
+ ISeqListRef<uint> var = (ISeqListRef<uint>)obj;
+ return var[index, key];
+ }
+
+ public static float ParseFloatSeqList(object obj, int index, int key)
+ {
+ ISeqListRef<float> var = (ISeqListRef<float>)obj;
+ return var[index, key];
+ }
+ public static double ParseDoubleSeqList(object obj, int index, int key)
+ {
+ ISeqListRef<double> var = (ISeqListRef<double>)obj;
+ return var[index, key];
+ }
+ public static string ParseStringSeqList(object obj, int index, int key)
+ {
+ ISeqListRef<string> var = (ISeqListRef<string>)obj;
+ return var[index, key];
+ }
+
+ public static ulong TransInt64(string a)
+ {
+ ulong _a = 0;
+ ulong.TryParse(a, out _a);
+ return _a;
+ }
+
+
+ public static string TansString(ulong o)
+ {
+ return o.ToString();
+ }
+
+ public static string OpInit64(string a, string b, int op)
+ {
+ ulong _a = 0;
+ ulong _b = 0;
+ ulong.TryParse(a, out _a);
+ ulong.TryParse(b, out _b);
+ ulong result = 0;
+ switch (op)
+ {
+ case 0: result = _a + _b; break;
+ case 1: result = _a - _b; break;
+ case 2: result = _a * _b; break;
+ case 3: result = _a / _b; break;
+ case 4: result = _a % _b; break;
+ }
+ return result.ToString();
+ }
+
+ public static void PrintBytes(byte[] bytes)
+ {
+ PrintBytes("LUA", bytes);
+ }
+ public static void PrintBytes(string tag, byte[] bytes,int length)
+ {
+#if LuaDebug
+ StringBuilder sb = new StringBuilder(tag.ToUpper());
+ sb.Append(" length:");
+ sb.Append(bytes.Length.ToString());
+ sb.Append(" =>");
+ for (int i = 0; i < bytes.Length&&i<length; i++)
+ {
+ sb.Append(bytes[i]);
+ sb.Append(" ");
+ }
+ Debug.Log(sb.ToString());
+#endif
+ }
+ public static void PrintBytes(string tag, byte[] bytes)
+ {
+#if LuaDebug
+ StringBuilder sb = new StringBuilder(tag.ToUpper());
+ sb.Append(" length:");
+ sb.Append(bytes.Length.ToString());
+ sb.Append(" =>");
+ for (int i = 0; i < bytes.Length; i++)
+ {
+ sb.Append(bytes[i]);
+ sb.Append(" ");
+ }
+ Debug.Log(sb.ToString());
+#endif
+ }
+
+
+
+}
diff --git a/Client/Assets/Scripts/LuaEngine/Hotfix.cs.meta b/Client/Assets/Scripts/LuaEngine/Hotfix.cs.meta
new file mode 100644
index 00000000..3572cb2c
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/Hotfix.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: c95bcf20e315b7e41a9df83643d15abb
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/HotfixManager.cs b/Client/Assets/Scripts/LuaEngine/HotfixManager.cs
new file mode 100644
index 00000000..62cf83be
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/HotfixManager.cs
@@ -0,0 +1,454 @@
+//
+// HotfixManager.cs
+// Created by huailiang.peng on 2016-3-11 17:0:4
+//
+using UnityEngine;
+using System.Collections.Generic;
+using LuaInterface;
+using XUtliPoolLib;
+
+
+public class HotfixManager : IHotfixManager
+{
+ LuaScriptMgr hotfixLua = null;
+ LuaFunction func_refresh = null;
+ LuaFunction func_click_b = null;
+ LuaFunction func_click_a = null;
+
+ LuaFunction func_enterscene = null;
+ LuaFunction func_leavescene = null;
+ LuaFunction func_enterfinally = null;
+ LuaFunction func_attach = null;
+ LuaFunction func_detach = null;
+ LuaFunction func_reconnect = null;
+ LuaFunction func_pause = null;
+ LuaFunction func_fade = null;
+ LuaFunction func_pandora = null;
+ LuaFunction func_pay = null;
+
+
+ public const string CLICK_LUA_FILE = "HotfixClick.lua";
+ public const string DOC_LUA_FILE = "HotfixDocument.lua";
+ public const string MSG_LUE_FILE = "HotfixMsglist.lua";
+
+ public string[] befRpath, aftPath, breakPath;
+
+ public bool useHotfix = true;
+
+ private bool init = false;
+
+ private List<string> doluafiles = new List<string>();
+
+ public Dictionary<string, string> hotmsglist = new Dictionary<string, string>();
+
+ private static HotfixManager _single;
+ public static HotfixManager Instance
+ {
+ get
+ {
+ if (_single == null) _single = new HotfixManager();
+ return _single;
+ }
+ }
+
+
+
+ /// <summary>
+ /// init load click and refresh type of hot fix files
+ /// </summary>
+ public void LoadHotfix(System.Action finish)
+ {
+ init = true;
+ hotfixLua = new LuaScriptMgr();
+ hotfixLua.Start();
+ Hotfix.Init(() =>
+ {
+ TryFixMsglist();
+ InitClick();
+ InitDocument();
+ HotfixPatch.Init(hotfixLua);
+ OnAttachToHost();
+ if (finish != null) finish();
+ });
+ }
+
+
+ public void Dispose()
+ {
+ doluafiles.Clear();
+ DisposeFunc(func_click_a);
+ DisposeFunc(func_click_b);
+ DisposeFunc(func_attach);
+ DisposeFunc(func_detach);
+ DisposeFunc(func_leavescene);
+ DisposeFunc(func_enterfinally);
+ DisposeFunc(func_enterscene);
+ DisposeFunc(func_reconnect);
+ DisposeFunc(func_pause);
+ DisposeFunc(func_fade);
+ DisposeFunc(func_pandora);
+ DisposeFunc(func_pay);
+ if (init)
+ {
+ hotfixLua.Destroy();
+ hotfixLua = null;
+ init = false;
+ }
+ }
+
+
+ private void DisposeFunc(LuaFunction func)
+ {
+ if (func != null)
+ {
+ func.Dispose();
+ func = null;
+ }
+ }
+
+
+ public bool DoLuaFile(string name)
+ {
+ if (doluafiles.Contains(name) || !init) return true;
+ else
+ {
+ string path = name;
+ if (hotfixLua != null)
+ {
+ if (LuaStatic.Load(path) == null) return false;
+ hotfixLua.lua.DoFile(path);
+ doluafiles.Add(name);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Used for localization
+ /// </summary>
+ public void TryFixMsglist()
+ {
+ if (!useHotfix || !init) return;
+ string path = MSG_LUE_FILE;
+ byte[] objs = LuaStatic.Load(path);
+ if (objs != null)
+ {
+ ByteReader reader = new ByteReader(objs);
+ hotmsglist = reader.ReadDictionary();
+ }
+ }
+
+ private void InitClick()
+ {
+ if (!useHotfix || !init) return;
+ bool dofile = DoLuaFile(CLICK_LUA_FILE);
+ if (dofile)
+ {
+ if (func_click_b == null)
+ {
+ func_click_b = hotfixLua.lua.GetFunction("HotfixClick.BeforeClick");
+ }
+ if (func_click_a == null)
+ {
+ func_click_a = hotfixLua.lua.GetFunction("HotfixClick.AfterClick");
+ }
+ LuaFunction func_regist = hotfixLua.lua.GetFunction("HotfixClick.FetchRegists");
+ if (func_regist != null)
+ {
+ object[] o = func_regist.Call();
+ int k = -1, v = -1;
+ for (int i = 0; i < o.Length; i++)
+ {
+ if (o[i].Equals("|"))
+ {
+ if (k == -1) k = i;
+ else { v = i; break; }
+ }
+ }
+ befRpath = new string[k];
+ for (int i = 0; i < k; i++)
+ {
+ befRpath[i] = o[i] as string;
+ }
+ int max = Mathf.Max(v - k - 1, 0);
+ aftPath = new string[max];
+ for (int i = 0; i < max; i++)
+ {
+ aftPath[i] = o[i + k + 1] as string;
+ }
+ max = Mathf.Max(0, o.Length - v - 1);
+ breakPath = new string[max];
+ for (int i = 0; i < max; i++)
+ {
+ breakPath[i] = o[i + v + 1] as string;
+ }
+ }
+ func_regist.Dispose();
+ }
+ }
+
+ /// <summary>
+ /// Used for All Click Event
+ /// if lua return false, go on execute c#, else interupt
+ /// </summary>
+ public bool TryFixClick(HotfixMode _mode, string _path)
+ {
+ if (!useHotfix || !init) return false;
+ if (_mode == HotfixMode.BEFORE)
+ {
+ for (int i = 0; i < breakPath.Length; i++)
+ {
+ if (breakPath[i].Equals(_path))
+ {
+ func_click_b.Call(_path, true);
+ return true;
+ }
+ }
+
+ for (int i = 0; i < befRpath.Length; i++)
+ {
+ if (befRpath[i].Equals(_path))
+ {
+ func_click_b.Call(_path, false);
+ return false;
+ }
+ }
+ }
+ else
+ {
+ for (int i = 0; i < aftPath.Length; i++)
+ {
+ if (aftPath[i].Equals(_path))
+ {
+ func_click_a.Call(_path);
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+
+
+ /// <summary>
+ /// Used for GamePage Refresh Hide Unload
+ /// if lua return false, go on execute c#, else interupt
+ /// </summary>
+ public bool TryFixRefresh(HotfixMode _mode, string _pageName, GameObject go)
+ {
+ if (_pageName == "LoadingDlg" || _pageName == "LoginDlg" || _pageName == "LoginTip") return false;
+ if (useHotfix && init)
+ {
+ string filename = "Hotfix" + _pageName + ".lua";
+ bool dolua = DoLuaFile(filename);
+ if (dolua)
+ {
+ func_refresh = null;
+ if (_mode == HotfixMode.BEFORE) func_refresh = hotfixLua.lua.GetFunction(_pageName + ".BeforeRefresh");// : _pageName + ".AfterRefresh");
+ else if (_mode == HotfixMode.AFTER) func_refresh = hotfixLua.lua.GetFunction(_pageName + ".AfterRefresh");
+ else if (_mode == HotfixMode.HIDE) func_refresh = hotfixLua.lua.GetFunction(_pageName + ".Hide");
+ else if (_mode == HotfixMode.UNLOAD) func_refresh = hotfixLua.lua.GetFunction(_pageName + ".Unload");
+ if (func_refresh != null)
+ {
+ object[] r = func_refresh.Call(go);
+ func_refresh.Release();
+ return r != null && r.Length > 0 ? (bool)r[0] : false;
+ }
+ else
+ {
+ XDebug.singleton.AddLog("func is null!" + _pageName + " mode: " + _mode);
+ }
+ }
+ }
+ return false;
+ }
+
+ public bool TryFixHandler(HotfixMode _mode, string _handlerName, GameObject go)
+ {
+ if (useHotfix && init)
+ {
+ string filename = "Hotfix" + _handlerName + ".lua";
+ bool dolua = DoLuaFile(filename);
+ if (dolua)
+ {
+ func_refresh = null;
+ if (_mode == HotfixMode.BEFORE) func_refresh = hotfixLua.lua.GetFunction(_handlerName + ".BeforeHandlerShow");// : _pageName + ".AfterRefresh");
+ else if (_mode == HotfixMode.AFTER) func_refresh = hotfixLua.lua.GetFunction(_handlerName + ".AfterHandlerShow");
+ else if (_mode == HotfixMode.HIDE) func_refresh = hotfixLua.lua.GetFunction(_handlerName + ".Hide");
+ else if (_mode == HotfixMode.UNLOAD) func_refresh = hotfixLua.lua.GetFunction(_handlerName + ".Unload");
+ // func_refresh = hotfixLua.lua.GetFunction(_mode == HotfixMode.BEFORE ? _handlerName + ".BeforeHandlerShow" : _handlerName + ".AfterHandlerShow");
+ if (func_refresh != null)
+ {
+ object[] r = func_refresh.Call(go);
+ func_refresh.Release();
+ return r != null && r.Length > 0 ? (bool)r[0] : false;
+ }
+ else
+ {
+ XDebug.singleton.AddGreenLog("func is null! " + _handlerName);
+ }
+ }
+ }
+ return false;
+ }
+
+ public void CallLuaFunc(string className, string funcName)
+ {
+ LuaFunction func = null;
+ func = hotfixLua.lua.GetFunction(XCommon.singleton.StringCombine(className, ".", funcName));
+ if(func != null)
+ {
+ func.Call();
+ func.Release();
+ }
+ }
+
+ public void RegistedPtc(uint _type, byte[] body, int length)
+ {
+ XLua.NotifyRoute(_type, body, length);
+ }
+
+
+ public void ProcessOveride(uint _type, byte[] body, int length)
+ {
+ XLua.OverideNet(_type, body, length);
+ }
+
+ public LuaScriptMgr GetLuaScriptMgr()
+ {
+ return hotfixLua;
+ }
+
+ private void InitDocument()
+ {
+ if (!useHotfix || !init) return;
+ bool dofile = DoLuaFile(DOC_LUA_FILE);
+ if (dofile)
+ {
+ if(func_leavescene == null)
+ {
+ func_leavescene = hotfixLua.lua.GetFunction("HotfixDocument.LeaveScene");
+ }
+ if (func_enterscene == null)
+ {
+ func_enterscene = hotfixLua.lua.GetFunction("HotfixDocument.EnterScene");
+ }
+ if (func_enterfinally == null)
+ {
+ func_enterfinally = hotfixLua.lua.GetFunction("HotfixDocument.EnterSceneFinally");
+ }
+ if (func_attach == null)
+ {
+ func_attach = hotfixLua.lua.GetFunction("HotfixDocument.Attach");
+ }
+ if (func_detach == null)
+ {
+ func_detach = hotfixLua.lua.GetFunction("HotfixDocument.Detach");
+ }
+ if (func_reconnect == null)
+ {
+ func_reconnect = hotfixLua.lua.GetFunction("HotfixDocument.Reconnect");
+ }
+ if (func_pause == null)
+ {
+ func_pause = hotfixLua.lua.GetFunction("HotfixDocument.Pause");
+ }
+ if (func_fade == null)
+ {
+ func_fade = hotfixLua.lua.GetFunction("HotfixDocument.FadeShow");
+ }
+ if(func_pandora == null)
+ {
+ func_pandora = hotfixLua.lua.GetFunction("HotfixDocument.PandoraCallback");
+ }
+ if(func_pay == null)
+ {
+ func_pay = hotfixLua.lua.GetFunction("HotfixDocument.PayCallback");
+ }
+ }
+ }
+
+ public void OnLeaveScene()
+ {
+ if(func_leavescene != null)
+ {
+ func_leavescene.Call();
+ }
+ }
+
+ public void OnEnterScene()
+ {
+ if (func_enterscene != null)
+ {
+ func_enterscene.Call();
+ }
+ }
+
+ public void OnEnterSceneFinally()
+ {
+ if (func_enterfinally != null)
+ {
+ func_enterfinally.Call();
+ }
+ }
+
+
+ public void OnAttachToHost()
+ {
+ if (func_attach != null)
+ {
+ func_attach.Call();
+ }
+ }
+
+ public void OnPandoraCallback(string json)
+ {
+ if(func_pandora != null)
+ {
+ Debug.Log("json=>"+json);
+ func_pandora.Call(json);
+ }
+ }
+
+ public void OnPayCallback(string result, string paramID)
+ {
+ if(func_pay != null)
+ {
+ func_pay.Call(result, paramID);
+ }
+ }
+
+ public void OnReconnect()
+ {
+ if (func_reconnect != null)
+ {
+ func_reconnect.Call();
+ }
+ }
+
+ public void OnDetachFromHost()
+ {
+ if (func_detach != null)
+ {
+ func_detach.Call();
+ }
+ }
+
+ public void FadeShow(bool show)
+ {
+ if (func_fade != null)
+ {
+ func_fade.Call(show);
+ }
+ }
+
+ public void OnPause(bool pause)
+ {
+ if (func_pause != null)
+ {
+ func_pause.Call(pause);
+ }
+ }
+
+}
diff --git a/Client/Assets/Scripts/LuaEngine/HotfixManager.cs.meta b/Client/Assets/Scripts/LuaEngine/HotfixManager.cs.meta
new file mode 100644
index 00000000..f9e04c0a
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/HotfixManager.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: fb40312f5dddb534fa3ce3829d1ee092
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs b/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs
new file mode 100644
index 00000000..af06701a
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs
@@ -0,0 +1,75 @@
+using UnityEngine;
+using System.Collections.Generic;
+using LuaInterface;
+
+public class HotfixPatch
+{
+ static List<string> list = new List<string>();
+ static LuaFunction lua_dispacher_func;
+ const string LUA_FILE = "HotfixPatch.lua";
+
+ public static void Init(LuaScriptMgr luamgr)
+ {
+ luamgr.lua.DoFile(LUA_FILE);
+ var func = luamgr.lua.GetFunction("Fetch");
+ object[] ret = func.Call();
+ Debug.Log("lua regist func cnt:" + (ret.Length));
+ list.Clear();
+ for (int i = 0, cnt = ret.Length; i < cnt; i++)
+ {
+ list.Add((string)ret[i]);
+ }
+ lua_dispacher_func = luamgr.lua.GetFunction("Dispacher");
+ }
+
+
+ /// <summary>
+ /// 方法由IL层-注入代码调用
+ /// </summary>
+ public static bool IsRegist(string class_name, string func_name)
+ {
+ string key = class_name + "|" + func_name;
+ return list.Contains(key);
+ }
+
+ /// <summary>
+ /// 方法由IL层-注入代码调用
+ /// </summary>
+ public static object Execute(string class_name, string func_name, string type, object[] args)
+ {
+ if (lua_dispacher_func != null)
+ {
+ Debug.Log("inject arg len: " + args.Length);
+ object val = lua_dispacher_func.Call(class_name, func_name, args)[0];
+ if (val != null && typeof(System.Double) == val.GetType()) //先转换成double,再拆箱
+ {
+ switch (type)
+ {
+ case "int":
+ case "Int32":
+ return (int)(double)val;
+ case "uint":
+ case "UInt32":
+ return (uint)(double)val;
+ case "float":
+ case "Single":
+ return (float)(double)val;
+ case "short":
+ case "Int16":
+ return (short)(double)val;
+ case "UInt64":
+ case "ulong":
+ return (ulong)(double)val;
+ }
+ return val;
+ }
+ else
+ {
+ return val;
+ }
+ }
+ return null;
+ }
+
+
+} \ No newline at end of file
diff --git a/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs.meta b/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs.meta
new file mode 100644
index 00000000..5699f5a8
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 93f56124b195bf143ab6bb6496c340cc
+timeCreated: 1508139279
+licenseType: Pro
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Client/Assets/Scripts/LuaEngine/LuaEngine.cs b/Client/Assets/Scripts/LuaEngine/LuaEngine.cs
new file mode 100644
index 00000000..0de305ea
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/LuaEngine.cs
@@ -0,0 +1,130 @@
+//
+// LuaEngine.cs
+// Created by huailiang.peng on 2016/04/14 11:39:07
+//
+
+using UnityEngine;
+using System.Collections;
+using LuaCore;
+using System.IO;
+using LuaInterface;
+using XUtliPoolLib;
+
+
+public class LuaEngine : MonoBehaviour, ILuaEngine
+{
+
+ public static LuaEngine Instance = null;
+
+ void Awake()
+ {
+ Instance = this;
+ }
+
+
+ void OnDestroy()
+ {
+ HotfixManager.Instance.Dispose();
+ Instance = null;
+ }
+
+
+
+ bool gui = false;
+ //string cname = "LuaEngine";
+ string origin_text = "des";
+ string des_text = "code";
+ int y = 200;
+
+#if UNITY_EDITOR
+ void OnGUI()
+ {
+
+ if (gui)
+ {
+ GUI.color = Color.red;
+ y = 200;
+ GUI.Label(new Rect(20, y, 700, 30), "HOTFIX TOOL");
+ GUI.color = Color.white;
+
+ GUI.color = Color.green;
+ y += 40;
+ GUI.Label(new Rect(20, y, 100, 30), "Click Btn Path:");
+ y += 30;
+ GUI.TextArea(new Rect(20, y, 700, 20), UICamera.clickpath);
+
+ y += 30;
+ GUI.Label(new Rect(20, y, 280, 30), "Test DES Encryption");
+ y += 30;
+ origin_text = GUI.TextField(new Rect(20, y, 180, 20), origin_text);
+ if (GUI.Button(new Rect(220, y, 80, 24), "Encrypt"))
+ {
+ des_text = Encryption.Encrypt(origin_text);
+ Debug.Log(des_text);
+ }
+ if (GUI.Button(new Rect(320, y, 80, 24), "Decrypt"))
+ {
+ Debug.Log(Encryption.Decrypt(des_text));
+ }
+ }
+ }
+#endif
+ private bool init = false;
+
+ public void InitLua()
+ {
+ init = true;
+ TimerManager.Instance.Init();
+ HotfixManager.Instance.LoadHotfix(OnInitFinish);
+ }
+
+
+ void Update()
+ {
+ if (init)
+ {
+ TimerManager.Instance.Update();
+ }
+#if UNITY_EDITOR
+ if (Input.GetKeyUp(KeyCode.F5))
+ {
+ //gui = !gui;
+ }
+#endif
+ }
+
+ void OnApplicationPause(bool pause)
+ {
+ HotfixManager.Instance.OnPause(pause);
+ }
+
+ private void OnInitFinish()
+ {
+ Debug.Log("Hotfix init finish!");
+ }
+
+
+ public IHotfixManager hotfixMgr
+ {
+ get
+ {
+ return HotfixManager.Instance as IHotfixManager;
+ }
+ }
+
+ public ILuaUIManager luaUIManager
+ {
+ get
+ {
+ return LuaUIManager.Instance as ILuaUIManager;
+ }
+ }
+
+ public ILuaGameInfo luaGameInfo
+ {
+ get
+ {
+ return LuaGameInfo.single as ILuaGameInfo;
+ }
+ }
+}
diff --git a/Client/Assets/Scripts/LuaEngine/LuaEngine.cs.meta b/Client/Assets/Scripts/LuaEngine/LuaEngine.cs.meta
new file mode 100644
index 00000000..b7964a34
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/LuaEngine.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: bf417024f2081594abec09d06d918d0f
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
diff --git a/Client/Assets/Scripts/LuaEngine/XLua.cs b/Client/Assets/Scripts/LuaEngine/XLua.cs
new file mode 100644
index 00000000..59e33224
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/XLua.cs
@@ -0,0 +1,51 @@
+using UnityEngine;
+using System.Collections.Generic;
+using LuaInterface;
+using System;
+
+public class XLua
+{
+
+
+
+
+ /// <summary>
+ /// ptc 处理
+ /// </summary>
+ /// <returns></returns>
+ public static void NotifyRoute(uint _type, byte[] bytes, int length)
+ {
+ LuaScriptMgr mgr = HotfixManager.Instance.GetLuaScriptMgr();
+ mgr.DoFile("LuaNotifyProcess.lua");
+ LuaFunction func = mgr.GetLuaFunction("LuaNotifyProcess.Process");
+ func.Call(_type, Hotfix.LuaProtoBuffer(bytes, length), length);
+ }
+
+
+
+ /// <summary>
+ /// 重载 c#协议
+ /// </summary>
+ public static void OverideNet(uint _type,byte[] bytes,int length)
+ {
+ LuaScriptMgr mgr = HotfixManager.Instance.GetLuaScriptMgr();
+ mgr.DoFile("LuaNotifyProcess.lua");
+ LuaFunction func = mgr.GetLuaFunction("LuaNotifyProcess.ProcessOveride");
+ func.Call(_type, Hotfix.LuaProtoBuffer(bytes, length), length);
+ }
+
+
+ /// <summary>
+ /// 抓取lua初始化的协议
+ /// </summary>
+ /// <returns></returns>
+ public static object[] FetchRegistID()
+ {
+ LuaScriptMgr mgr = HotfixManager.Instance.GetLuaScriptMgr();
+ mgr.DoFile("LuaNotifyProcess.lua");
+ LuaFunction func = mgr.GetLuaFunction("LuaNotifyProcess.FetchRegistedID");
+ return func.Call();
+ }
+
+
+}
diff --git a/Client/Assets/Scripts/LuaEngine/XLua.cs.meta b/Client/Assets/Scripts/LuaEngine/XLua.cs.meta
new file mode 100644
index 00000000..daef9a4f
--- /dev/null
+++ b/Client/Assets/Scripts/LuaEngine/XLua.cs.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 3dc0e778e3a058e4b85ff7ee5b85cdb6
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData: