private void LoadStampDirFileInfo() { if (m_selectedCategoryID != -99) { string directory = GaiaDirectories.GetStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID]; if (!Directory.Exists(directory)) { directory = GaiaDirectories.GetUserStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID]; } if (!Directory.Exists(directory)) { Debug.LogWarning("Could not find the selected subdirectory '" + m_categoryNames[m_selectedCategoryID] + "' neither in the Gaia Stamps or in the User Stamps folder when trying to browse stamps."); return; } var info = new DirectoryInfo(directory); if (info == null) { Debug.LogWarning("Could not access directory " + directory + " when trying to browse stamps."); return; } m_currentStampDirFileInfo = info.GetFiles(); } }
public void Init(ImageMask imageMask = null) { allBiomeController = (BiomeController[])Resources.FindObjectsOfTypeAll(typeof(BiomeController)); allStampers = (Stamper[])Resources.FindObjectsOfTypeAll(typeof(Stamper)); allSpawners = (Spawner[])Resources.FindObjectsOfTypeAll(typeof(Spawner)); m_categoryNames.Clear(); var info = new DirectoryInfo(GaiaDirectories.GetStampDirectory()); var fileInfo = info.GetDirectories(); foreach (DirectoryInfo dir in fileInfo) { m_categoryNames.Add(dir.Name); } //Do the same with the user stamp folder info = new DirectoryInfo(GaiaDirectories.GetUserStampDirectory()); fileInfo = info.GetDirectories(); foreach (DirectoryInfo dir in fileInfo) { m_categoryNames.Add(dir.Name); } m_categoryNames.Sort(); if (imageMask != null) { m_editedImageMask = imageMask; } //read & store the original texture guid if the user wants to cancel if ((m_editedImageMask != null && m_editedImageMask.ImageMaskTexture != null)) { string pathToImage = ""; if (m_editedImageMask != null) { pathToImage = AssetDatabase.GetAssetPath(m_editedImageMask.ImageMaskTexture); } //else //{ // pathToImage = AssetDatabase.GetAssetPath(m_editedStamperSettings.m_stamperInputImage); //} m_originalTextureGUID = AssetDatabase.AssetPathToGUID(pathToImage); m_previewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(pathToImage, typeof(Texture2D)); //Try to locate the selected image in the stamps directory if (pathToImage.Contains(GaiaDirectories.STAMP_DIRECTORY)) { string lastFolderName = Path.GetFileName(Path.GetDirectoryName(pathToImage)); m_selectedCategoryID = m_categoryNames.FindIndex(x => x == lastFolderName); LoadStampDirFileInfo(); int index = -1; foreach (var fi in m_currentStampDirFileInfo) { index++; if (pathToImage.Contains(fi.Name)) { m_currentStampIndex = index; } } } } else { m_originalTextureGUID = ""; } }
private bool PickNextStamp(int direction) { //try to load a stamp file from the next index int nextIndexCandidate = m_currentStampIndex + direction; if (m_currentStampDirFileInfo == null) { LoadStampDirFileInfo(); } //still null? abort! if (m_currentStampDirFileInfo == null) { return(false); } if (0 <= nextIndexCandidate && nextIndexCandidate < m_currentStampDirFileInfo.Length - 1) { try { //Try to load the next texture2D into the preview texture, whatever file it is. string assetPath = GaiaDirectories.GetStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID] + "/" + m_currentStampDirFileInfo[nextIndexCandidate].Name; m_previewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)); if (m_previewTexture == null) { //Not found? Try to load from the user stamps folder instead assetPath = GaiaDirectories.GetUserStampDirectory() + "/" + m_categoryNames[m_selectedCategoryID] + "/" + m_currentStampDirFileInfo[nextIndexCandidate].Name; m_previewTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)); } if (m_previewTexture == null) { //no exception, but no valid texture file either, let's try the next index then m_currentStampIndex = nextIndexCandidate; return(PickNextStamp(direction)); } else { m_currentStampIndex = nextIndexCandidate; if (m_editedImageMask != null) { m_editedImageMask.ImageMaskTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)); } //else //{ // m_editedStamperSettings.m_stamperInputImage = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)); //} UpdateToolsAndScene(); return(true); } } catch (Exception) { //there might be more valid files, let's try the next index then m_currentStampIndex = nextIndexCandidate; return(PickNextStamp(direction)); } } else { return(false); } }