今天主要学习加载XML表中的数据,按每条数据对应一个预制体方块显示在UI界面上:

一、图鉴界面上加载预制体方块和相应数据:

using UnityEngine;
using System.Collections;
using System.Collections .Generic ;public class PetIllustrations : MonoBehaviour {public static PetIllustrations self;public GameObject parentObj;public int number{get{return ConfigManager.Instance.GetpetXmlDictCount();}}private GameObject[] gridItemobj = null;//加载数量即为xml所有数量void OnEnable(){InitPetIllustrations();}void Awake(){self = this;}public void InitPetIllustrations()//加载所有宠物{UnityEngine.Object gridItem = Resources.Load("Prefabs/item/"+"petItem");if (gridItemobj == null){// gridItemobj = new GameObject[ConfigManager.Instance.GetpetXmlDictCount()];gridItemobj = new GameObject[number];}for (int i = 0; i < gridItemobj.Length; i++)//           {gridItemobj[i] = GameObject.Instantiate(gridItem) as GameObject;//实例化gridItemobj[i].name = "petItem" + (i + 1).ToString();//添加的预制体的名字gridItemobj[i].transform.parent = parentObj.transform;//确定父物体位置,gridItemobj[i].transform.localPosition = Vector3.zero;//落点为中心点gridItemobj[i].transform.localScale = Vector3.one;//大小正常(1)gridItemobj[i].GetComponent<petItem>().UpdatepetItemData(i + 1);//给预制体加载数据。}}public void OnClickBtnBack(){UIManager.instance.HidePanel(UIPanelNames.PetIllustrationsPanel);RoleControl.self.IsCanMove = false;}
}

二、预制体加载数据:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;public class petItem : MonoBehaviour {public static petItem self;public PetXmlData PetXmlVO;public Image HeadImage;public Image ImageMask;public Text Text_Hp;public Text Text_Attack;public Text Text_Lv;void Awake(){self = this;}public void UpdatepetItemData(int id)//预制体 加载数据{PetXmlVO = ConfigManager.Instance.GetPetData(id);      Text_Hp.text = PetXmlVO.hp.ToString();Text_Attack.text = PetXmlVO.attack.ToString();Text_Lv.text = PetXmlVO.level.ToString();HeadImage.sprite = Resources.Load<Sprite>("Images/" + PetXmlVO.headImage);}
}

三、数据管理DataManager:

using UnityEngine;
using Mono.Xml;
using System.Security;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Reflection;
using ZPStudio;public class ConfigManager : MonoBehaviour
{private static ConfigManager mInstance = null;//宠物配置public Dictionary<int, PetXmlData> petXmlDataDict = new Dictionary<int, PetXmlData>();public static ConfigManager Instance{get{return mInstance;}}public int GetpetXmlDictCount()//获取长度{return petXmlDataDict.Count;}public PetXmlData GetPetXMLInfo(int DictOrder){return petXmlDataDict[DictOrder];}
}

