private static void CheckForCollisions(List <string> generatedAtlases)
        {
            var fixedGeneratedAtlases = generatedAtlases
                                        .Select(path => path.FixUnityPath())
                                        .ToList();

            var existingAtlases = Directory
                                  .GetFiles(Application.dataPath, spriteAtlasExtension, SearchOption.AllDirectories)
                                  .Select(path => EditorFileUtils.ToProjectPath(path))
                                  .Except(fixedGeneratedAtlases)
                                  .ToList();

            var existingNames = existingAtlases
                                .Select(path => Path.GetFileName(path))
                                .ToList();

            var generatedNames = generatedAtlases
                                 .Select(path => Path.GetFileName(path))
                                 .ToList();

            foreach (var collision in existingNames.Intersect(generatedNames))
            {
                Debug.LogError($"[{nameof(RuleChangeHandler)}] Generated atlas was assigned the name that's already taken: {collision}");
            }
        }
 public static void RemoveStreamingCache()
 {
     try {
         var targetPath = Application.streamingAssetsPath + StreamingAddressablesPath;
         EditorFileUtils.DeleteDirectory(targetPath);
     }
     catch (Exception e) {
         Debug.LogError(e);
     }
 }
        public static void RemoveLibraryCache()
        {
            try {
                EditorFileUtils.DeleteDirectoryFiles(AddressablesCachePath);
                EditorFileUtils.DeleteSubDirectories(AddressablesCachePath);
            }
            catch (Exception e) {
                Debug.LogError(e);
            }

            GameLog.Log("Addressables Library Cache Removed");
        }
Пример #4
0
        public void EditorFileUtilsTest_GetFileNameWithoutExtend_Name()
        {
            //Arrange
            string t1 = testPath + "ObjectPool.cs";

            //Act
            //Try to rename the GameObject
            string name = EditorFileUtils.GetFileNameWithoutExtend(t1);

            //Assert
            //The object has a new name
            Assert.AreEqual("ObjectPool", name);
        }
Пример #5
0
        public void EditorFileUtilsTest_GetDirSubDirNameList_Count()
        {
            //Arrange
            string t1 = testPath;

            //Act
            //Try to rename the GameObject
            int length = EditorFileUtils.GetDirSubDirNameList(t1).Count;

            //Assert
            //The object has a new name
            Assert.AreEqual(1, length);
        }
Пример #6
0
        public void EditorFileUtilsTest_GetDirPath_Name()
        {
            //Arrange
            string t1 = testPath;

            //Act
            //Try to rename the GameObject
            string name = EditorFileUtils.GetDirPath(t1);

            //Assert
            //The object has a new name
            Assert.AreEqual(t1, name);
        }
Пример #7
0
        public void EditorFileUtilsTest_GetDirSubFilePathList_Count()
        {
            //Arrange
            string t1 = testPath;

            //Act
            //Try to rename the GameObject
            int length = EditorFileUtils.GetDirSubFilePathList(testPath, true, "cs").Count;

            //Assert
            //The object has a new name
            Assert.AreEqual(4, length);

            int length1 = EditorFileUtils.GetDirSubFilePathList(testPath, false, "cs").Count;

            Assert.AreEqual(2, length1);
        }
