Skip to content

Commit

Permalink
Added Package Manager support
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirkula committed Apr 28, 2020
1 parent a53ad59 commit c5737d7
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 9 deletions.
File renamed without changes.
23 changes: 17 additions & 6 deletions README.md → .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

![SlidingPuzzleExample](screenshots/1.jpg)

This plugin helps you save/load textures and perform simple operations on them, like scale and slice. It also contains an example sliding puzzle project to demonstrate the slice operation.
**Forum Thread:** https://forum.unity.com/threads/texture-ops-a-basic-image-processing-plugin-for-unity-open-source.539065/

**[Support the Developer ☕](https://yasirkula.itch.io/unity3d)**

## ABOUT

[Support the Developer ☕](https://yasirkula.itch.io/unity3d)
This plugin helps you save/load textures and perform simple operations on them, like scale and slice. It also contains an example sliding puzzle project to demonstrate the slice operation.

### iOS Setup

Expand All @@ -16,9 +20,16 @@ iOS setup is normally handled automatically via a post processor script but, if

![OtherLinkerFlags](screenshots/2.png)

## How To
## INSTALLATION

There are 3 ways to install this plugin:

- import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextureOps/releases) via *Assets-Import Package*
- clone/[download](https://github.com/yasirkula/UnityTextureOps/archive/master.zip) this repository and move the *Plugins* folder to your Unity project's *Assets* folder
- *(via Package Manager)* add the following line to *Packages/manifest.json*:
- `"com.yasirkula.textureops": "https://github.com/yasirkula/UnityTextureOps.git",`

Simply import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextureOps/releases) to your project and you are good to go!
## HOW TO

**NOTE:** functions that return a *Texture2D* or *Texture2D[]* may return *null*, if something goes wrong.

Expand All @@ -42,7 +53,7 @@ Simply import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextur

**NOTE:** on some Android devices, these functions may not work correctly when called with a *sourceTex* that was created in the same frame. Therefore, if you'd like to call these functions immediately after *LoadImage*, consider instead waiting for at least one frame. You can use `yield return null;` in a coroutine to wait for one frame.

`Texture2D[] TextureOps.Crop( Texture2D, sourceTex, int leftOffset, int topOffset, int width, int height, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options )`: crops sourceTex and returns the cropped texture.
`Texture2D TextureOps.Crop( Texture2D, sourceTex, int leftOffset, int topOffset, int width, int height, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options )`: crops *sourceTex* and returns the cropped texture.

`Texture2D TextureOps.Scale( Texture2D sourceTex, int targetWidth, int targetHeight, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options )`: scales *sourceTex* to the specified size and returns the scaled texture. sourceTex's aspect ratio may not be preserved.

Expand All @@ -56,7 +67,7 @@ Simply import [TextureOps.unitypackage](https://github.com/yasirkula/UnityTextur

`TextureOps.VideoProperties TextureOps.GetVideoProperties( string videoPath )`: *[Android & iOS only]* returns a *VideoProperties* instance that holds the width, height, duration (in milliseconds) and rotation information of a video file. To play a video in correct orientation, you should rotate it by *rotation* degrees clockwise. For a 90-degree or 270-degree rotated video, values of *width* and *height* should be swapped to get the display size of the video.

## Example Code
## EXAMPLE CODE

The following code loads "*DESKTOP_DIR/image.jpeg*" into a Texture, applies *TextureOps.ScaleFill* to it and then saves it as "*DESKTOP_DIR/image_new.jpeg*". See *SlidePuzzleScene* demo scene for an example usage of *TextureOps.Slice*.

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
7 changes: 7 additions & 0 deletions LICENSE.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Plugins/TextureOps/Editor/TextureOps.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "TextureOps.Editor",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Plugins/TextureOps/Editor/TextureOps.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Plugins/TextureOps/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Texture2D TextureOps.LoadImage( string imagePath, int maxSize = -1, TextureOps.O
//// TEXTURE OPERATIONS ////
// NOTE: on some Android devices, these functions may not work correctly when called with a 'sourceTex' that was created in the same frame. Therefore, if you'd like to call these functions immediately after 'LoadImage', consider instead waiting for at least one frame. You can use `yield return null;` in a coroutine to wait for one frame.

Texture2D TextureOps.Crop( Texture2D, sourceTex, int leftOffset, int topOffset, int width, int height, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): crops sourceTex and returns the cropped texture.
Texture2D TextureOps.Scale( Texture2D sourceTex, int targetWidth, int targetHeight, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): scales sourceTex to the specified size and returns the scaled texture. sourceTex's aspect ratio may not be preserved.
Texture2D TextureOps.ScaleFill( Texture2D sourceTex, int targetWidth, int targetHeight, Color32 fillColor, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): scales sourceTex to the specified size and returns the scaled texture. sourceTex's aspect ratio is preserved and blank space is filled with fillColor.
Texture2D[] TextureOps.Slice( Texture2D sourceTex, int sliceTexWidth, int sliceTexHeight, TextureFormat format = TextureFormat.RGBA32, TextureOps.Options options ): slices sourceTex into smaller textures and returns these textures in an array. sourceTex is sliced row-by-row, starting from top-left corner.
Expand Down
3 changes: 3 additions & 0 deletions Plugins/TextureOps/TextureOps.Runtime.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "TextureOps.Runtime"
}
7 changes: 7 additions & 0 deletions Plugins/TextureOps/TextureOps.Runtime.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Plugins/TextureOps/TextureOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,17 @@ public static bool SaveImage( byte[] sourceBytes, string imagePath )
{
if( sourceTex == null )
throw new ArgumentException( "Parameter 'sourceTex' is null!" );

if( width <= 0 || width > sourceTex.width )
width = sourceTex.width;
if( height <= 0 || height > sourceTex.height )
height = sourceTex.height;

if( leftOffset <= 0 )
leftOffset = 0;
else if( leftOffset + width > sourceTex.width )
leftOffset = sourceTex.width - width;

if( topOffset <= 0 )
topOffset = 0;
else if( topOffset + height > sourceTex.height )
Expand Down Expand Up @@ -294,7 +296,7 @@ public static bool SaveImage( byte[] sourceBytes, string imagePath )

return result;
}

public static Texture2D Scale( Texture sourceTex, int targetWidth, int targetHeight, TextureFormat format = TextureFormat.RGBA32, Options options = new Options() )
{
if( sourceTex == null )
Expand Down Expand Up @@ -377,7 +379,7 @@ public static bool SaveImage( byte[] sourceBytes, string imagePath )

return result;
}

public static Texture2D[] Slice( Texture sourceTex, int sliceTexWidth, int sliceTexHeight, TextureFormat format = TextureFormat.RGBA32, Options options = new Options() )
{
if( sourceTex == null )
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "com.yasirkula.textureops",
"displayName": "Texture Ops",
"version": "1.1.0",
"description": "This plugin helps you save/load textures and perform simple operations on them, like scale and slice. It also contains an example sliding puzzle project to demonstrate the slice operation."
}
7 changes: 7 additions & 0 deletions package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5737d7

Please sign in to comment.