Example #1
0
 static int DestroyAll(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 0);
         LogicBaseLua.DestroyAll();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #2
0
 static int set_current(IntPtr L)
 {
     try
     {
         LogicBaseLua arg0 = (LogicBaseLua)ToLua.CheckUnityObject(L, 2, typeof(LogicBaseLua));
         LogicBaseLua.current = arg0;
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #3
0
 static int FastHide(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LogicBaseLua obj = (LogicBaseLua)ToLua.CheckObject(L, 1, typeof(LogicBaseLua));
         obj.FastHide();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #4
0
    static int set_HasLogicBaseLuaParent(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LogicBaseLua obj  = (LogicBaseLua)o;
            bool         arg0 = LuaDLL.luaL_checkboolean(L, 2);
            obj.HasLogicBaseLuaParent = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index HasLogicBaseLuaParent on a nil value" : e.Message));
        }
    }
Example #5
0
    static int set_fullLuaFileName(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LogicBaseLua obj  = (LogicBaseLua)o;
            string       arg0 = ToLua.CheckString(L, 2);
            obj.fullLuaFileName = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index fullLuaFileName on a nil value" : e.Message));
        }
    }
Example #6
0
    static int set_ID(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LogicBaseLua obj  = (LogicBaseLua)o;
            int          arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
            obj.ID = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index ID on a nil value" : e.Message));
        }
    }
Example #7
0
    static int get_IsFastHide(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LogicBaseLua obj = (LogicBaseLua)o;
            bool         ret = obj.IsFastHide;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index IsFastHide on a nil value" : e.Message));
        }
    }
Example #8
0
    static int get_ID(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LogicBaseLua obj = (LogicBaseLua)o;
            int          ret = obj.ID;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index ID on a nil value" : e.Message));
        }
    }
Example #9
0
    static int get_fullLuaFileName(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LogicBaseLua obj = (LogicBaseLua)o;
            string       ret = obj.fullLuaFileName;
            LuaDLL.lua_pushstring(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index fullLuaFileName on a nil value" : e.Message));
        }
    }
    void OnGUI()
    {
        GUILayout.Label("请确保Prefab的预览挂在【UIRoot】或【UICamera】下,否则出错", EditorStyles.boldLabel);
        GUILayout.Space(30f);

        GUILayout.Label("作者名字:", EditorStyles.label);
        m_luaAuthorName = EditorGUILayout.TextArea(m_luaAuthorName, GUILayout.Width(150));
        GUILayout.Space(10f);

        GUILayout.Label("lua文件所在的文件夹名(相对于 XY_Lua/logic/,如:level_sys)", EditorStyles.label);
        m_luaFolderName = EditorGUILayout.TextArea(m_luaFolderName, GUILayout.Width(150));
        GUILayout.Space(10f);

        GUILayout.Label("ui prefab文件所在的文件夹名(相对于 Resource/Prefab/UI/,如:Level)", EditorStyles.label);
        m_uiPrefabFolderName = EditorGUILayout.TextArea(m_uiPrefabFolderName, GUILayout.Width(150));
        GUILayout.Space(30f);

        if (GUILayout.Button("生 成"))
        {
            if (m_luaFolderName == null || m_uiPrefabFolderName == null || m_luaFolderName.Length < 1 || m_uiPrefabFolderName.Length < 1)
            {
                ShowNotification(new GUIContent("失败!文件夹名不能为空!"));
                return;
            }

            // 文件名和prefab的名字一样
            // 向上取得prefab的名字
            goPrefab = null;
            if (Selection.gameObjects.Length > 0)
            {
                GameObject go          = Selection.gameObjects[0];
                Transform  parentTrans = go.transform.parent;
                while (parentTrans != null)
                {
                    if (parentTrans.gameObject.GetComponent <UIRoot>() != null || parentTrans.gameObject.GetComponent <Camera>() != null)
                    {
                        goPrefab   = go;
                        m_fileName = goPrefab.name;
                        break;
                    }
                    go          = parentTrans.gameObject;
                    parentTrans = parentTrans.parent;
                }

                if (goPrefab == null)
                {
                    ShowNotification(new GUIContent("失败!Prefab的根节点没有挂在【UIRoot】或【UICamera】下!"));
                    return;
                }
            }
            else
            {
                ShowNotification(new GUIContent("失败!请至少选择一个节点,如果不想选,就选择根节点"));
                return;
            }

            Debug.Log("开始!!!!!!!!!");
            Debug.Log("lua文件:" + GetLuaFilePath());
            Debug.Log("ui prefab文件:" + GetUIPrefabFilePath());

            // 挂上LogicBaseLua
            LogicBaseLua logicBaseLua = goPrefab.GetComponent <LogicBaseLua>();
            if (logicBaseLua == null)
            {
                logicBaseLua = goPrefab.AddComponent <LogicBaseLua>();
            }
            logicBaseLua.fullLuaFileName = GetLuaBehaviorPath();
            logicBaseLua.isOldUnique     = true;

            // table declare
            StringBuilder fileContent = new StringBuilder();

            fileContent.Append("--[[--\n");
            fileContent.Append("* @Description: description\n");
            fileContent.AppendFormat("* @Author:   {0}\n", m_luaAuthorName);
            fileContent.AppendFormat("* @FileName:  {0}\n", m_fileName + ".lua");
            fileContent.Append("* @DateTime:  " + DateTime.Now.ToString() + "\n");
            fileContent.Append("]]\n\n");

            // 目前只支持生成单例对象的lua
            MakeSingleClassLua(fileContent);

            string       file       = GetLuaFilePath();
            StreamWriter textWriter = new StreamWriter(file, false, Encoding.UTF8);

            textWriter.Write(fileContent.ToString());
            textWriter.Flush();
            textWriter.Close();

            Debug.Log("完成!!!!!!!!!!!");

            ShowNotification(new GUIContent("成功!Lua文件生成在:" + GetLuaBehaviorPath()));
        }
    }
