Code Monkey home page Code Monkey logo

skiaforunity's Introduction

SkiaSharp for Unity with Lottie Animation and HarfBuzz Text, SVG Supports

SkiaSharp for Unity is a powerful plugin that leverages the SkiaSharp 2D graphics library to enhance Unity game development. With the added advantage of HarfBuzz support, this plugin allows you to create high-quality, cross-platform 2D graphics and user interfaces for your Unity projects. HarfBuzz support enables better text rendering, including advanced features such as native fonts, emoji support, and right-to-left (RTL) language rendering.

SkiaSharp is a .NET binding to the Skia library, which is utilized by popular platforms like Google Chrome, Android, and Flutter. By integrating SkiaSharp into Unity, you gain access to a wide range of APIs for rendering vector graphics, text, and images. The inclusion of HarfBuzz further improves text rendering, making it ideal for internationalization and multilingual projects.

Added support for SVG.Skia:

SkiaForUnity now supports rendering SVG graphics using SVG.Skia. This allows you to leverage the power of SVG for creating scalable vector graphics within your Unity projects.

Benefits of SVG.Skia:

Scalability: SVG graphics can be scaled to any size without losing quality.
Cross-platform compatibility: SVG is a widely supported format that works across different platforms.

Features

  • High-performance graphics: SkiaSharp for Unity utilizes Skia's hardware-accelerated rendering capabilities to deliver fast and smooth graphics performance.

  • Cross-platform support: SkiaSharp supports multiple platforms, including Windows, macOS, iOS, Android, allowing you to create graphics that work seamlessly across different devices.

  • Extensive API: SkiaSharp provides a rich set of APIs for drawing paths, shapes, text, and images, enabling you to create visually stunning graphics and user interfaces.

  • Custom shaders: With SkiaSharp for Unity, you can write custom shaders using the Skia graphics API, allowing you to create unique visual effects and stylized graphics.

  • Lottie animations: The package includes the Skottie library, which enables you to import and play Lottie animations in your Unity projects.

  • HarfBuzz support: The integration of HarfBuzz enhances text rendering in SkiaSharp, offering benefits such as native fonts, emoji rendering, and RTL language support. This makes SkiaSharp for Unity an excellent choice for projects that require advanced text rendering capabilities.

aa88e0f6-619e-41d5-8bff-95017e870b38.mp4
  • Integration with Unity: SkiaSharp for Unity seamlessly integrates with the Unity Editor, providing a familiar development environment for working with Skia graphics and Lottie animations in your Unity projects.

Watch the SkiaForUnity v1.0.0.Pre-2 Release Videos:

Editor Mode

Screen.Recording.2023-07-07.at.2.50.10.AM.mp4

Playing Animations

Untitled.mp4

Getting Started

To get started with SkiaSharp for Unity, follow these steps:

  1. Clone or download the SkiaSharp for Unity repository from GitHub. or you can use

Package Manager

  1. Open your Unity project and navigate to Windows> Package Manager.
  2. Click the + button in the top-left corner and select Add package from git URL
  3. Enter the following URL and click Add

https://github.com/ammariqais/SkiaForUnity.git?path=SkiaUnity/Assets/SkiaSharp

  1. Import the SkiaSharp package into your Unity project.

  2. In Unity, go to Edit > Project Settings > Player and select the iOS platform.

  3. Scroll down to the Other Settings section and locate the Scripting Define Symbols field.

  4. Add __ UNIFIED _ _ and _ IOS _ to the Scripting Define Symbols. This is necessary to enable the SkiaSharp functionality specifically for iOS.

  5. Create a new script or modify an existing script to leverage the SkiaSharp API for drawing graphics and the Skottie API for playing Lottie animations.

  6. Build and run your Unity project on an iOS device to see the Skia graphics and Lottie animations in action.

Tutorials

Document

Contributing

Contributions to SkiaSharp for Unity are welcome! If you encounter any issues, have suggestions for improvements, or would like to contribute code, please feel free to open an issue or submit a pull request on the GitHub repository.

License

SkiaSharp for Unity is licensed under the MIT License. Please refer to the LICENSE file for more information.

Support

If you have any questions, need assistance, or want to join a community of developers using SkiaSharp for Unity, you can:

Acknowledgements

SkiaSharp for Unity is built on top of the amazing SkiaSharp library and includes the Skottie library for Lottie animations. We would like to express our gratitude to the SkiaSharp and Skottie communities for their hard work and dedication in developing and maintaining these powerful libraries.

Authors

SkiaSharp for Unity is developed and maintained by Qais Ammari.

skiaforunity's People

Contributors

ammariqais avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

skiaforunity's Issues

Crash in Unity on recompile

During development we have constant crashes with the below stack trace. I'm not sure what conditions are needed exactly but at least the case if one forget to stop play mode before triggering a recompile is always triggering the crash. The component in question is the SkottiePlayer. Unity 2022.3.10 (Windows Standalone), Skia package version 2.1.3. A fix for this would be much appreciated!

