Esempio n. 1
0
        private static void SetABName()
        {
            NBsn.C_Global.EditorBegin();
            LuaTable table = NBsn.C_Global.Instance.Lua.NewTable();

            NBsn.C_Global.Instance.Lua.DoString("require 'editor.ab_config'");
            NBsn.C_Global.Instance.Lua.Get("g_tTemp", out table);
            table.ForEach <string, LuaTable>((strPath, tb) => {
                string strAB;
                tb.Get("strAssetBundleOutPath", out strAB);
                NBsn.C_Global.Instance.Log.InfoFormat("{0} -> {1}", strPath, strAB);

                var strAssetsPath = strPath.PathFormat();
                var importer      = AssetImporter.GetAtPath(strAssetsPath);
                if (importer == null)
                {
                    Debug.LogErrorFormat("basePath={0} importer == null", strAssetsPath);
                    return;
                }

                var strABPath = strAB;
                importer.SetAssetBundleNameAndVariant(strABPath, null);
            });

            NBsn.C_Global.EditorEnd();
        }
Esempio n. 2
0
        private void ResetLua()
        {
            if (m_LuaTable != null)
            {
                CompAgent.ClearChildren(transform);
                CompAgent.ClearCompnents <LuaBehaviour>(transform);
                m_LuaTable = null;

                List <string> loadedRemoveList = new List <string>();
                m_LoadedTable.ForEach <string, object>((luaName, value) => loadedRemoveList.Add(luaName));
                foreach (string luaName in loadedRemoveList)
                {
                    if (!m_LoadedBuiltInSet.Contains(luaName))
                    {
                        m_LoadedTable.Set <string, object>(luaName, null);
                    }
                }
                List <string> preloadRemoveList = new List <string>();
                m_PreloadTable.ForEach <string, object>((luaName, value) => preloadRemoveList.Add(luaName));
                foreach (string luaName in preloadRemoveList)
                {
                    if (!m_PreloadBuiltInSet.Contains(luaName))
                    {
                        m_PreloadTable.Set <string, object>(luaName, null);
                    }
                }

                foreach (LuaTable csTable in m_HotFixDict.Keys)
                {
                    foreach (string fieldName in m_HotFixDict[csTable])
                    {
                        m_HotFix(csTable, fieldName, null);
                    }
                }
                m_HotFixDict.Clear();
                foreach (LuaTable csTable in m_HotFixExDict.Keys)
                {
                    foreach (string fieldName in m_HotFixExDict[csTable])
                    {
                        m_HotFixEx(csTable, fieldName, null);
                    }
                }
                m_HotFixExDict.Clear();

                List <string> globalVarRemoveList = new List <string>();
                m_LuaEnv.Global.ForEach <string, object>((key, value) => globalVarRemoveList.Add(key));
                foreach (string varName in globalVarRemoveList)
                {
                    if (!m_GlobalVarBuiltInSet.Contains(varName))
                    {
                        m_LuaEnv.Global.Set <string, object>(varName, null);
                    }
                }

                FuncInvoke(m_LuaEnv.Global, "collectgarbage");
            }
        }
Esempio n. 3
0
 public void GetSkillTable(LuaTable skillTab, List <ZtEdFrameData> frameList)
 {
     skillTab.ForEach <int, LuaTable>((int key, LuaTable value) =>
     {
         ZtEdFrameData framedata = new ZtEdFrameData();
         framedata.frame         = key;
         frameList.Add(framedata);
         GetSkillParam(value, framedata);
     });
 }
Esempio n. 4
0
        public static StructData GenerateVMData(LuaTable luaData)
        {
            LuaTable   strct     = luaData.Get <LuaTable>("__vm_value");
            StructData strctData = new StructData();

            strct.ForEach <string, LuaTable>(delegate(string key, LuaTable el)
            {
                strctData.AddField(key, XLuaData.GenerateDataWithLuaTable(el));
            });
            return(strctData);
        }
Esempio n. 5
0
 public void GetSkillParam(LuaTable actiontable, ZtEdFrameData framedata)
 {
     actiontable.ForEach <int, LuaTable>((int key, LuaTable value) =>
     {
         LuaTable paramTab           = value.Get <LuaTable>("param");
         int actionType              = value.Get <int>("actionType");
         ZtEdSkillAction skillAction = new ZtEdSkillAction();
         skillAction.actionType      = actionType;
         paramTab.ForEach <int, string>((int paramKey, string paramVal) =>
         {
             skillAction.param.Add(paramVal);
         });
         framedata.actoinList.Add(skillAction);
     });
 }
