public GameObject GetAsset(Type GameObjectType, String AssetName) { if (AssetName == null) { AssetName = "!Default"; } GameObject Asset = GetAssetFromCache(GameObjectType, AssetName); if (Asset == null) { String PathToAsset = m_DataAssetTree.GetPathToAsset(GameObjectType.Name, AssetName); if (PathToAsset == null) { if (AssetName == "!Default") { // we are trying to load the default item and we don't have one yet. ConstructorInfo constructInfo = GameObjectType.GetConstructor(Type.EmptyTypes); if (constructInfo == null) { throw new System.Exception("You must have a default constructor defined for '" + GameObjectType.Name + "' for default game object creation to work."); } GameObject defaultGameObjectItem = (GameObject)constructInfo.Invoke(null); String DefaultAssetPath = m_DataAssetTree.Root + Path.DirectorySeparatorChar + "Default"; if (!Directory.Exists(DefaultAssetPath)) { Directory.CreateDirectory(DefaultAssetPath); } String PathName = DefaultAssetPath + Path.DirectorySeparatorChar + AssetName + "." + GameObjectType.Name; defaultGameObjectItem.SaveXML(PathName); AddAssetToCache(GameObjectType, AssetName, defaultGameObjectItem); return(defaultGameObjectItem); } else { throw new System.Exception("'" + GameObjectType.Name + "' named '" + AssetName + "' does not exist."); } } GameObject gameObjectItem = LoadGameObjectFromDisk(GameObjectType, AssetName, PathToAsset); AddAssetToCache(GameObjectType, AssetName, gameObjectItem); return(gameObjectItem); } return(Asset); }
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); } }
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); } }
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); } }