四、XML数据配表:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Pets> <Pet  id="1"  name="蜗牛兽"         level="1"  hp="15"   attack="3"   catchcost="5"   worth="3"  probability="0.8"   headImage="1boluo"/><Pet  id="2"  name="小黄鸡"         level="1"  hp="9"    attack="5"   catchcost="5"   worth="3"  probability="0.8"   headImage="2xigua"/><Pet  id="3"  name="小乌贼"         level="1"  hp="11"   attack="5"   catchcost="5"   worth="3"  probability="0.8"   headImage="3kefu"/><Pet  id="4"  name="蓝蛇怪"         level="1"  hp="10"   attack="5"   catchcost="5"   worth="3"  probability="0.8"   headImage="4labbg"/><Pet  id="5"  name="小萝卜"         level="1"  hp="10"   attack="5"   catchcost="5"   worth="3"  probability="0.8"   headImage="5star"/><Pet  id="6"  name="宝箱怪"         level="1"  hp="10"  attack="1"   catchcost="5"   worth="3"  probability="0.8"   headImage="js2"/><Pet  id="7"  name="小苹果"         level="1"  hp="10"   attack="1"   catchcost="5"   worth="3"  probability="0.8"   headImage="jsk_00"/><Pet  id="8"  name="巴努兽"         level="1"  hp="10"   attack="4"   catchcost="5"   worth="3"  probability="0.8"   headImage="jump"/><Pet  id="9"   name="小章鱼"       level="2"  hp="20"   attack="8"    catchcost="20"   worth="8"  probability="0.7"   headImage="jxjt"/><Pet  id="10"  name="僵尸熊"       level="2"  hp="20"   attack="8"    catchcost="20"   worth="8"  probability="0.7"   headImage="kongdiandian"/><Pet  id="11"  name="小羊兽"       level="2"  hp="10"   attack="10"   catchcost="20"   worth="8"  probability="0.7"   headImage="lansebuffzhuagntai"/><Pet  id="12"  name="胡萝卜拳手"   level="2"  hp="15"   attack="9"    catchcost="20"   worth="8"  probability="0.7"   headImage="libao"/><Pet  id="13"  name="长牙怪"       level="2"  hp="30"   attack="3"    catchcost="20"   worth="8"  probability="0.7"   headImage="shengjituan"/><Pet  id="14"  name="千足蛙"       level="2"  hp="30"   attack="5"    catchcost="20"   worth="8"  probability="0.7"   headImage="shezhi"/><Pet  id="15"  name="混种蜗牛"     level="2"  hp="40"   attack="10"   catchcost="20"   worth="8"  probability="0.7"   headImage="shop"/><Pet  id="16"  name="卡布拉怪"     level="3"  hp="35"   attack="10"   catchcost="40"   worth="10"  probability="0.6"   headImage="skill_huoqiu"/><Pet  id="17"  name="洋葱头"       level="3"  hp="30"   attack="8"   catchcost="40"   worth="10"  probability="0.6"   headImage="skill_zhiliao"/><Pet  id="18"  name="香蕉侠"       level="3"  hp="45"   attack="15"   catchcost="40"   worth="10"  probability="0.6"   headImage="suo"/><Pet  id="19"  name="章鱼王"       level="3"  hp="50"   attack="10"   catchcost="40"   worth="10"  probability="0.6"   headImage="tequan"/><Pet  id="20"  name="派拉斯"       level="3"  hp="35"   attack="10"   catchcost="40"   worth="10"  probability="0.6"   headImage="tuichu"/><Pet  id="21"  name="胡萝卜船长"  level="4"  hp="65"   attack="30"   catchcost="60"   worth="12"  probability="0.5"   headImage="tx_01"/><Pet  id="22"  name="肥蜥蜴"      level="4"  hp="45"   attack="20"   catchcost="60"   worth="12"  probability="0.5"   headImage="tx_02"/><Pet  id="23"  name="紫茄兽"      level="4"  hp="55"   attack="15"   catchcost="60"   worth="12"  probability="0.5"   headImage="tx_03"/><Pet  id="24"  name="盲眼鸟"      level="4"  hp="50"   attack="25"   catchcost="60"   worth="12"  probability="0.5"   headImage="tx_04"/><Pet  id="25"  name="花椰菜"      level="4"  hp="75"   attack="20"   catchcost="60"   worth="12"  probability="0.5"   headImage="tx_05"/><Pet  id="26"  name="嘎啦"        level="4"  hp="55"   attack="25"   catchcost="60"   worth="12"  probability="0.5"   headImage="tx_06"/><Pet  id="27"  name="独眼布欧"    level="4"  hp="85"   attack="15"   catchcost="60"   worth="12"  probability="0.5"   headImage="tx_07"/><Pet  id="28"  name="臭臭泥"      level="5"  hp="115"   attack="24"   catchcost="80"   worth="15"  probability="0.4"   headImage="zuanshi"/><Pet  id="29"  name="香蕉先生"    level="5"  hp="75"    attack="35"   catchcost="80"   worth="15"  probability="0.4"   headImage="zuanshi-icon"/><Pet  id="30"  name="海王星"      level="5"  hp="90"    attack="30"   catchcost="80"   worth="15"  probability="0.4"   headImage="zuanshi-icon1"/><Pet  id="31"  name="羊头怪"      level="5"  hp="80"    attack="35"   catchcost="80"   worth="15"  probability="0.4"   headImage="zuanshi-icon2"/><Pet  id="32"  name="独眼恶魔"    level="5"  hp="85"    attack="30"   catchcost="80"   worth="15"  probability="0.4"   headImage="zuanshi-icon3"/><Pet  id="33"  name="图图犬"      level="5"  hp="115"   attack="25"   catchcost="80"   worth="15"  probability="0.4"   headImage="suger2"/><Pet  id="34"  name="哥达鸭"      level="5"  hp="75"    attack="40"   catchcost="80"   worth="15"  probability="0.4"   headImage="sailout"/><Pet  id="35"  name="铁甲蟹"      level="6"  hp="100"    attack="55"   catchcost="120"   worth="18"  probability="0.3"   headImage="skill_huoqiu"/><Pet  id="36"  name="镰刀盔"      level="6"  hp="125"    attack="65"   catchcost="120"   worth="18"  probability="0.3"   headImage="skill_huoqiu"/><Pet  id="37"  name="蓝皮鼠"      level="6"  hp="130"    attack="55"   catchcost="120"   worth="18"  probability="0.3"   headImage="skill_huoqiu"/><Pet  id="38"  name="兔宝宝"      level="6"  hp="125"    attack="55"   catchcost="120"   worth="18"  probability="0.3"   headImage="skill_huoqiu"/><Pet  id="39"  name="遁甲蜗牛"    level="6"  hp="145"    attack="45"   catchcost="120"   worth="18"  probability="0.3"   headImage="skill_huoqiu"/><Pet  id="40"  name="铁犀牛"      level="6"  hp="145"    attack="50"   catchcost="120"   worth="18"  probability="0.3"   headImage="skill_huoqiu"/><Pet  id="41"  name="眼魔"        level="7"  hp="110"    attack="65"   catchcost="150"   worth="25"  probability="0.2"   headImage="skill_huoqiu"/><Pet  id="42"  name="大嘴鳄鱼"    level="7"  hp="115"    attack="75"   catchcost="150"   worth="25"  probability="0.2"   headImage="skill_huoqiu"/><Pet  id="43"  name="蓝色魔鬼"    level="7"  hp="165"    attack="65"   catchcost="150"   worth="25"  probability="0.2"   headImage="skill_huoqiu"/><Pet  id="44"  name="僵尸兽"      level="7"  hp="180"    attack="90"   catchcost="150"   worth="25"  probability="0.2"   headImage="skill_huoqiu"/><Pet  id="45"  name="杯子猫"      level="7"  hp="145"    attack="80"   catchcost="150"   worth="25"  probability="0.2"   headImage="skill_huoqiu"/><Pet  id="46"  name="暴龙"        level="7"  hp="200"    attack="80"   catchcost="150"   worth="25"  probability="0.2"   headImage="skill_huoqiu"/><Pet  id="47"  name="兔米花"      level="8"  hp="200"    attack="160"   catchcost="200"   worth="40"  probability="0.1"   headImage="skill_huoqiu"/><Pet  id="48"  name="饼干人"      level="8"  hp="165"    attack="125"   catchcost="200"   worth="40"  probability="0.1"   headImage="skill_huoqiu"/><Pet  id="49"  name="糖果猫"      level="8"  hp="220"    attack="165"   catchcost="200"   worth="40"  probability="0.1"   headImage="skill_huoqiu"/><Pet  id="50"  name="宇宙大帝"    level="8"  hp="220"    attack="200"   catchcost="200"   worth="40"  probability="0.1"   headImage="1boluo"/></Pets>

