Ejemplo n.º 1
0
    public void RegComp(UnityEngine.Object regObj, Type type, string name, bool isArray = false)
    {
        LuaState lua_ = LuaInstance.instance.Get();

        Register.AddFuncInfo(type);
        LuaClass lua_class = LuaInstance.instance.RegisterLuaClass(type);

        FuncInfo[] funcInfos;
        if (lua_class.is_register == false)
        {
            if (LuaClassList.classes.TryGetValue(type, out funcInfos))
            {
                for (int j = 0; j < funcInfos.Length; j++)
                {
                    if (funcInfos[j].IsStatic)
                    {
                        lua_class.RegisterStaticFunction(funcInfos[j]);
                    }
                    else
                    {
                        lua_class.RegisterFunction(funcInfos[j]);
                    }
                }
            }

            lua_class.EndRegisterClass();
        }
        // register other CSharp object to lua object field
        if (isArray)
        {
            LuaInstance.instance.RegisterGameObject(regObj, Object_ref);
        }
        else
        {
            lua_.RawGetI(LuaAPI.LUA_REGISTRYINDEX, Object_ref);
            LuaInstance.instance.RegisterGameObject(regObj, name);
        }
    }