/**************************************************
* 创建人 :XingHua
* 创建时间 :2016-1-31
* 模块名字 :LuaBasePanel
* 基本功能 :luaPanel
* 注意 : 1.继承BasePanel,只是封装一层对lua脚本的引用
* 2.要在CustomSetting注册到lua的类型列表_GT(typeof(LuaBasePanel))
* 3.一般使用 new LuaBasePanel("LoginResgisterPanel");
* 4.也可以新开个脚本继承LuaBasePanel,这种情况在于模块需要交互的情况,需要在CustomSetting注册这个新开的脚本
* 同时要注意:先clearWrap,再生产Wrap+Bind
* 5.以后丰富暂时提供简单方法
* 6.注意这次的热跟新只支持UI的热更新(不支持模块,场景新添加)但是支持module下面子类的添加就是View
* 7.注意之前一直在require("LoginChildPanel_lua") 这里找不到模块,看log,LoginChildPanel_lua.lua但是我已经
* 将文件转成txt,再打包assetBundle 加载DoString 不需要再require
************************************************/
using UnityEngine;
using System.Collections;
using LuaInterface;
public class LuaBasePanel : BasePanel {
protected override string _resPath { get { return ""; } } //在luaPanel里面不使用,使用_luaScript代替底层
protected LuaState _luaState; //luaState
protected LuaFunction _func = null; //调用方法
protected string _luaScript; //脚本名称
/// <summary>
/// 构造函数
/// </summary>
/// <param name="luaScript"></param>
public LuaBasePanel(string luaScript)
: base(luaScript)
{
_luaState = new LuaState ();
_luaState.Start ();
LuaBinder.Bind (_luaState);
_luaScript = luaScript + "_lua";
//string fullPath = Application.dataPath + "/Lua"; //暂时全部放到lua文件夹下面
//_luaState.AddSearchPath(fullPath);
//_luaState.DoFile(_luaScript + ".lua");
TextAsset script = LuaScriptsManager.Instance.GetObject(_luaScript) as TextAsset;
_luaState.DoString(script.text);
CallLuaFun ("New",this);
CallLuaFun("Init");
}
/// <summary>
/// 加载子对象lua脚本并且创建子类
/// </summary>
/// <param name="childLuaScript"></param>
public BaseUiContainer LoadChildPanelAndLuaScript(string panelLoaclPath)
{
string[] tempLuaScritps = panelLoaclPath.Split('@');
string luaScript = tempLuaScritps[tempLuaScritps.Length-1].Trim()+"_lua";
//string fullPath = Application.dataPath + "/Resources/BundleResTemp/LuaScripts/LuaScripts";
// _luaState.AddSearchPath(fullPath);
// _luaState.DoFile(luaScript+ ".lua"); //加载lua脚本
TextAsset script = LuaScriptsManager.Instance.GetObject(luaScript) as TextAsset;
_luaState.DoString(script.text);
BaseUiContainer Child = new BaseUiContainer(this, _RegisterUI(panelLoaclPath).gameObject); //创建Panel脚本
return Child;
}
/// <summary>
/// 调用父类的外部方法,不带返回值
/// </summary>
/// <param name="funName"></param>
/// <param name="obj"></param>
public void CallLuaFun(string funName,System.Object obj = null)
{
if (_luaState == null)return;
_func = _luaState.GetFunction(_luaScript+"."+funName);
if (_func == null) return;
_func.BeginPCall();
if (obj != null)
_func.Push(obj);
else
_func.Push();
_func.PCall();
_func.EndPCall();
}
public LuaInterface.LuaTable CallLuaFuns(string funName, object[] obj = null)
{
object[] temp = null;
if (_luaState == null) return null;
_func = _luaState.GetFunction(_luaScript + "." + funName);
if (_func == null) return null;
object[] tempObjs = {};
if(obj == null)
temp = _func.Call((object)tempObjs);
else
temp = _func.Call((object)obj);
LuaInterface.LuaTable tb = temp[0] as LuaInterface.LuaTable;
return tb;
}
public override void Show ()
{
base.Show ();
CallLuaFun("Show");
}
public override void Close()
{
CallLuaFun("Close");
base.Close();
if (_luaState != null) {
_luaState.CheckTop ();
_luaState.Dispose ();
_luaState = null;
}
}
}