示例#1
0
        /// <summary>
        /// 组合生成的定义,点击绑定,设置函数为一个字符串
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        static public string GetAllMat(LuaFileData dt)
        {
            string content = null;

            //className, defineList, find_component, set_function, null, click_function, defaultTextComponent
            if (dt != null && dt.clickFunction != null)
            {
                string        value1        = string.Empty;
                string        value2        = string.Empty;
                string        value3        = string.Empty;
                string        value4        = string.Empty;
                string        value5        = string.Empty;
                string        value6        = string.Empty;
                List <string> clickFunction = new List <string>(dt.clickFunction.Values);
                string        className     = dt.className;
                value1 = GetLuaString(dt.defineVar);
                value2 = GetLuaString(dt.setFunction);
                value3 = GetLuaString(dt.findComponent);
                value4 = GetLuaString(clickFunction);
                value5 = GetLuaString(dt.initMat);
                //这个暂时没用,有需求在加上
                value6 = GetLuaString(dt.defaultTextComponent);
                LuaUIMould uimould = new LuaUIMould();
                content = uimould.Set(className, value1, value2, value3, value4, value5);
            }
            return(content);
        }
示例#2
0
        /// <summary>
        /// 创建新的定义,点击绑定,设置函数,同时保存原有的逻辑(如点击逻辑,业务逻辑等)
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        static public string CreateNewFile(GameObject obj, string filePath)
        {
            CleanUpGameObject(obj);
            string      content = UILuaRead.Instance.ReadLua(filePath);
            LuaFileData dt      = GetComponentInfo(obj, filePath);

            if (dt == null)
            {
                return(null);
            }
            Dictionary <string, string> clickFunctionDic = dt.clickFunction;

            if (!string.IsNullOrEmpty(content))
            {
                string after_str      = string.Empty;
                string old_str        = string.Empty;
                string new_str        = string.Empty;
                string auto_after_str = string.Empty;
                string custom_str     = string.Empty;
                string auto_str       = string.Empty;
                GetReadStr(content, ref after_str, ref old_str, ref custom_str);
                Dictionary <string, string> clickTemp = ChangeFunc(old_str, clickFunctionDic);
                dt.clickFunction = clickTemp;
                string new_content = GetAllMat(dt);
                GetReadStr(new_content, ref auto_after_str, ref new_str, ref auto_str);
                string create_content = after_str + new_str + custom_str;
                return(create_content);
            }
            return(null);
        }
示例#3
0
        /// <summary>
        /// 创建新的UI文件,里面保存新的定义,点击绑定,设置函数(不需要保存原来的)
        /// </summary>
        /// <param name="Obj"></param>
        /// <param name="fileName"></param>
        /// <param name="respath"></param>
        /// <returns></returns>
        static public bool CreateUIFile(GameObject Obj, string fileName, string respath)
        {
            if (Obj != null)
            {
                string objName = Obj.name;

                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = objName;
                }
                string buildPath = EditorUtility.SaveFilePanel("选择保存路径:", constPath, fileName, "lua");
                if (string.IsNullOrEmpty(buildPath))
                {
                    return(false);
                }
                LuaFileData dt = GetComponentInfo(Obj, buildPath);
                if (dt == null)
                {
                    return(false);
                }
                string content = GetAllMat(dt);
                bool   is_succ = UILuaRead.Instance.WriteLua(buildPath, content);
                if (is_succ)
                {
                    if (string.IsNullOrEmpty(respath))
                    {
                        respath = GetResPath(Obj);
                    }
                    RegisterLuaFile(Obj, buildPath, respath);
                    SetLuaBehaviour(Obj, buildPath);
                }
                return(is_succ);
            }
            return(false);
        }