=================================================================
	Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at NonAlertableWin32Lock:EnterCriticalSection <0x000db>
	  at NonAlertableWin32Lock:Enter <0x0008a>
	  at NonAlertableWin32Lock:EnterWriteLock <0x00082>
	  at SkiaSharp.HandleDictionary:DeregisterHandle <0x00236>
	  at SkiaSharp.SKObject:DeregisterHandle <0x0010a>
	  at SkiaSharp.SKObject:set_Handle <0x00132>
	  at SkiaSharp.SKNativeObject:Dispose <0x0030b>
	  at SkiaSharp.SKObject:Dispose <0x0007a>
	  at SkiaSharp.SKCanvas:Dispose <0x0007a>
	  at SkiaSharp.SKNativeObject:Finalize <0x000c0>
	  at System.Object:runtime_invoke_virtual_void__this__ <0x0018b>
=================================================================

DllNotFoundException on iOS build

When I build my game for iOS, I get this error on my device.

This is link of my Unity project:
https://github.com/e-fo/UnityRuntimeAtlasMultithreaded

Can anyone helps me to find and solve my problem?

DllNotFoundException: Unable to load DLL 'libSkiaSharp'. Tried the load the following dynamic libraries: Unable to load dynamic library '/libSkiaSharp' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen(/libSkiaSharp, 0x0005): tried: '/libSkiaSharp' (errno=2), '/private/preboot/Cryptexes/OS/libSkiaSharp' (errno=2), '/libSkiaSharp' (errno=2)\
  at SkiaSharp.SkiaApi.sk_version_get_milestone () [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SkiaSharpVersion.get_Native () [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible (System.Boolean throwIfIncompatible) [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SKObject..cctor () [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SKObject.set_Handle (System.IntPtr value) [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SKNativeObject.Finalize () [0x00000] in <00000000000000000000000000000000>:0 \
Rethrow as TypeInitializationException: The type initializer for 'SkiaSharp.SKObject' threw an exception.\
  at SkiaSharp.SKObject.set_Handle (System.IntPtr value) [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SKNativeObject.Finalize () [0x00000] in <00000000000000000000000000000000>:0 \
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)\
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)\
\
DllNotFoundException: Unable to load DLL 'libSkiaSharp'. Tried the load the following dynamic libraries: Unable to load dynamic library '/libSkiaSharp' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen(/libSkiaSharp, 0x0005): tried: '/libSkiaSharp' (errno=2), '/private/preboot/Cryptexes/OS/libSkiaSharp' (errno=2), '/libSkiaSharp' (errno=2)\
  at SkiaSharp.SkiaApi.sk_version_get_milestone () [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SkiaSharpVersion.get_Native () [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible (System.Boolean throwIfIncompatible) [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SKObject..cctor () [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SKObject.set_Handle (System.IntPtr value) [0x00000] in <00000000000000000000000000000000>:0 \
  at SkiaSharp.SKNativeObject.Finalize () [0x00000] in <00000000000000000000000000000000>:0 \
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)\
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)\

Doesn't work for Windows builds

Android, iOS and the Editor seem to work. Windows compile bombs out with the following:

## Script Compilation Error for: Csc Library/Bee/artifacts/1900b0aP.dag/SkiaSharp.Unity.dll (+2 others)
## CmdLine: "C:\Program Files\Unity\Hub\Editor\2022.3.1f1\Editor\Data\NetCoreRuntime\dotnet.exe" exec "C:/Program Files/Unity/Hub/Editor/2022.3.1f1/Editor/Data/DotNetSdkRoslyn/csc.dll" /nostdlib /noconfig /shared "@Library/Bee/artifacts/1900b0aP.dag/SkiaSharp.Unity.rsp" "@Library/Bee/artifacts/1900b0aP.dag/SkiaSharp.Unity.rsp2"
## Output:
SkiaSharp\Runtime\SkottiePlayer.cs(6,29): error CS0234: The type or namespace name 'Skottie' does not exist in the namespace 'SkiaSharp' (are you missing an assembly reference?)
SkiaSharp\Runtime\SkottiePlayer.cs(26,11): error CS0246: The type or namespace name 'SKCanvas' could not be found (are you missing a using directive or an assembly reference?)
SkiaSharp\Runtime\SkottiePlayer.cs(27,11): error CS0246: The type or namespace name 'SKRect' could not be found (are you missing a using directive or an assembly reference?)
SkiaSharp\Runtime\SkottiePlayer.cs(29,11): error CS0246: The type or namespace name 'SKImageInfo' could not be found (are you missing a using directive or an assembly reference?)
SkiaSharp\Runtime\SkottiePlayer.cs(30,11): error CS0246: The type or namespace name 'SKSurface' could not be found (are you missing a using directive or an assembly reference?)

I tried simply removing that file and it caused other errors.. so presumably it's needed.

UPM entry?

I am currently creating a package which includes a set of scenes for other projects to use. Those scenes have lottie animations. Due to Unity's limitation that packages can't have git dependencies (source: https://docs.unity3d.com/Manual/upm-git.html), I really need this in an importable format for that if possible

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.