zoukankan      html  css  js  c++  java
  • Unity热更新03-C#调用XLua-06-将Lua表 映射到C#的列表和字典

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Lesson6_CallListDic : MonoBehaviour
    {
        void Start()
        {
            LuaMgr.GetInstance().Init();
            LuaMgr.GetInstance().DoLuaFile("Main");
    
            //同一类型List
            List<int> list = LuaMgr.GetInstance().Global.Get<List<int>>("testList");
            Debug.Log("*******************List************************");
            for ( int i = 0; i <list.Count; ++i )
            {
                Debug.Log(list[i]);
            }
            //值拷贝 浅拷贝 不会改变lua中的内容
            list[0] = 100;
            List<int> list2 = LuaMgr.GetInstance().Global.Get<List<int>>("testList");
            Debug.Log(list2[0]);
    
            //不指定类型 object
            List<object> list3 = LuaMgr.GetInstance().Global.Get<List<object>>("testList2");
            Debug.Log("*******************List object************************");
            for (int i = 0; i < list3.Count; ++i)
            {
                Debug.Log(list3[i]);
            }
    
            Debug.Log("*******************Dictionary************************");
            Dictionary<string, int> dic = LuaMgr.GetInstance().Global.Get<Dictionary<string, int>>("testDic");
            foreach (string item in dic.Keys)
            {
                Debug.Log(item + "_" + dic[item]);
            }
            dic["1"] = 100000;
            //值拷贝 不会改变lua中的内容
            Dictionary<string, int> dic2 = LuaMgr.GetInstance().Global.Get<Dictionary<string, int>>("testDic");
            Debug.Log(dic2["1"]);
    
            Debug.Log("*******************Dictionary object************************");
            Dictionary<object, object> dic3 = LuaMgr.GetInstance().Global.Get<Dictionary<object, object>>("testDic2");
            foreach (object item in dic3.Keys)
            {
                Debug.Log(item + "_" + dic3[item]);
            }
        }
    }
    
    
  • 相关阅读:
    爬虫面试资料
    python高级知识
    Python2和Python3的字符串编码和类型
    cookie和session-csrf防护-中间件
    [干货]弄清楚迭代器, 生成器概念/作用
    MySQL中四种常用存储引擎的介绍
    python常见面试集合
    [MongoDB教程] 2.MongoDB的安装与使用
    深入理解:线程,进程,协程和并行,并发-协程
    [MongoDB教程] 1.简介
  • 原文地址:https://www.cnblogs.com/unitysir/p/13890975.html
Copyright © 2011-2022 走看看