Пример #8
0
        public SpriteAtlas Create(string fullPath)
        {
            if (string.IsNullOrEmpty(fullPath))
            {
                return(null);
            }

            var atlas = new SpriteAtlas();

            var atlasTextureSettings = new SpriteAtlasTextureSettings();

            atlasTextureSettings.generateMipMaps = _atlasSettings.GenerateMipMaps;
            atlasTextureSettings.filterMode      = _atlasSettings.FilterMode;
            atlasTextureSettings.readable        = _atlasSettings.ReadWriteEnabled;
            atlasTextureSettings.sRGB            = _atlasSettings.SRgb;

            var atlasPackingSettings = new SpriteAtlasPackingSettings();

            atlasPackingSettings.padding            = _atlasSettings.Padding;
            atlasPackingSettings.enableRotation     = _atlasSettings.AllowRotation;
            atlasPackingSettings.enableTightPacking = _atlasSettings.TightPacking;

            var platformSettings = new TextureImporterPlatformSettings();

            platformSettings.textureCompression  = _atlasSettings.Compression;
            platformSettings.maxTextureSize      = _atlasSettings.MaxTextureSize;
            platformSettings.format              = (TextureImporterFormat)_atlasSettings.Format;
            platformSettings.crunchedCompression = _atlasSettings.UseCrunchCompression;
            platformSettings.compressionQuality  = _atlasSettings.CompressionQuality;

            atlas.SetTextureSettings(atlasTextureSettings);
            atlas.SetPackingSettings(atlasPackingSettings);
            atlas.SetPlatformSettings(platformSettings);

            atlas.SetIncludeInBuild(_atlasSettings.IncludeInBuild);
            atlas.SetIsVariant(_atlasSettings.Type == SpriteAtlasType.Variant);

            EditorFileUtils.CreateDirectories(fullPath);
            AssetDatabase.CreateAsset(atlas, fullPath);

            AssetDatabase.SaveAssets();

            AssetDatabase.WriteImportSettingsIfDirty(fullPath);

            return(atlas);
        }
Пример #9
0
        public StackTraceLine(string line, string sourcePath = null, int lineNumber = -1, int lineNumberLength = 0)
        {
            this.line        = line;
            this.sourcePath  = sourcePath;
            this.lineNumber  = lineNumber;
            this.frame       = default(Rect);
            this.sourceFrame = default(Rect);

            if (!string.IsNullOrEmpty(sourcePath))
            {
                sourcePathExists = EditorFileUtils.PathExists(sourcePath);
                sourcePathStart  = line.IndexOf(sourcePath);
                sourcePathEnd    = sourcePathStart + sourcePath.Length + 1 + lineNumberLength;
            }
            else
            {
                sourcePathExists = false;
                sourcePathStart  = sourcePathEnd = -1;
            }
        }
Пример #10
0
        public static bool WriteUnityFile(this string scriptValue, string path, bool force = false)
        {
            var content = _fileContentCache[path];

            if (string.IsNullOrEmpty(scriptValue))
            {
                return(false);
            }

            if (!force && scriptValue.Equals(content))
            {
                return(false);
            }

            var result = EditorFileUtils.WriteAssetsContent(path, scriptValue);

            if (result)
            {
                _fileContentCache[path] = scriptValue;
            }

            return(result);
        }
Пример #11
0
    private void OnEnable()
    {
        string path = "folder/folder2/aa3_.txt";
        var    fi   = FileUtils.Creator.GetFileInfoForCreationInDataPath(path, FileUtils.Creator.CreateOnFileExistBehaviour.RenameNewFile);

//        fi.Create();

#if UNITY_EDITOR
        EditorFileUtils.OpenFolder(fi.FullName);
#endif

        Debug.LogError(fi.FullName);



        var fi2 = FileUtils.Creator.GetFileInfoForCreationInDataPath(FileUtils.AddTimeSuffix(path), FileUtils.Creator.CreateOnFileExistBehaviour.RenameNewFile);
        // fi2.Create();
#if UNITY_EDITOR
        // EditorFileUtils.OpenFolder(fi2.FullName);
#endif
        Debug.LogError(fi2.FullName);

        Debug.LogError($"{path} || {FileUtils.AddTimeSuffix(path)}");
    }
Пример #12
0
        public static void ReadUnityFile(this string path, out string content, bool createIfNonExists = false)
        {
            var result = EditorFileUtils.ReadContent(path, createIfNonExists);

            content = result.content;
        }
Пример #13
0
 public static bool CreateScript(this string scriptData, string path)
 {
     return(EditorFileUtils.WriteAssetsContent(path, scriptData));
 }