Esempio n. 6
0
        public void SendSavePoint(LuaTable tbl)
        {
            List <DianfengInfo_Attr> list = new List <DianfengInfo_Attr>();

            tbl.ForEach <int, int>((id, num) =>
            {
                DianfengInfo_Attr attr = new DianfengInfo_Attr();
                attr.ID  = id;
                attr.Num = num;

                list.Add(attr);
            });

            NetLogicGame.Instance.SendReqDianfengSave(list);
        }
Esempio n. 7
0
        void Start()
        {
            luaEnv.DoString(@"
                function ReturnMultiValue()
                    return 1, 1.5, 'MultiValueFromLua'
                end
                function ReturnTable()
                    return { intValue = 2, floatValue = 2.5, stringValue = 'TableFromLua' }
                end
                function ArrayParamTest()
                    local ArrayTest = CS.EZhex1991.EZUnity.XLuaExample.FromLua.ArrayTest
                    local Color = CS.UnityEngine.Color
                    ArrayTest({ Color.red, Color.green, Color.blue }, 0)
                    ArrayTest({ Color.red, Color.green, Color.blue }, 1)
                end

                Message = {
                    content = 'Interface Test'
                }
            ");
            int    intValue    = 0;
            float  floatValue  = 0;
            string stringValue = "";

            MultiValueFromLua func1 = luaEnv.Global.Get <MultiValueFromLua>("ReturnMultiValue");

            intValue = func1(out floatValue, ref stringValue);
            print(string.Format("intValue={0}, floatValue={1}, stringValue={2}", intValue, floatValue, stringValue));

            TableFromLua func2 = luaEnv.Global.Get <TableFromLua>("ReturnTable");
            LuaTable     table = func2();

            intValue    = table.Get <int>("intValue");
            floatValue  = table.Get <float>("floatValue");
            stringValue = table.Get <string>("stringValue");
            print(string.Format("intValue={0}, floatValue={1}, stringValue={2}", intValue, floatValue, stringValue));

            LuaFunction func3 = luaEnv.Global.Get <LuaFunction>("ArrayParamTest");

            func3.Call();

            table.ForEach <string, object>((key, value) => print(string.Format("{0}={1}, type:{2}", key, value, value.GetType())));

            IMessage test = luaEnv.Global.Get <IMessage>("Message");

            print(test.content);
        }
Esempio n. 8
0
 void Initilize(LuaTable luaTbl, LuaTable LuaDLL)
 {
     if (luaTbl == null)
     {
         Debug.LogError("LuaComponent.Initilize: initilize with nil lua table");
         return;
     }
     
     LuaDLL.ForEach<int,LuaFunction>((int func,LuaFunction cb) =>{
         //int func;
         //LuaFunction cb;
         //tb.Get<int,int>(1,out func);
         //tb.Get<int,LuaFunction>(1,out cb);
         _luaBindFuncs[func] = cb;
     });
     _luaEntity = luaTbl;
 }
        public static IListData GenerateVMData(LuaTable luaData)
        {
            LuaTable  listLua  = luaData.Get <LuaTable>("__vm_value");
            LuaTable  first    = listLua.Get <int, LuaTable>(1);
            IListData listData = CreateListDataInstanceWithItemLuaTable(first);

            listData.DisableValueChangeHandler = true;
            listLua.ForEach <int, LuaTable>(delegate(int index, LuaTable item)
            {
                listData.Add(XLuaData.GenerateDataWithLuaTable(item));
            });
            listData.DisableValueChangeHandler = false;
            listData.InvokeValueChanged();

            luaData.Set <string, Action <LuaTable> >("__vm_list_add", delegate(LuaTable item) {
                listData.AddItem(XLuaData.GenerateDataWithLuaTable(item));
            });

            luaData.Set <string, Action <int, LuaTable> >("__vm_list_insert", delegate(int index, LuaTable item) {
                listData.InsertItem(index - 1, XLuaData.GenerateDataWithLuaTable(item));
            });

            luaData.Set <string, Action>("__vm_list_pop", delegate() {
                listData.RemoveAt(listData.Count - 1);
            });

            luaData.Set <string, Action <int> >("__vm_list_remove", delegate(int index) {
                listData.RemoveAt(index - 1);
            });

            luaData.Set <string, Action>("__vm_list_reorder", delegate() {
                listData.DisableValueChangeHandler = true;
                LuaTable newListLua = luaData.Get <LuaTable>("__vm_value");
                listData.Clear();
                newListLua.ForEach <int, LuaTable>(delegate(int index, LuaTable item)
                {
                    listData.Add(XLuaData.GenerateDataWithLuaTable(item));
                });
                listData.DisableValueChangeHandler = false;
                listData.InvokeValueChanged();
            });

            return(listData);
        }
Esempio n. 10
0
        void Awake()
        {
            m_LuaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
            m_LuaEnv.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg);
            m_LuaEnv.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);

            m_Require  = m_LuaEnv.Global.Get <Func <string, LuaTable> >("require");
            m_DoFile   = m_LuaEnv.Global.Get <Func <string, LuaTable> >("dofile");
            m_LoadFile = m_LuaEnv.Global.Get <Func <string, LuaFunction> >("loadfile");

            m_TraceBack = m_LuaEnv.Global.GetInPath <Func <string, int, string> >("debug.traceback");

            LuaTable package = m_LuaEnv.Global.Get <LuaTable>("package");

            m_LoadedTable = package.Get <LuaTable>("loaded");
            m_LoadedTable.ForEach <string, object>((key, value) => m_LoadedBuiltInSet.Add(key));
            m_PreloadTable = package.Get <LuaTable>("preload");
            m_PreloadTable.ForEach <string, object>((key, value) => m_PreloadBuiltInSet.Add(key));

            LuaTable xlua = m_LuaEnv.Global.Get <LuaTable>("xlua");

            m_LuaEnv.Global.Set <string, LuaTable>("xlua", xlua);
            m_HotFix = xlua.Get <Action <LuaTable, object, LuaFunction> >("hotfix");
            xlua.Set <string, Action <LuaTable, object, LuaFunction> >("hotfix", HotFix);

            LuaTable util = Require("xlua.util");

            m_LuaEnv.Global.Set <string, LuaTable>("util", util);
            m_HotFixEx = util.Get <Action <LuaTable, object, LuaFunction> >("hotfix_ex");
            util.Set <string, Action <LuaTable, object, LuaFunction> >("hotfix_ex", HotFixEx);

            LuaTable csHelp = Require("LuaUtil.CSHelp");

            m_LuaEnv.Global.Set <string, LuaTable>("CSHelp", csHelp);
            m_FuncInvoke = csHelp.Get <Func <object, object[], object> >("FuncInvoke");

            m_LuaEnv.Global.ForEach <string, object>((key, value) => m_GlobalVarBuiltInSet.Add(key));

            m_LuaEnv.AddLoader(CustomLoad);

            Debugger.LogMessageFormat = message => m_TraceBack(message.ToString(), 1);
        }
