From 44f8ef6bd9d84fa9a181cc83c808b2f56cbf30ae Mon Sep 17 00:00:00 2001 From: mrkelly Date: Tue, 28 Jun 2016 18:39:56 +0800 Subject: [PATCH] =?UTF-8?q?UI=20Lua=E8=84=9A=E6=9C=AC=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KSFramework/Editor/KSFrameworkEditor.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs b/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs index 49972638..965011fc 100644 --- a/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs +++ b/KSFramework/Assets/Plugins/KSFramework/Editor/KSFrameworkEditor.cs @@ -1,5 +1,6 @@ using UnityEngine; using System.Collections; +using System.IO; using KEngine; using KEngine.UI; using UnityEditor; @@ -93,6 +94,67 @@ public static void OpenMainScene() #endif } + [MenuItem("KSFramework/UI/Make UI Lua Scripts(Current Scene)")] + public static void GenerateLuaTemplates() + { + var luaPath = AppEngine.GetConfig("KSFramework.Lua", "LuaPath"); + Debug.Log("Find UI from current scenes, LuaScriptPath: " + luaPath); + + var windowAssets = GameObject.FindObjectsOfType(); + if (windowAssets.Length > 0) + { + foreach (var windowAsset in windowAssets) + { + var uiName = windowAsset.name; + var scriptPath = string.Format("{0}/{1}/UI/UI{2}.lua", KResourceModule.EditorProductFullPath, + luaPath, uiName); + if (!File.Exists(scriptPath)) + { + File.WriteAllText(scriptPath, LuaUITempalteCode.Replace("$UI_NAME", "UI" + uiName)); + Debug.LogWarning("New Lua Script: " + scriptPath); + } + else + { + Debug.Log("Exists Lua Script, ignore: " + scriptPath); + } + } + + } + else + { + Debug.LogError("Not found any `UIWindowAsset` Component"); + } + } + + /// + /// UI Lua Scripts Tempalte Code + /// + private static string LuaUITempalteCode = @" +local UIBase = import('KSFramework/UIBase') + +if not Cookie then local Cookie = Slua.GetClass('KSFramework.Cookie') end +if not Log then Log = Slua.GetClass('KEngine.Log') end + +local $UI_NAME = {} +extends($UI_NAME, UIBase) + +-- create a ui instance +function $UI_NAME.New(controller) + local newUI = new($UI_NAME) + newUI.Controller = controller + return newUI +end + +function $UI_NAME:OnInit(controller) + Log.Info('$UI_NAME OnInit, do controls binding') +end + +function $UI_NAME:OnOpen() + Log.Info('$UI_NAME OnOpen, do your logic') +end + +return $UI_NAME +"; [MenuItem("KSFramework/UI/Reload UI Lua %&r")] public static void ReloadLuaCache() {