[Unity暖更新]tolua# & LuaFramework(十):扩展工具包

[Unity热更新]tolua# & LuaFramework(十):扩展工具包

这个工具包有以下功能:

1.提供一个资源打包工具。因为LuaFramework默认对例子中的资源进行打包,不具有通用性,因此要有这样一个工具,详细的见系列二。

2.提供一个工具简化编写lua文件的步骤。按照LuaFramework的规定,如果要添加一个Panel,那么就要编写对应的Controller、View,以及修改三个框架自带的lua文件,比较繁琐,因此要有这样一个工具提高效率。

[Unity暖更新]tolua# & LuaFramework(十):扩展工具包

3.提供一个小型的UI框架。这个框架是针对热更新而设计的,提供c#和lua的实现,规范c#代码的编写。优点是对于一个Panel,其c#的实现与其lua的实现有比较多的相似,可以减小二次开发的时间,例如下面的:

using UnityEngine;
using System.Collections;

public class MainPanel : UIPanelBase {

    public UILabel hpLabel;
    public UILabel mpLabel;

    protected override void Awake()
    {
        base.Awake();
        UIPanelManager.Instance.CreatePanel(UIPanelName.MainPanel, OnCreate);
    }

    protected override void OnCreate(GameObject go)
    {
        base.OnCreate(go);

        hpLabel = transform.FindChild("HpLabel").GetComponent<UILabel>();
        mpLabel = transform.FindChild("MpLabel").GetComponent<UILabel>();

        UIEventListener.Get(transform.FindChild("Button1").gameObject).onClick = 
            delegate(GameObject a) {
                UIPanelManager.Instance.GetPanel(UIPanelName.FirstPanel).Open();
        };

        UIEventListener.Get(transform.FindChild("Button2").gameObject).onClick =
            delegate(GameObject a)
            {
                UIPanelManager.Instance.GetPanel(UIPanelName.ThirdPanel).Open();
            };
    }

}

require "Common/define"
require "Logic/UIPanelBase"

MainCtrl = UIPanelBase:New();
local gameObject;
local transform;
local tweener;

function MainCtrl.New()
	return MainCtrl;
end

function MainCtrl.Awake()
	panelMgr:CreatePanel('Main', MainCtrl.OnCreate);
end

function MainCtrl.OnCreate(obj)
	gameObject = obj;
    transform = obj.transform;
	MainCtrl.gameObject = obj;
    MainCtrl.transform = obj.transform;
	
	MainCtrl.hpLabel = transform:FindChild("HpLabel"):GetComponent('UILabel');
	MainCtrl.mpLabel = transform:FindChild("MpLabel"):GetComponent('UILabel');
	
	UIEventListener.Get(transform:FindChild("Button1").gameObject).onClick = MainCtrl.OpenFirstPanel;
	UIEventListener.Get(transform:FindChild("Button2").gameObject).onClick = MainCtrl.OpenThirdPanel;
	
	MainCtrl:Open();
end

function MainCtrl.OpenFirstPanel()
	CtrlManager.GetCtrl(CtrlNames.First):Open();
end

function MainCtrl.OpenThirdPanel()
	CtrlManager.GetCtrl(CtrlNames.Third):Open();
end

你也许会觉得,上面的不同之处挺多的,但是不要忘了我们可以创建lua模板文件,这样一来,当实现了c#版本后,就可以较快地实现lua版本。


扩展包的截图:

[Unity暖更新]tolua# & LuaFramework(十):扩展工具包

下载地址:

http://pan.baidu.com/s/1dEZhqpV