五、结果显示:

unity物品图鉴(xml数据加载)相关推荐

  1. Unity导表工具Luban插件的数据加载原理与优化

    文章目录 1. 配置Luban并测试 2. Luban 数据加载原理 3. 根据工程进行懒加载优化 3.1 增加公共接口与接口实现方法 3.2 外部提供获取数据的方法 3.3 对Luban中的导表模板 ...

  2. Unity大场景数据加载及优化方案

    前段时间,有几个虚拟仿真公司跟我请教关于大地形的加载优化问题,它们使用的引擎都是自己研发的,引擎对于开发者来说,大同小异,它们的基本构造是一样的,关键是在于解决问题的方法,正是基于这个前提写了这个课程 ...

  3. Python之pandas数据加载、存储

    Python之pandas数据加载.存储 0. 输入与输出大致可分为三类: 0.1 读取文本文件和其他更好效的磁盘存储格式 2.2 使用数据库中的数据 0.3 利用Web API操作网络资源 1. 读 ...

  4. hive 导入hdfs数据_将数据加载或导入运行在基于HDFS的数据湖之上的Hive表中的另一种方法。

    hive 导入hdfs数据 Preceding pen down the article, might want to stretch out appreciation to all the well ...

  5. odoo基础数据加载

    odoo 基础数据加载 这里介绍的odoo基础数据加载分两种方式,一种是演示数据加载,一种是默认数据加载,下面就是详细介绍 首先,当然是创建一个date文件夹 项目目录,右键自定义一个文件夹 XML数 ...

  6. winform如何实现将数据库数据加载到树上

    一.简介 对于winform中如何加载xml生成目录树,在前边一篇文章"c#如何实现从xml中加载树目录,并且显示完整的Text"中我已经写了详细的过程.但是有些时候我们不可能将大 ...

  7. python实时数据存储与显示_利用python进行数据加载和存储

    1.文本文件 (1)pd.read_csv加载分隔符为逗号的数据:pd.read_table从文件.URL.文件型对象中加载带分隔符的数据.默认为制表符.(加载为DataFrame结构) 参数name ...

  8. 《利用Python进行数据分析·第2版》第6章 数据加载、存储与文件格式

    第1章 准备工作 第2章 Python语法基础,IPython和Jupyter 第3章 Python的数据结构.函数和文件 第4章 NumPy基础:数组和矢量计算 第5章 pandas入门 第6章 数 ...

  9. 数据加载中,请稍等......

    loading图片下载:loading 页面代码: <%@ page language="java"contentType="text/html; charset= ...

  10. android MVP连接服务器,Android之MVP模式实现登陆和网络数据加载

    MVP简介 相信你们对 MVC 都是比较熟悉了:M-Model-模型.V-View-视图.C-Controller-控制器,MVP做为MVC的演化版本,也是做为用户界面(用户层)的实现模式,那么相似的 ...

