public void ModifyOrCreateAsset(GameObject AssetToSave, string DesiredPathHint, string AssetName) { if (AssetExists(AssetToSave.GetType(), AssetName)) { // re-save it String PathToAsset = m_DataAssetTree.GetPathToAsset(AssetToSave.GetType().Name, AssetName); AssetToSave.SaveXML(PathToAsset); } else { // create the file and save the asset String DesiredAssetPath = m_DataAssetTree.Root + Path.DirectorySeparatorChar + DesiredPathHint; if (!Directory.Exists(DesiredAssetPath)) { Directory.CreateDirectory(DesiredAssetPath); } String PathName = DesiredAssetPath + Path.DirectorySeparatorChar + AssetName + "." + AssetToSave.GetType().Name; AssetToSave.SaveXML(PathName); AddAssetToCache(AssetToSave.GetType(), AssetName, AssetToSave); m_DataAssetTree.AddItemToTree(PathName); } }
private void AddAssetToCache(Type GameObjectType, String AssetName, GameObject Asset) { Dictionary<string, GameObject> gameObjectClassDictionary; if (!m_AssetCache.TryGetValue(GameObjectType, out gameObjectClassDictionary)) { // create the dictionary gameObjectClassDictionary = new Dictionary<string, GameObject>(); m_AssetCache.Add(GameObjectType, gameObjectClassDictionary); } GameObject itemInCach; if (gameObjectClassDictionary.TryGetValue(AssetName, out itemInCach)) { throw new System.Exception("The '" + GameObjectType.Name + "' asset named '" + AssetName + "' is already in the cache."); } gameObjectClassDictionary.Add(AssetName, Asset); }