关于资源版本管理的问题
2012-07-16 10:35
344 查看
unity3d 提供了比读取txt,xml更好用的ScriptableObject(脚本对象化)。为了方便于版本管理,一般会添加一个版本号(guid)
LevelPortalRelationShipBatchProcess.cs
然后把创建出来的,已经带有数据的*.assets文件直接打包成*.unity3d文件。
客户端可以直接读取*.unity3d文件,获取到数据
public class ScriptObjectCOS : ScriptableObject { public string guid = ""; } public class LevelPortalRefTable : ScriptObjectCOS { public List<LevelPortalRef> levelPortalRefList = new List<LevelPortalRef>(); } //每个关卡的portral [System.Serializable] public class LevelPortalRef { public int levelID; public string levelName = string.Empty; public List<PortalInstance> PortalInstanceList = new List<PortalInstance>(); //< 1.portalID, 2.PortalInstance> private Dictionary<int, PortalInstance> cacheLevelPortalRefTable = new Dictionary<int, PortalInstance>(); //缓存所有PortalInstance public static void PopulatePortalInstanceTable(LevelPortalRef _ref) { if (_ref == null) { return; } foreach (PortalInstance _portal in _ref.PortalInstanceList) { if (!_ref.cacheLevelPortalRefTable.ContainsKey(_portal.portalID)) { _ref.cacheLevelPortalRefTable.Add(_portal.portalID, _portal); } else { Debug.LogError("PortalInstance repeat: " + _ref.levelID + " " + _portal.portalID); } } } //根据portalID获取PortalInstance public PortalInstance GetPortalInstanceData(int _portalID) { if (cacheLevelPortalRefTable.ContainsKey(_portalID)) { return cacheLevelPortalRefTable[_portalID]; } return null; } } [System.Serializable] public class PortalInstance { public int portalID; public int x; public float y; public int z; public int soloDestinationPortalID;//目标关卡的portal public string soloDestinationLevelName = string.Empty;//目标关卡名字 public int soloDestinationLevelID;//目标关卡ID }
LevelPortalRelationShipBatchProcess.cs
using UnityEngine; using System.Collections; using System.IO; using System.Text; using System.Collections.Generic; //using Aspose.Cells; using System; using UnityEditor; using System.Xml; public class LevelPortalRelationShipBatchProcess : ScriptableWizard { private static string filePath = "MyAssets/LevelPortalRelationShipData.asset"; static string path = @"d:\MySavedLevels\LevelMap\"; public static String[] filePaths; private static Dictionary<int, LevelPortalRef> levelPortalRefTable = new Dictionary<int, LevelPortalRef>(); [MenuItem("Example/Portal/LevelPortalRelationShipBatchProcess")] static void CreatePortalRelationShipData() { filePath = "MyAssets/LevelPortalRelationShipData.asset"; string _guid = Guid.NewGuid().ToString(); BuiltToScriptTableObject(_guid); WriteToXML(_guid); Debug.Log(" CreatePortalRelationShipData Done"); } private static void BuiltToScriptTableObject(string _guid) { //先创建一个空的.asset LevelPortalRefTable _newTable = GenericAssetUtility<LevelPortalRefTable>.Create(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); _newTable.guid = _guid; //获取数据 if (Directory.Exists(path)) { filePaths = Directory.GetFiles(path, "*.xml"); } foreach (string _filePath in filePaths) { Debug.LogWarning("################ url: " + _filePath); ReadMapXML(_filePath); } //Debug.Log("################ BuiltToScriptTableObject() " + levelPortalRefTable.Count); foreach (LevelPortalRef _protalRef in levelPortalRefTable.Values) { LevelPortalRef levelPortalRef = new LevelPortalRef(); levelPortalRef.levelID = _protalRef.levelID; levelPortalRef.levelName = _protalRef.levelName; levelPortalRef.dungeonID = _protalRef.dungeonID; foreach (PortalInstance _portal in _protalRef.PortalInstanceList) { PortalInstance portalData = new PortalInstance(); portalData.portalID = _portal.portalID; Debug.Log(" PortalID: " + portalData.portalID); portalData.x = _portal.x; portalData.y = _portal.y; portalData.z = _portal.z; portalData.soloDestinationPortalID = _portal.soloDestinationPortalID; portalData.soloDestinationLevelID = _portal.soloDestinationLevelID; portalData.soloDestinationLevelName = _portal.soloDestinationLevelName; levelPortalRef.PortalInstanceList.Add(portalData); } _newTable.levelPortalRefList.Add(levelPortalRef); } } static void ReadMapXML(string _filePath) { try { XmlDocument _doc = new XmlDocument(); _doc.Load(_filePath); XmlElement _root = _doc.DocumentElement; if (_root.Name.ToUpper().Equals("LEVEL") || _root.Name.ToUpper().Equals("OPENLEVEL")) { LevelPortalRef _levelPortalRef = new LevelPortalRef();//每个关卡 XmlNodeList elemList = _root.ChildNodes; foreach (XmlNode xmlNode in elemList) { if (xmlNode != null) { #region every Level string _tagName = xmlNode.Name.ToUpper(); switch (_tagName) { case "ID": _levelPortalRef.levelID = Convert.ToInt32(xmlNode.InnerXml); break; case "Name": _levelPortalRef.levelName = xmlNode.InnerXml; break; case "DEMGUON": _levelPortalRef.dungeonID = Convert.ToInt32(xmlNode.InnerXml); break; case "PORTALS": XmlNodeList _portalList = xmlNode.ChildNodes; foreach (XmlNode _portalNode in _portalList) { PortalInstance _portalInstance = new PortalInstance(); if (_portalNode.Name.ToUpper().Equals("PORTAL") && _portalNode != null) { #region every portal XmlNodeList _nodesList = _portalNode.ChildNodes; foreach (XmlNode _portalElement in _nodesList) { string _elementName = _portalElement.Name.ToUpper(); if (!string.IsNullOrEmpty(_portalElement.InnerXml)) { switch (_elementName) { case "ID": //Debug.Log(_elementName + " " + _portalElement.InnerXml); _portalInstance.portalID = Convert.ToInt32(_portalElement.InnerXml); break; case "X": _portalInstance.x = (int)Convert.ToSingle(_portalElement.InnerXml); break; case "Y": _portalInstance.y = Convert.ToSingle(_portalElement.InnerXml); break; case "Z": _portalInstance.z = (int)Convert.ToSingle(_portalElement.InnerXml); break; /////////////////////////因为要兼容旧的格式///////// case "DESTINATIONPORTALID": _portalInstance.soloDestinationPortalID = Convert.ToInt32(_portalElement.InnerXml); break; case "DESTINATIONLEVELNAME": _portalInstance.soloDestinationLevelName = _portalElement.InnerXml; break; case "DESTINATIONLEVELID": _portalInstance.soloDestinationLevelID = Convert.ToInt32(_portalElement.InnerXml); break; /////////////////////////////////////////////////// /////////////////////////新的格式////////////////// case "SoloDestination": foreach (XmlNode solodes in _portalElement) { string _soldesName = solodes.Name.ToUpper(); switch (_soldesName) { case "SOLODESTINATIONPORTALID": _portalInstance.soloDestinationPortalID = Convert.ToInt32(solodes.InnerXml); break; case "SOLODESTINATIONLEVELNAME": _portalInstance.soloDestinationLevelName = solodes.InnerXml; break; case "SOLODESTINATIONLEVELID": _portalInstance.soloDestinationLevelID = Convert.ToInt32(solodes.InnerXml); break; } } break; /////////////////////////////////////////////////// default: break; } } } #endregion } _levelPortalRef.PortalInstanceList.Add(_portalInstance); } break; default: break; } #endregion } } levelPortalRefTable[_levelPortalRef.levelID] = _levelPortalRef; } } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } } private static void WriteToXML(string _guid) { } }
然后把创建出来的,已经带有数据的*.assets文件直接打包成*.unity3d文件。
客户端可以直接读取*.unity3d文件,获取到数据
相关文章推荐
- 国务院关于做好省级以下国土资源管理体制改革有关问题的通知-国发(2004)12号
- 前端资源多个产品整站一键打包&包版本管理(四)—— js&css文件文件打包并生成哈希后缀,自动写入路径、解决资源缓存问题。
- 关于svn版本管理ignore文件不起作用的问题
- 关于Android6.0(23以上)版本权限管理的问题
- 关于获取info.plist文件的属性和获取资源管理xcassets里的启动图片的问题
- 关于Unity中的资源管理,你可能遇到这些问题
- 关于项目管理的七十五个问题的答案之MVM版本(转载)
- SVN 多人修改,如何管理 关于版本的问题
- 关于Unity中的资源管理,你可能遇到这些问题
- 关于maven包管理版本冲突的问题
- 关于VMware虚拟机的上网问题[Workstation版本]
- 关于ruby使用gem安装资源包失败问题。
- 关于extJS3.2版本中设置datefield控件和combo控件等只读的问题
- 关于niosii不同版本的ip核不兼容的问题
- 关于财易酒店管理系统折扣问题详解
- 关于MappedByteBuffer资源释放问题
- 关于在一套复制环境中使用不同版本OGG的问题.
- 关于Thiankphp3.2与PHP版本之间的问题
- 关于C#学籍管理项目控制台的问题
- 关于JDK版本的问题