Esempio n. 11
0
        public void HotFix(LuaTable csTable, object field, LuaFunction fixFunc = null)
        {
            if (m_HotFix != null)
            {
                HashSet <string> set;
                if (m_HotFixDict.ContainsKey(csTable))
                {
                    set = m_HotFixDict[csTable];
                }
                else
                {
                    set = new HashSet <string>();
                    m_HotFixDict[csTable] = set;
                }

                if (field is string)
                {
                    if (fixFunc != null)
                    {
                        string fieldName = field.ToString();
                        if (!set.Contains(fieldName))
                        {
                            set.Add(fieldName);
                        }
                    }
                }
                else if (field is LuaTable)
                {
                    LuaTable fixTable = field as LuaTable;
                    fixTable.ForEach <string, object>((fieldName, function) =>
                    {
                        if (!set.Contains(fieldName))
                        {
                            set.Add(fieldName);
                        }
                    });
                }

                m_HotFix(csTable, field, fixFunc);
            }
        }
Esempio n. 12
0
        //---------------------------------------------------------------------
        // 异步加载本地的AssetBundle
        public LoaderTicket LoadLocalBundleAsync(LuaTable lua_table, LuaTable need_load_ab_path, DelegateLua4 loaded_callback)
        {
            List <string> list_ab_name = new List <string>();

            need_load_ab_path.ForEach <int, string>(
                (i, v) =>
            {
                list_ab_name.Add(v);
            });

            var ticket = Context.AsyncAssetLoadGroup.asyncLoadLocalBundle(
                list_ab_name, _eAsyncAssetLoadType.LocalBundle, (List <AssetBundle> list_ab1) =>
            {
                if (loaded_callback != null)
                {
                    loaded_callback.Invoke(lua_table, list_ab1);
                    loaded_callback = null;
                }
            });

            return(ticket);
        }
