SimpleSpritePackerEditor.SPTools.AssetSetReadWriteEnabled C# (CSharp) Method

AssetSetReadWriteEnabled() public static method

Sets the asset Read/Write enabled state.
public static AssetSetReadWriteEnabled ( string path, bool enabled, bool force ) : bool
path string Path.
enabled bool If set to true enabled.
force bool If set to true force.
return bool
        public static bool AssetSetReadWriteEnabled(string path, bool enabled, bool force)
        {
            if (string.IsNullOrEmpty(path))
                return false;

            TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;

            if (ti == null)
                return false;

            TextureImporterSettings settings = new TextureImporterSettings();
            ti.ReadTextureSettings(settings);

            if (force || settings.readable != enabled)
            {
                settings.readable = enabled;
                ti.SetTextureSettings(settings);
                SPTools.DoAssetReimport(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
            }

            return true;
        }

Usage Example

        /// <summary>
        /// Sets the assets read write enabled.
        /// </summary>
        /// <returns><c>true</c>, if assets read write enabled was set, <c>false</c> otherwise.</returns>
        /// <param name="assetPaths">Asset paths.</param>
        /// <param name="enabled">If set to <c>true</c> enabled.</param>
        protected bool SetAssetsReadWriteEnabled(string[] assetPaths, bool enabled)
        {
            bool success = true;

            // Make the assets readable
            foreach (string assetPath in assetPaths)
            {
                // Make the texture readable
                if (!SPTools.AssetSetReadWriteEnabled(assetPath, enabled, false))
                {
                    Debug.LogWarning("Sprite Packer failed to set Read/Write state (" + enabled.ToString() + ") on asset: " + assetPath);
                    success = false;
                }
            }

            // Return the result
            return(success);
        }
All Usage Examples Of SimpleSpritePackerEditor.SPTools::AssetSetReadWriteEnabled