Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabriziospadaro/SpriteSheetRenderer
Spritesheet renderer is a powerful Unity ECS API to render massive numbers of sprites using the new dots stack, taking full advantage of Jobs, DynamicBuffers and ComputeBuffer
https://github.com/fabriziospadaro/SpriteSheetRenderer
ecs entity-component-system unity unity-dots unity2d
Last synced: 2 months ago
JSON representation
Spritesheet renderer is a powerful Unity ECS API to render massive numbers of sprites using the new dots stack, taking full advantage of Jobs, DynamicBuffers and ComputeBuffer
- Host: GitHub
- URL: https://github.com/fabriziospadaro/SpriteSheetRenderer
- Owner: fabriziospadaro
- License: other
- Created: 2019-06-17T14:00:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-08T19:02:30.000Z (about 2 years ago)
- Last Synced: 2024-08-03T13:14:19.415Z (5 months ago)
- Topics: ecs, entity-component-system, unity, unity-dots, unity2d
- Language: ShaderLab
- Homepage: https://www.linkedin.com/in/fabrizio-spadaro/
- Size: 1.8 MB
- Stars: 375
- Watchers: 31
- Forks: 48
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-opensource-unity - SpriteSheetRenderer - A powerful Unity ECS system to render massive numbers of animated sprites. (Open Source Packages / DOTS)
- awesome-unity3d - SpriteSheetRenderer - A powerful Unity ECS system to render massive numbers of animated sprites (Open Source Repositories / DOTS)
- awesome-unity-open-source-on-github - SpriteSheetRenderer - A powerful Unity ECS system to render massive numbers of animated sprites (ECS)
README
## Support
SpriteSheetRenderer is an open-source project that I am developing in my free time. If you like it you can support me by donations.[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/LRTk8rn
)# SpriteSheetRenderer (updated to unity 2020.3 and entitas V0.17.0)
A powerful Unity ECS api to render massive numbers of animated sprites using the new dots stack, taking full advantages of Jobs, DynamicBuffers and ComputeBuffer:
##### 1 million animated sprites were rendered at 60fps(none of them was hurt during the process) on a Mid-2015 MacBook Pro.
![N|Solid](https://forum.unity.com/proxy.php?image=https%3A%2F%2Fi.imgur.com%2FzRSWhy0.png&hash=754bc4b4187e2d72ce0eb2c578b996dc)
## C# 4 required### How to use (SINGLE INSTANTIATE):
* 1- Create the Archetype:```sh
EntityArchetype archetype = eManager.CreateArchetype(
typeof(Position2D),
typeof(Rotation2D),
typeof(Scale),
//required params
typeof(SpriteIndex),
typeof(SpriteSheetAnimation),
typeof(SpriteSheetMaterial),
typeof(SpriteSheetColor),
typeof(SpriteMatrix),
typeof(BufferHook)
);
```* 2- Record and bake this spritesheet(only once)
```sh
SpriteSheetManager.RecordSpriteSheet(sprites, "emoji");
```
* 3- Populate components```sh
List components = new List {
new Position2D { Value = float2.zero },
new Scale { Value = 15 },
new SpriteIndex { Value = UnityEngine.Random.Range(0, maxSprites) },
new SpriteSheetAnimation { maxSprites = maxSprites, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10 },
new SpriteSheetColor { color = new float4(color.r, color.g, color.b, color.a) }
};
```* 4- Instantiate the entity
```sh
Entity e = SpriteSheetManager.Instantiate(archetype, components, "emoji");
```
* Update the entity```sh
Entity e = SpriteSheetManager.UpdateEntity(e, new Position2D { Value = float2.zero});
```* Destroy the entity
```sh
Entity e = SpriteSheetManager.DestroyEntity(e, "emoji");
```### How to use (BULK INSTANTIATE):
* 1- Create the Archetype:
```sh
EntityArchetype archetype = eManager.CreateArchetype(
typeof(Position2D),
typeof(Rotation2D),
typeof(Scale),
//required params
typeof(SpriteIndex),
typeof(SpriteSheetAnimation),
typeof(SpriteSheetMaterial),
typeof(SpriteSheetColor),
typeof(SpriteMatrix),
typeof(BufferHook)
);
```* 2- Bulk instantiate entities
```sh
NativeArray entities = new NativeArray(spriteCount, Allocator.Temp);
eManager.CreateEntity(archetype, entities);
```* 2- Record and bake this spritesheet(only once)
```sh
SpriteSheetManager.RecordSpriteSheet(sprites, "emoji");
```* 3- Populate components
```sh
for(int i = 0; i < entities.Length; i++) {
Entity e = entities[i];
eManager.SetComponentData(e, new SpriteIndex { Value = 0});
eManager.SetComponentData(e, new Scale { Value = 10 });
eManager.SetComponentData(e, new Position2D { Value = RANDOM_VECTOR });
eManager.SetComponentData(e, new SpriteSheetAnimation { maxSprites = MAX_SPRITES, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10 });
SpriteSheetColor col = new SpriteSheetColor { color = A_COLOR };
eManager.SetComponentData(e, col);
eManager.SetComponentData(e, new BufferHook { bufferID = i, bufferEnityID = DynamicBufferManager.GetEntityBufferID(material) });
eManager.SetSharedComponentData(e, material);
}
```