Example #11
0
    public void RefreshLuaSetting()
    {
        try
        {
            if (fullLuaFileName == null)
            {
                return;
            }

            current         = this;
            fullLuaFileName = fullLuaFileName.Replace('\\', '/');
            m_luaFileName   = fullLuaFileName.Substring(fullLuaFileName.LastIndexOf('/') + 1);
            luaState.Require(fullLuaFileName);

            LogicBaseLua[] baseLuas = gameObject.GetComponentsInChildren <LogicBaseLua>(true);
            for (int i = 0; i < baseLuas.Length; ++i)
            {
                if (baseLuas[i].gameObject == this.gameObject)
                {
                    continue;
                }
                baseLuas[i].HasLogicBaseLuaParent = true;
            }

            m_luaClassName = m_luaFileName;
            self           = luaState.GetTable(m_luaClassName);
            update         = self.RawGetLuaFunction("Update");
            lateUpdate     = self.RawGetLuaFunction("LateUpdate");
            fixedUpdate    = self.RawGetLuaFunction("FixedUpdate");

            InitLuaFuncHandlers();

            // 对于只有一个实例的情况
            if (!isOldUnique)
            {
                LuaFunction func = self.RawGetLuaFunction("New");

                if (func == null)
                {
                    throw new LuaException(m_luaClassName + " does not have a New function, GameObject is" + gameObject.name);
                }

                func.BeginPCall();
                func.PCall();
                self.Dispose();
                self = func.CheckLuaTable();
                func.EndPCall();
                func.Dispose();
                func = null;
            }

            LuaFunction addLuaObjectFunc = luaState.GetFunction("logicLuaObjMgr.AddLuaUIObject");
            addLuaObjectFunc.BeginPCall();
            addLuaObjectFunc.Push(gameObject);
            addLuaObjectFunc.Push(self);
            addLuaObjectFunc.PCall();
            addLuaObjectFunc.EndPCall();
            addLuaObjectFunc.Dispose();
            addLuaObjectFunc = null;

            self.name          = m_luaClassName;
            self["gameObject"] = gameObject;
            self["transform"]  = transform;
            self["ID"]         = ID;
            CallLuaFunction(m_luaClassName + ".Awake");
        }
        catch (Exception e)
        {
            luaState.ToLuaException(e);
        }
    }