Esempio n. 13
0
    public List <ZtEdFrameData> LoadSkillLua(string skillId)
    {
        //DoString("Battle.Skill.SkillDefine");
        DoString("ALuaConfig.Local.SkillActionConfig");
        //DoString("Battle.skill.MoveAction.MoveActionConfig");
        SkillConfigTab = luaenv.Global.Get <LuaTable>("SkillActionConfig");//映射到LuaTable,by ref

        CurLuaKey    = skillId;
        CurFrameList = GetSkillFrameList(skillId);
        if (SkillIdList == null)
        {
            SkillIdList = new List <string>();
            SkillConfigTab.ForEach <string, LuaTable>((string key, LuaTable value) =>
            {
                if (key != "TestSkillId")
                {
                    SkillIdList.Add(key);
                }
            });
            SkillIdList.Sort();
        }
        return(CurFrameList);
    }
Esempio n. 14
0
    public static LuaTable LoadSprieList(string _path, LuaTable _tab)
    {
        string      ab_name = QPathHelper.GetAssetBundleOutPath() + _path;
        AssetBundle ab      = null;

        if (ab_dict.ContainsKey(ab_name))
        {
            ab = ab_dict[ab_name];
        }
        else
        {
            ab = AssetBundle.LoadFromFile(ab_name);
            ab_dict.Add(ab_name, ab);
        }
        if (ab != null)
        {
            LuaTable sprites = AppMng.luaEnv.NewTable();
            _tab.ForEach <int, string> ((k, v) =>
            {
                Sprite go = ab.LoadAsset <Sprite> (v);
                if (go != null)
                {
                    sprites.Set <string, Sprite> (v, go);
                }
                else
                {
                    Debug.LogErrorFormat("[ABTool.LoadSprieList]资源加载为空:{0}.{1}", _path, v);
                }
            });
            return(sprites);
        }
        else
        {
            Debug.LogError("[ABTool.LoadSprieList]资源加载为空:" + _path);
            return(null);
        }
    }
Esempio n. 15
0
    /// <summary>
    /// 设置玩家属性 必须在初始化App之前调用
    /// </summary>
    /// <param name="level">玩家等级</param>
    /// <param name="iapt">购买总金额</param>
    /// <param name="userCreationDate">创建时间 首次进游戏时间</param>
    /// <param name="att">自定义参数 最多5个 key和value都为string类型 </param>
    public void SetAdsUserInfo(int level, double iapt, long userCreationDate, LuaTable att)
    {
        string id = IronSource.Agent.getAdvertiserId();

        IronSource.Agent.setUserId(id);
        EzDebug.Log("unity-script: getAdvertiserId" + id);

        IronSourceSegment segment = new IronSourceSegment();

        segment.level            = level;
        segment.iapt             = iapt;
        segment.userCreationDate = userCreationDate;

        //自定义参数最多5个
        if (att != null)
        {
            att.ForEach <string, string>((k, v) =>
            {
                segment.customs.Add(k, v);
            });
        }

        IronSource.Agent.setSegment(segment);
    }