Пример #14
0
        public static bool CreateScript(this ScriptData scriptData, string path, bool force = false)
        {
            var result = EditorFileUtils.WriteAssetsContent(path, scriptData.Convert());

            return(result);
        }
        public Sprite Create(SpriteAssetFactoryInputData data)
        {
            if (!string.IsNullOrEmpty(data.Name) && !string.IsNullOrEmpty(data.Path) && data.Reference != null)
            {
                EditorFileUtils.CreateDirectories(data.Path);

                var directoryInfo = new DirectoryInfo(data.Path);
                var fullPath      = Path.Combine(directoryInfo.FullName, $"{data.Name}.png");
                var relativePath  = Path.Combine(data.Path, $"{data.Name}.png");

                var bytes = data.Reference.EncodeToPNG();
                File.WriteAllBytes(fullPath, bytes);

                AssetDatabase.Refresh();

                _importerSettings         = data.ImporterSettings;
                _importerPlatformSettings = data.ImporterPlatformSettings;

                var importer = AssetImporter.GetAtPath(relativePath);
                if (importer != null && importer is TextureImporter textureImporter)
                {
                    if (_importerSettings != null)
                    {
                        textureImporter.textureType         = _importerSettings.textureType;
                        textureImporter.spritePixelsPerUnit = _importerSettings.spritePixelsPerUnit;
                        textureImporter.spritePivot         = _importerSettings.spritePivot;
                        textureImporter.sRGBTexture         = _importerSettings.sRGBTexture;
                        textureImporter.alphaSource         = _importerSettings.alphaSource;
                        textureImporter.alphaIsTransparency = _importerSettings.alphaIsTransparency;
                        textureImporter.isReadable          = _importerSettings.readable;
                        textureImporter.mipmapEnabled       = _importerSettings.mipmapEnabled;
                        textureImporter.wrapMode            = _importerSettings.wrapMode;
                        textureImporter.filterMode          = _importerSettings.filterMode;
                        textureImporter.anisoLevel          = _importerSettings.aniso;

                        var importerSettings = new TextureImporterSettings();
                        textureImporter.ReadTextureSettings(importerSettings);

                        importerSettings.spriteMode      = _importerSettings.spriteMode;
                        importerSettings.spriteMeshType  = _importerSettings.spriteMeshType;
                        importerSettings.spriteExtrude   = _importerSettings.spriteExtrude;
                        importerSettings.spriteAlignment = _importerSettings.spriteAlignment;
                        importerSettings.spriteGenerateFallbackPhysicsShape = _importerSettings.spriteGenerateFallbackPhysicsShape;

                        textureImporter.SetTextureSettings(importerSettings);

                        foreach (var platformSettings in _importerPlatformSettings)
                        {
                            var existingSettings = textureImporter.GetPlatformTextureSettings(platformSettings.name);

                            existingSettings.overridden                  = platformSettings.overridden;
                            existingSettings.maxTextureSize              = platformSettings.maxTextureSize;
                            existingSettings.resizeAlgorithm             = platformSettings.resizeAlgorithm;
                            existingSettings.format                      = platformSettings.format;
                            existingSettings.textureCompression          = platformSettings.textureCompression;
                            existingSettings.crunchedCompression         = platformSettings.crunchedCompression;
                            existingSettings.compressionQuality          = platformSettings.compressionQuality;
                            existingSettings.allowsAlphaSplitting        = platformSettings.allowsAlphaSplitting;
                            existingSettings.androidETC2FallbackOverride = platformSettings.androidETC2FallbackOverride;

                            textureImporter.SetPlatformTextureSettings(existingSettings);
                        }
                    }
                    else
                    {
                        textureImporter.mipmapEnabled = false;

                        textureImporter.isReadable  = true;
                        textureImporter.textureType = TextureImporterType.Sprite;
                        textureImporter.spritePivot = new Vector2(0.5f, 0.5f);

                        textureImporter.filterMode          = _settings.FilterMode;
                        textureImporter.mipmapEnabled       = _settings.GenerateMipMaps;
                        textureImporter.crunchedCompression = _settings.UseCrunchCompression;
                        textureImporter.compressionQuality  = _settings.CompressionQuality;
                        textureImporter.textureCompression  = _settings.Compression;
                    }

                    textureImporter.SaveAndReimport();
                }

                AssetDatabase.Refresh();
                AssetDatabaseHelper.TryGetAsset <Sprite>(relativePath, out var sprite);

                return(sprite);
            }

            return(null);
        }