Esempio n. 1
0
 public static void RegisterClass(ILuaState lua)
 {
     LuaComponentMaskableGraphic.RegisterClass(lua);
     LuaComponentUIText.RegisterClass(lua);
     LuaComponentUIImage.RegisterClass(lua);
     //LuaComponentUIButton.RegisterClass(lua);
 }
Esempio n. 2
0
        // -- describing object oriented class in Lua
        // Test = {}
        // function Test:new()
        //   o = {}
        //   setmetatable(o, self)
        //   self.__index = self
        //   return o
        // end
        // function Test:hoge()
        //   return 3
        // end
        // NewTest = Test:new()
        // function NewTest:hoge()
        //   return 4
        // end
        public static int PushNew(ILuaState lua, GameObject obj)
        {
            LuaVM.Assert(lua, obj != null);
            LuaGameObjectCache cache = obj.GetComponent <LuaGameObjectCache>();

            if (cache != null && cache.index == LuaConstants.LUA_NOREF)
            {
                Object.Destroy(cache);
                cache = null;
            }
            if (cache == null)
            {
                cache = obj.AddComponent <LuaGameObjectCache>();
                // o = {}
                lua.NewTable();
                // setmetatable(o, self)
                //lua.PushValue(-2); // self
                lua.GetGlobal(klassName);
                lua.SetMetaTable(-2); // -> o
                // self.__index = self
                lua.GetMetaTable(-1);
                lua.SetField(-1, "__index");
                // return o
                set_internal <GameObject>(lua, -1, obj);
                set_boolean(lua, -1, "is_prefab", false);
                //
                LuaScriptBehaviour lsb = obj.GetComponent <LuaScriptBehaviour>();
                if (lsb != null)
                {
                    LuaComponentBehaviour.PushNew(lua, lsb);
                    lua.SetField(-2, "behaviour");
                }
                LuaComponentTransform.PushNew(lua, obj.transform);
                lua.SetField(-2, "transform");
                RectTransform rt = obj.GetComponent <RectTransform>();
                if (rt != null)
                {
                    LuaComponentRectTransform.PushNew(lua, rt);
                    lua.SetField(-2, "rect_transform");
                }
                LuaComponentUIText.PushNew(lua, obj);
                lua.SetField(-2, "ui_text");
                LuaComponentUIImage.PushNew(lua, obj);
                lua.SetField(-2, "ui_image");
                if (constructorHook != null)
                {
                    constructorHook(lua, obj);
                }
                lua.PushValue(-1);
                int refidx = lua.L_Ref(LuaDef.LUA_REGISTRYINDEX);
                cache.index    = refidx;
                cache.luaState = lua;
            }
            lua.RawGetI(LuaDef.LUA_REGISTRYINDEX, cache.index);
            //Debug.Log(string.Format("Find {0} {1}", objid, obj.name));
            if (get_internal <GameObject>(lua, -1) == null)
            {
                set_internal <GameObject>(lua, -1, obj);
            }
            return(1);
        }