Пример #1
0
        private void BuildAtlas()
        {
            DisplayProgressBar("Loading source textures...", .0f);
            var inputFolderHelper = new FolderAssetHelper(inputFolderProperty.objectReferenceValue);
            var textureAssets     = inputFolderHelper.LoadContainedAssets <Texture2D>(includeSubfoldersProperty.boolValue, prependSubfolderNamesProperty.boolValue);
            var dicedUnits        = DiceSourceTextures(textureAssets);

            if (!CreateAtlasTextures(dicedUnits))
            {
                EditorUtility.ClearProgressBar(); return;
            }
            CreateDicedSprites(dicedUnits);
            dataSizeValueContent = GetDataSizeValueContent();
            AssetDatabase.SaveAssets();
            EditorUtility.ClearProgressBar();
        }
        private void BuildAtlas()
        {
            var atlasAssetPath        = AssetDatabase.GetAssetPath(target);
            var unitSize              = diceUnitSizeProperty.intValue;
            var padding               = paddingProperty.intValue;
            var uvInset               = uvInsetProperty.floatValue;
            var ppu                   = pixelsPerUnitProperty.floatValue;
            var forceSquare           = forceSquareProperty.boolValue;
            var atlasSizeLimit        = atlasSizeLimitProperty.intValue;
            var includeSubfolder      = includeSubfoldersProperty.boolValue;
            var prependSubfolderNames = prependSubfolderNamesProperty.boolValue;
            var inputFolder           = inputFolderProperty.objectReferenceValue;
            var keepOriginalPivot     = keepOriginalPivotProperty.boolValue;
            var defaultPivot          = defaultPivotProperty.vector2Value;
            var decoupleSpriteData    = decoupleSpriteDataProperty.boolValue;

            try
            {
                DisplayProgressBar("Loading source textures...", .0f);
                var inputFolderHelper = new FolderAssetHelper(inputFolder);
                var textureAssets     = inputFolderHelper.LoadContainedAssets <Texture2D>(includeSubfolder, prependSubfolderNames);
                var dicedUnits        = DiceSourceTextures(textureAssets, unitSize, padding, ppu);
                if (!CreateAtlasTextures(dicedUnits, unitSize, padding, uvInset, forceSquare, atlasSizeLimit, texturesProperty, atlasAssetPath))
                {
                    EditorUtility.ClearProgressBar();
                    return;
                }
                DisplayProgressBar("Generating sprite assets...", 1f);
                var sprites = dicedUnits.Select(nameToUnits => CreateSprite(nameToUnits.Key, nameToUnits.Value.First().AtlasTexture, nameToUnits.Value, ppu, keepOriginalPivot, defaultPivot)).ToList();
                SaveGeneratedSprites(sprites, decoupleSpriteData, generatedSpritesFolderGuidProperty, spritesProperty, target);

                serializedObject.ApplyModifiedProperties();
                AssetDatabase.SaveAssets();
                dataSizeValueContent = GetDataSizeValueContent();
            }
            finally { EditorUtility.ClearProgressBar(); }
        }