Esempio n. 16
0
 void OnGUI()
 {
     if (Application.isPlaying && m_aiList != null)
     {
         if (m_aiResName != null)
         {
             GUILayout.BeginHorizontal();
             {
                 GUILayout.Label("行为树资源文件名:" + m_aiResName, m_guiStyleBigLabel);
             }
             GUILayout.EndHorizontal();
         }
         GUILayout.BeginHorizontal();
         {
             m_scrollViewPos = GUILayout.BeginScrollView(m_scrollViewPos);
             {
                 m_aiList.DoLayoutList();
             }
             GUILayout.EndScrollView();
             if (m_historyLogCache != null || m_historyLog != null)
             {
                 m_scrollViewPos1 = GUILayout.BeginScrollView(m_scrollViewPos1, GUILayout.Width(position.width * 4 / 7));
                 {
                     int logCacheCount = 0;
                     m_historyLogCache?.ForEach <int, LuaTable>((i, cache) => {
                         var str = cache.Get <string, string>("content");
                         logCacheCount++;
                         if (m_pressedButtonIndex != -1 && m_pressedButtonIndex == i)
                         {
                             str = string.Format("--->{0}<---", str);
                             m_currentAiSubContent = cache.Get <string, LuaTable>("subContent");
                             m_debugInfo           = cache.Get <string, LuaTable>("debugInfo");
                         }
                         if (GUILayout.Button(str, m_guiStyleDebugInfo))
                         {
                             m_pressedButtonIndex = i;
                         }
                     });
                     m_historyLog?.ForEach <int, LuaTable>((i, cache) => {
                         var str = cache.Get <string, string>("content");
                         if (m_pressedButtonIndex != -1 && m_pressedButtonIndex == i + logCacheCount)
                         {
                             str = string.Format("--->{0}<---", str);
                             m_currentAiSubContent = cache.Get <string, LuaTable>("subContent");
                             m_debugInfo           = cache.Get <string, LuaTable>("debugInfo");
                         }
                         if (GUILayout.Button(str, m_guiStyleDebugInfo))
                         {
                             m_pressedButtonIndex = i + logCacheCount;
                         }
                     });
                 }
                 GUILayout.EndScrollView();
             }
             if (m_pressedButtonIndex != -1)
             {
                 GUILayout.BeginVertical(GUILayout.Width(150f));
                 {
                     GUILayout.BeginVertical("box");
                     {
                         GUILayout.Label("详细数据:");
                         m_debugInfo?.ForEach <string, string>((key, value) => {
                             GUILayout.Label(string.Format("{0} : {1}", key, value));
                         });
                     }
                     GUILayout.EndVertical();
                     GUILayout.BeginVertical("box");
                     {
                         GUILayout.Label("打断信息:");
                         m_currentAiSubContent?.ForEach <int, string>((i, subContent) => {
                             GUILayout.Label(subContent, m_guiStyleDebugInfo);
                         });
                     }
                     GUILayout.EndVertical();
                 }
                 GUILayout.EndVertical();
             }
         }
         GUILayout.EndHorizontal();
     }
     else
     {
         GUILayout.Label("本工具需要游戏运行时才有效!", m_guiStyleBigLabel);
     }
 }
Esempio n. 17
0
 private void ListReload()
 {
     if (Application.isPlaying)
     {
         if (m_currentBattle == null)
         {
             var luaBridge = LuaManager.Instance.Bridge;
             var b         = luaBridge.DoString("return Battle")[0];
             if (b != null)
             {
                 // ** bmg
                 m_currentBattle = (LuaTable)b;
                 m_currentBattle.Get("Instance", out LuaTable instance);
                 if (instance != null)
                 {
                     m_currentBattle = instance;
                 }
             }
             if (m_currentBattle == null)
             {
                 // ** 其他
                 var battle = (LuaTable)luaBridge.DoString(@"return require('Logic/Battle/Battle')")[0];
                 battle.Get("Instance", out LuaTable instance);
                 if (instance != null)
                 {
                     m_currentBattle = instance;
                 }
                 else
                 {
                     m_currentBattle = (LuaTable)luaBridge.DoString("return Battle")[0];
                 }
             }
             LuaTable actorsMap = null;
             m_currentBattle?.Get("actorsMap", out actorsMap);
             if (actorsMap == null)
             {
                 m_currentBattle = null;
             }
         }
         if (m_currentBattle == null)
         {
             return;
         }
         if (m_targetAiBev == null || m_allAiBev == null)
         {
             m_currentBattle.Get("TargetAIBev", out m_targetAiBev);
             m_currentBattle.Get("AllAIBev", out m_allAiBev);
         }
         LuaTable      aiBevTable   = (LuaTable)m_allAiBev.Call(m_currentBattle)[0];
         List <string> fileNameList = new List <string>();
         aiBevTable.ForEach <string, LuaTable>((fileName, currentData) => {
             fileNameList.Add(fileName);
         });
         fileNameList.Sort((a, b) => String.Compare(a, b, StringComparison.Ordinal));
         var aiBevNames = fileNameList.ToArray();
         if (m_aiList == null)
         {
             m_aiList = new ReorderableList(aiBevNames, typeof(string), false, false, false, false);
             m_aiList.drawElementCallback += (rect, index, isActive, isFocused) => {
                 var currentName = (string)m_aiList.list[index];
                 EditorGUI.LabelField(rect, currentName);
             };
             m_aiList.onSelectCallback += list => {
                 m_pressedButtonIndex = -1;
                 m_historyLog         = null;
                 m_historyLogCache    = null;
                 m_aiResName          = null;
             };
         }
         else
         {
             m_aiList.list = aiBevNames;
             var index = m_aiList.index;
             if (index >= 0 && index < m_aiList.count)
             {
                 m_aiList.index = Array.FindIndex(aiBevNames, p => p == (string)m_aiList.list[index]);
             }
         }
     }
 }