summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/LuaEngine/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assets/Scripts/LuaEngine/Core')
-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
20 files changed, 1828 insertions, 0 deletions
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: