游戏存储工具类
using UnityEngine; using System.Collections; using System.Xml; using System.Collections.Generic; using System.Reflection; using System; /// <summary> /// 游戏存储读取工具类 /// </summary> public class Record { /// <summary> /// 存档名称 /// </summary> public static string RecordName; /// <summary> /// 切换场景 /// </summary> public static void ChangeScene(Character player,string nextLevel,string index){ UILocation.locationID = index; SaveGame(player,"Temp"); PlayerPrefs.SetString("LevelName",nextLevel); Application.LoadLevel("Load"); } /// <summary> /// 存储信息(临时) /// </summary> public static void SaveGame(Character player){ SaveGame(player,"Temp"); } /// <summary> /// 存储信息(指定) /// </summary> public static void SaveGame(Character player, string index){ SaveRecord(player,index); //玩家数据存储 string data = "<?xml version='1.0' encoding='utf-8'?>"; data += "<Player>"; data += saveSystem(player); data += saveBaseInfo(player); data += saveItems(player); data += saveSkills(player); data += saveTask(player); data += saveAttendant(player); data += saveHotSkill(); data += "</Player>"; //获取文件路径 string filePath = "//Save//Record_" +index; Persistence.CreateXML(filePath,data); Debug.Log("Save :"+filePath); } /// <summary> /// 存档记录 /// </summary> public static void SaveRecord(Character player,string index){ //保存图片 CaptureScreen.SaveCapture(index); //存储XML XmlDocument xml = new XmlDocument(); string xmlPath = Application.dataPath + "//StreamingAssets//Xml//Persistence//Save//Record.xml"; xml.Load(xmlPath); string xmlStr = "<?xml version='1.0' encoding='utf-8'?>"; xmlStr += "<records>"; XmlNodeList records = xml.SelectSingleNode("records").ChildNodes; for(int i = 0; i < records.Count; i++){ xmlStr += "<record>"; XmlNodeList recordList = records.Item(i).ChildNodes; if(recordList.Item(0).InnerText == index){ DateTime date = System.DateTime.Now; string dateStr = date.Year+" / "+date.Month+" / "+date.Day; xmlStr += "<index>"+index+"</index>"; xmlStr += "<savePic>"+index+"</savePic>"; xmlStr += "<character>"+player.realname+"</character>"; xmlStr += "<date>"+dateStr+"</date>"; xmlStr += "<level>等 级 "+player.level+"</level>"; xmlStr += "<location>"+UILocation.LocationLabel.text+"</location>"; xmlStr += "<savenum>存 档 "+index+"</savenum>"; xmlStr += "<time>"+WeatherManager.GetGameTime()+"</time>"; }else{ xmlStr += "<index>"+recordList.Item(0).InnerText+"</index>"; xmlStr += "<savePic>"+recordList.Item(1).InnerText+"</savePic>"; xmlStr += "<character>"+recordList.Item(2).InnerText+"</character>"; xmlStr += "<date>"+recordList.Item(3).InnerText+"</date>"; xmlStr += "<level>"+recordList.Item(4).InnerText+"</level>"; xmlStr += "<location>"+recordList.Item(5).InnerText+"</location>"; xmlStr += "<savenum>"+recordList.Item(6).InnerText+"</savenum>"; xmlStr += "<time>"+recordList.Item(7).InnerText+"</time>"; } xmlStr += "</record>"; } xmlStr += "</records>"; Persistence.CreateXML("//Save//Record",xmlStr); } /// <summary> /// 读取存档记录 /// </summary> public static XmlNodeList LoadRecord(string index){ XmlNodeList list = null; XmlDocument xml = new XmlDocument(); string xmlPath = Application.dataPath + "//StreamingAssets//Xml//Persistence//Save//Record.xml"; xml.Load(xmlPath); XmlNodeList records = xml.SelectSingleNode("records").ChildNodes; for(int i = 0; i < records.Count; i++){ XmlNodeList recordList = records.Item(i).ChildNodes; if(recordList.Item(0).InnerText == index){ list = recordList; } } return list; } /// <summary> /// 用户读取信息(指定) /// </summary> public static void LoadGame(){ if(Record.RecordName == null) Record.RecordName = "Temp"; string index = Record.RecordName; Transform player = GameObject.FindGameObjectWithTag("Player").transform; //获取文件路径,解析XML,读取记录 XmlDocument xml = new XmlDocument(); string filePath = Application.dataPath + "//StreamingAssets//Xml//Persistence//Save//Record_"+index+".xml"; xml.Load(filePath); XmlNodeList PlayerInfo = xml.SelectSingleNode("Player").ChildNodes; //①加载系统信息 XmlNodeList systemInfo = PlayerInfo.Item(0).ChildNodes; loadSystem(systemInfo); //②初始化起始位置 string locationID = UILocation.locationID; if(locationID != null){ GameObject location = GameObject.Find(locationID); if(location != null){ player.position = location.transform.position; } } //③加载角色基本信息 XmlNodeList baseInfo = PlayerInfo.Item(1).ChildNodes; string characterName = getCharacterName(baseInfo); //④实例化模型对象,设置层级关系 GameObject prefab = ResourceManager.GetCharacterObj(characterName); GameObject character = GameObject.Instantiate(prefab,player.position,player.rotation) as GameObject; character.transform.parent = player; //⑤添加角色信息组件 Character ct = player.gameObject.AddComponent(characterName) as Character; loadBaseInfo(baseInfo,ct); ct.mapIconType = MapIconType.Player; //⑥加载其他信息,如道具、技能、任务、同伴、快捷键 if(PlayerInfo.Count > 2){ loadItems(PlayerInfo.Item(2).ChildNodes,ct); loadSkills(PlayerInfo.Item(3).ChildNodes,ct); loadTask(PlayerInfo.Item(4).ChildNodes,ct); loadAttendant(PlayerInfo.Item(5).ChildNodes,ct); loadHotSkill(PlayerInfo.Item(6).ChildNodes,ct); } //⑦添加控制器组件 player.gameObject.AddComponent<PlayControl>(); //⑧添加人物预览 GameObject characterModel = GameObject.Find("CharacterModel") as GameObject; GameObject model = GameObject.Instantiate(prefab) as GameObject; model.transform.parent = characterModel.transform; model.transform.localPosition = new Vector3(0f,0f,0f); model.transform.rotation = new Quaternion(0f,-180f,0f,0f); Vector3 scale = Vector3.zero; switch(ct.name){ case "Paladin": scale = new Vector3(210f,150f,210f); break; case "Berserker": scale = new Vector3(180f,120f,180f); break; } model.transform.localScale = scale; model.name = "model"; setLayer(model.transform,characterModel.layer); Debug.Log("Load :"+filePath); } /// <summary> /// 设置层为NGUI /// </summary> static void setLayer(Transform model,int layer){ foreach(Transform t in model.transform){ t.gameObject.layer = layer; setLayer(t,layer); } } /// <summary> /// 获取记录的角色类型 /// </summary> static string getCharacterName(XmlNodeList list){ return list.Item(1).InnerText; } /// <summary> /// 获取地图信息 /// </summary> public static string getLevelName(string index){ //获取文件路径,解析XML,读取记录 XmlDocument xml = new XmlDocument(); string filePath = Application.dataPath + "//StreamingAssets//Xml//Persistence//Save//Record_"+index+".xml"; xml.Load(filePath); XmlNodeList systemInfo = xml.SelectSingleNode("Player").ChildNodes.Item(0).ChildNodes; return systemInfo.Item(1).InnerText; } /// <summary> /// 保存系统信息 /// </summary> static string saveSystem(Character ct){ string xml = ""; xml += "<system>"; xml += "<worldTime>"+WeatherManager.WorldTime+"</worldTime>"; xml += "<levelName>"+Application.loadedLevelName+"</levelName>"; xml += "<locationID>"+UILocation.locationID+"</locationID>"; xml += "</system>"; return xml; } /// <summary> /// 加载系统信息 /// </summary> static void loadSystem(XmlNodeList list){ WeatherManager.WorldTime = float.Parse(list.Item(0).InnerText); string id = list.Item(2).InnerText; UILocation.locationID = id; } /// <summary> /// 保存角色基本信息 /// </summary> static string saveBaseInfo(Character ct){ string baseInfo = ""; baseInfo += "<baseInfo>"; #region 角色信息 baseInfo += "<id>"+ct.id+"</id>"; baseInfo += "<name>"+ct.name+"</name>"; baseInfo += "<realname>"+ct.realname+"</realname>"; baseInfo += "<teamType>"+(int)ct.teamType+"</teamType>"; baseInfo += "<occupation>"+(int)ct.occupation+"</occupation>"; baseInfo += "<portrait>"+ct.portrait+"</portrait>"; baseInfo += "<introduction>"+ct.introduction+"</introduction>"; baseInfo += "<fightGrade>"+(int)ct.fightGrade+"</fightGrade>"; #endregion #region 基础属性 baseInfo += "<level>"+ct.level+"</level>"; baseInfo += "<exp>"+ct.exp+"</exp>"; baseInfo += "<point>"+ct.point+"</point>"; baseInfo += "<skillPoint>"+ct.skillPoint+"</skillPoint>"; baseInfo += "<power>"+ct.power+"</power>"; baseInfo += "<strength>"+ct.strength+"</strength>"; baseInfo += "<intelligence>"+ct.intelligence+"</intelligence>"; baseInfo += "<dexterity>"+ct.dexterity+"</dexterity>"; baseInfo += "<health_max>"+ct.health_max+"</health_max>"; baseInfo += "<health_cur>"+ct.health_cur+"</health_cur>"; baseInfo += "<health_restore>"+ct.health_restore+"</health_restore>"; baseInfo += "<magic_max>"+ct.magic_max+"</magic_max>"; baseInfo += "<magic_cur>"+ct.magic_cur+"</magic_cur>"; baseInfo += "<magic_restore>"+ct.magic_restore+"</magic_restore>"; baseInfo += "<damage_max>"+ct.damage_max+"</damage_max>"; baseInfo += "<damage_min>"+ct.damage_min+"</damage_min>"; baseInfo += "<defence>"+ct.defence+"</defence>"; baseInfo += "<magic_power>"+ct.magic_power+"</magic_power>"; baseInfo += "<magic_resist>"+ct.magic_resist+"</magic_resist>"; baseInfo += "<crit>"+ct.crit+"</crit>"; baseInfo += "<crit_damage>"+ct.crit_damage+"</crit_damage>"; baseInfo += "<speed>"+ct.speed+"</speed>"; baseInfo += "<attackSpeed>"+ct.attackSpeed+"</attackSpeed>"; baseInfo += "<maxAttackDistance>"+ct.maxAttackDistance+"</maxAttackDistance>"; baseInfo += "<rotationSpeed>"+ct.rotationSpeed+"</rotationSpeed>"; baseInfo += "<resist_fire>"+ct.resist_fire+"</resist_fire>"; baseInfo += "<resist_forzen>"+ct.resist_forzen+"</resist_forzen>"; baseInfo += "<resist_lighting>"+ct.resist_lighting+"</resist_lighting>"; baseInfo += "<resist_poison>"+ct.resist_poison+"</resist_poison>"; baseInfo += "<resist_holy>"+ct.resist_holy+"</resist_holy>"; baseInfo += "<resist_dark>"+ct.resist_dark+"</resist_dark>"; baseInfo += "<leadership>"+ct.leadership+"</leadership>"; baseInfo += "<requiredLeadership>"+ct.requiredLeadership+"</requiredLeadership>"; #endregion #region 升级成长率 baseInfo += "<power_up>"+(int)ct.power_up+"</power_up>"; baseInfo += "<strength_up>"+(int)ct.strength_up+"</strength_up>"; baseInfo += "<intelligence_up>"+(int)ct.intelligence_up+"</intelligence_up>"; baseInfo += "<dexterity_up>"+(int)ct.dexterity_up+"</dexterity_up>"; baseInfo += "<baseExp>"+ct.baseExp+"</baseExp>"; #endregion #region 辅助信息 baseInfo += "<isLive>"+ct.isLive+"</isLive>"; baseInfo += "<isInit>"+ct.isInit+"</isInit>"; #endregion baseInfo += "</baseInfo>"; return baseInfo; } /// <summary> /// 加载角色基本信息 /// </summary> static void loadBaseInfo(XmlNodeList list,Character ct){ #region 角色信息 ct.id = list.Item(0).InnerText; ct.name = list.Item(1).InnerText; ct.realname = list.Item(2).InnerText; ct.teamType = (TeamType)int.Parse(list.Item(3).InnerText); ct.occupation = (Occupation)int.Parse(list.Item(4).InnerText); ct.portrait = list.Item(5).InnerText; ct.introduction = list.Item(6).InnerText; ct.fightGrade = (FightGrade)int.Parse(list.Item(7).InnerText); #endregion #region 基础属性 ct.level = int.Parse(list.Item(8).InnerText); ct.exp = int.Parse(list.Item(9).InnerText); ct.point = int.Parse(list.Item(10).InnerText); ct.skillPoint = int.Parse(list.Item(11).InnerText); ct.power = float.Parse(list.Item(12).InnerText); ct.strength = float.Parse(list.Item(13).InnerText); ct.intelligence = float.Parse(list.Item(14).InnerText); ct.dexterity = float.Parse(list.Item(15).InnerText); ct.health_max = float.Parse(list.Item(16).InnerText); ct.health_cur = float.Parse(list.Item(17).InnerText); ct.health_restore = float.Parse(list.Item(18).InnerText); ct.magic_max = float.Parse(list.Item(19).InnerText); ct.magic_cur = float.Parse(list.Item(20).InnerText); ct.magic_restore = float.Parse(list.Item(21).InnerText); ct.damage_max = float.Parse(list.Item(22).InnerText); ct.damage_min = float.Parse(list.Item(23).InnerText); ct.defence = float.Parse(list.Item(24).InnerText); ct.magic_power = float.Parse(list.Item(25).InnerText); ct.magic_resist = float.Parse(list.Item(26).InnerText); ct.crit = float.Parse(list.Item(27).InnerText); ct.crit_damage = float.Parse(list.Item(28).InnerText); ct.speed = float.Parse(list.Item(29).InnerText); ct.attackSpeed = float.Parse(list.Item(30).InnerText); ct.maxAttackDistance = float.Parse(list.Item(31).InnerText); ct.rotationSpeed = float.Parse(list.Item(32).InnerText); ct.resist_fire = int.Parse(list.Item(33).InnerText); ct.resist_forzen = int.Parse(list.Item(34).InnerText); ct.resist_lighting = int.Parse(list.Item(35).InnerText); ct.resist_poison = int.Parse(list.Item(36).InnerText); ct.resist_holy = int.Parse(list.Item(37).InnerText); ct.resist_dark = int.Parse(list.Item(38).InnerText); ct.leadership = int.Parse(list.Item(39).InnerText); ct.requiredLeadership = int.Parse(list.Item(40).InnerText); #endregion #region 升级成长率 ct.power_up = (GrowthGrade)int.Parse(list.Item(41).InnerText); ct.strength_up = (GrowthGrade)int.Parse(list.Item(42).InnerText); ct.intelligence_up = (GrowthGrade)int.Parse(list.Item(43).InnerText); ct.dexterity_up = (GrowthGrade)int.Parse(list.Item(44).InnerText); ct.baseExp = int.Parse(list.Item(45).InnerText); #endregion #region 辅助信息 ct.isLive = bool.Parse(list.Item(46).InnerText); ct.isInit = bool.Parse(list.Item(47).InnerText); #endregion } /// <summary> /// 保存道具信息 /// </summary> static string saveItems(Character ct){ string itemsXML = ""; ItemManager itemManager = ct.itemManager; if(itemManager != null){ itemsXML += "<items>"; itemsXML += "<money>"+itemManager.Money+"</money>"; itemsXML += "<itemCount>"+itemManager.items.Length+"</itemCount>"; itemsXML += "<equipCount>"+itemManager.equipments.Length+"</equipCount>"; //保存道具信息 Item[] items = itemManager.items; itemsXML += "<list>"; for(int i = 0; i < items.Length; i++){ Item item = items[i]; if(item != null){ itemsXML += "<item>"; itemsXML += "<index>"+i+"</index>"; itemsXML += "<name>"+item.spriteName+"</name>"; itemsXML += "<count>"+item.count+"</count>"; itemsXML += "</item>"; } } itemsXML += "</list>"; //保存装备信息 itemsXML += "<equipments>"; Equipment[] equips = itemManager.equipments; for(int i = 0; i < equips.Length; i++){ Equipment equip = equips[i]; if(equip != null){ itemsXML += "<equip>"; itemsXML += "<index>"+i+"</index>"; itemsXML += "<name>"+equip.spriteName+"</name>"; itemsXML += "</equip>"; } } itemsXML += "</equipments>"; itemsXML += "</items>"; } return itemsXML; } /// <summary> /// 加载道具信息 /// </summary> static void loadItems(XmlNodeList list,Character ct){ if(list == null) return; int money = int.Parse(list.Item(0).InnerText); int itemCount = int.Parse(list.Item(1).InnerText); int equipCount = int.Parse(list.Item(2).InnerText); //初始化道具管理器 GameObject targetObj = ct.gameObject; ItemManager itemManager = targetObj.AddComponent<ItemManager>(); ct.itemManager = itemManager; itemManager.Money = money; Item[] items = new Item[itemCount]; Equipment[] equipments = new Equipment[equipCount]; itemManager.items = items; itemManager.equipments = equipments; //加载道具信息 XmlNodeList itemsList = list.Item(3).ChildNodes; for(int i = 0; i < itemsList.Count; i++){ XmlNodeList itemList = itemsList.Item(i).ChildNodes; int index = int.Parse(itemList.Item(0).InnerText); string name = itemList.Item(1).InnerText; int count = int.Parse(itemList.Item(2).InnerText); Item item = targetObj.AddComponent(name) as Item; item.init(); item.count = count; items[index] = item; } //加载装备信息 XmlNodeList equipmentsList = list.Item(4).ChildNodes; for(int i = 0; i < equipmentsList.Count; i++){ XmlNodeList equipList = equipmentsList.Item(i).ChildNodes; int index = int.Parse(equipList.Item(0).InnerText); string name = equipList.Item(1).InnerText; Equipment equip = targetObj.AddComponent(name) as Equipment; equipments[index] = equip; } } /// <summary> /// 保存技能信息 /// </summary> static string saveSkills(Character ct){ string xml = ""; SkillManager skillManager = ct.skillManager; if(skillManager != null){ xml += "<skills>"; Skill[][] skillTrees = skillManager.skills; xml += "<treesCount>"+skillTrees.Length+"</treesCount>"; xml += "<skillsCount>"+skillTrees[0].Length+"</skillsCount>"; xml += "<list>"; for(int i = 0; i < skillTrees.Length; i++){ Skill[] tree = skillTrees[i]; for(int j = 0; j < tree.Length; j++){ Skill skill = tree[j]; if(skill != null){ xml += "<skill>"; xml += "<tree>"+i+"</tree>"; xml += "<index>"+j+"</index>"; xml += "<name>"+skill.spriteName+"</name>"; xml += "<level>"+skill.level+"</level>"; xml += "</skill>"; } } } xml += "</list>"; xml += "</skills>"; } return xml; } /// <summary> /// 加载技能信息 /// </summary> static void loadSkills(XmlNodeList list,Character ct){ if(list == null) return; int treesCount = int.Parse(list.Item(0).InnerText); int skillsCount = int.Parse(list.Item(1).InnerText); GameObject targetObj = ct.gameObject; SkillManager skillManager = targetObj.AddComponent<SkillManager>(); //初始化技能树 Skill[][] skills = new Skill[treesCount][]; for(int i = 0; i < treesCount; i++){ skills[i] = new Skill[skillsCount]; } skillManager.skills = skills; skillManager.isInit = true; ct.skillManager = skillManager; //加载技能信息 XmlNodeList skillsList = list.Item(2).ChildNodes; for(int i = 0; i < skillsList.Count; i++){ XmlNodeList skillList = skillsList.Item(i).ChildNodes; int tree = int.Parse(skillList.Item(0).InnerText); int index = int.Parse(skillList.Item(1).InnerText); string skillName = skillList.Item(2).InnerText; int level = int.Parse(skillList.Item(3).InnerText); Skill skill = targetObj.AddComponent(skillName) as Skill; skill.init(ct.gameObject); skill.setLevel(level); skills[tree][index] = skill; } } /// <summary> /// 保存任务信息 /// </summary> static string saveTask(Character ct){ string xml = ""; Task[] tasks = TaskManager.tasks; if(tasks != null){ xml += "<tasks>"; xml += "<taskCount>"+tasks.Length+"</taskCount>"; xml += "<list>"; for(int i = 0; i < tasks.Length; i++){ Task task = tasks[i]; if(task != null){ xml += "<task>"; xml += "<index>"+i+"</index>"; xml += "<ID>"+task.ID+"</ID>"; xml += "<complete>"+task.complete+"</complete>"; //记录杀敌个数 if(task is Fight){ Fight fight = (Fight)task; xml += "<count>"+fight.count+"</count>"; } xml += "</task>"; } } xml += "</list>"; xml += "</tasks>"; } return xml; } /// <summary> /// 加载任务信息 /// </summary> static void loadTask(XmlNodeList list,Character ct){ if(list == null) return; TaskManager taskManager = ct.gameObject.AddComponent<TaskManager>(); int taskCount = int.Parse(list.Item(0).InnerText); Task[] tasks = new Task[taskCount]; TaskManager.tasks = tasks; ct.taskManager = taskManager; XmlNodeList tasksList = list.Item(1).ChildNodes; for(int i = 0; i < tasksList.Count; i++){ XmlNodeList taskList = tasksList.Item(i).ChildNodes; int index = int.Parse(taskList.Item(0).InnerText); string ID = taskList.Item(1).InnerText; bool complete = bool.Parse(taskList.Item(2).InnerText); Task task = TaskManager.LoadTask(ID); task.complete = complete; if(task is Fight){ Fight fight = (Fight)task; fight.count = int.Parse(taskList.Item(3).InnerText); } tasks[index] = task; } TaskManager.isInit = true; } /// <summary> /// 保存同伴信息 /// </summary> static string saveAttendant(Character ct){ string xml = ""; if(ct.attendantManager != null){ List<Attendant> attendants = ct.attendantManager.attendants; if(attendants != null && attendants.Count > 0){ xml += "<attendants>"; for(int i = 0; i < attendants.Count; i++){ Attendant attendant = attendants[i]; Character ctt = attendant.character; xml += "<attendant>"; xml += "<isFight>"+attendant.isFight+"</isFight>"; xml += saveBaseInfo(ctt); xml += "</attendant>"; } xml += "</attendants>"; } } return xml; } /// <summary> /// 加载同伴信息 /// </summary> static void loadAttendant(XmlNodeList list,Character ct){ if(list == null) return; AttendantManager attendantManager = ct.gameObject.AddComponent<AttendantManager>(); ct.attendantManager = attendantManager; attendantManager.attendants = new List<Attendant>(); ct.attendantManager = attendantManager; for(int i = 0; i < list.Count; i++){ XmlNodeList attList = list.Item(i).ChildNodes; bool isFight = bool.Parse(attList.Item(0).InnerText); XmlNodeList baseInfo = attList.Item(1).ChildNodes; //反射动态生成角色对象 string characterName = getCharacterName(baseInfo); Character character = Assembly.Load("Assembly-CSharp").CreateInstance(characterName) as Character; loadBaseInfo(baseInfo,character); //初始化同伴信息 Attendant att = new Attendant(character); att.isFight = isFight; attendantManager.attendants.Add(att); } AttendantManager.isInit = true; } /// <summary> /// 保存快捷键设置 /// </summary> static string saveHotSkill(){ string xml = ""; UISkill UISkill = GameObject.Find("MainUI").GetComponent<UISkill>(); if(UISkill != null){ xml += "<hotskills>"; Transform[] hotSkills = UISkill.hotSkills; for(int i = 0; i < hotSkills.Length; i++){ Transform hotSkill = hotSkills[i]; string spriteName = hotSkill.Find("skill").GetComponent<UISprite>().spriteName; int skillID = (int)hotSkill.Find("id").localPosition.x; xml += "<hotskill>"; xml += "<index>"+hotSkill.name+"</index>"; xml += "<spriteName>"+spriteName+"</spriteName>"; xml += "<skillID>"+skillID+"</skillID>"; xml += "</hotskill>"; } xml += "</hotskills>"; } return xml; } /// <summary> /// 加载快捷键设置 /// </summary> static void loadHotSkill(XmlNodeList list,Character ct){ if(list == null) return; GameObject hotSkills = GameObject.Find("MainUI/Camera/Skill"); for(int i = 0; i < list.Count; i++){ XmlNodeList hotSkill = list.Item(i).ChildNodes; string indexName = hotSkill.Item(0).InnerText; string spriteName = hotSkill.Item(1).InnerText; float id = float.Parse(hotSkill.Item(2).InnerText); hotSkills.transform.Find(indexName+"/skill").GetComponent<UISprite>().spriteName = spriteName; hotSkills.transform.Find(indexName+"/id").localPosition = new Vector3(id,0f,0f); } } }