最新文章

  1. 【深度学习】利用一些API进行图像数据增广
  2. 【Android 逆向】Android 进程注入工具开发 ( SO 进程注入环境及 root 权限获取 | 进程注入时序分析 )
  3. php 获取企业号用户,微信企业号 获取用户信息(示例代码)
  4. Coursera公开课笔记: 斯坦福大学机器学习第七课“正则化(Regularization)”
  5. aop执行跳过某个方法_简谈前端开发中的AOP(一) -- 前端AOP的实现思路
  6. python爬取歌曲评论并进行数据可视化
  7. Wi-Fi Expert专业无线网测试软件
  8. ARMA模型的性质之ARMA模型
  9. iPhone 12 mini被质疑锁屏触摸不灵
  10. 浅谈帆软报表的权限授权,以便于二次开发
  11. SVN自动定时更新方法
  12. SQL SERVER2008 打开脚本总是报“未能完成操作,存储空间不足”
  13. ​基于强化学习的自动交易系统研究与发展综述
  14. 一个月爆肝一个基于SpringBoot的在线教育系统【源码开源】【建议收藏】
  15. python + opencv 中值滤波器、最大值滤波器和最小值滤波器
  16. 【JS】顶部悬浮及缓慢回到顶部
  17. Ladon8.9扫描器简明教程/用法例子
  18. 浏览器打开苏宁易购证书错误
  19. 美国波士顿大学计算机专业排名,2017年波士顿大学各专业最新排名榜单 美国名校排名!...
  20. 从「集装箱」思考Docker风潮

热门文章

  1. Mac截图很大很怎么变小?
  2. USYD悉尼大学INFO1110 详细作业解析Week3 all quizzes
  3. js每日一题(11)
  4. Mobento:能搜索视频中说过的话
  5. 2014年校园招聘IT公司工资列表
  6. 如何在“一周内”摸清一个行业
  7. leetcode简单之1076.项目员工II
  8. Problem B 1076 素数
  9. java小球挡板游戏_多线程的一个小球游戏,就是以前的那个Pong游戏
  10. 游戏Call技术-绑定主线程调用CALL技术(反游戏检测call)