-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Such sprites will stretch to screen size and (for now) repeat it's texture, so some UVs settings from authorings may by ignored because of working of new full-screen size sprites (related only for those kind of sprites)
- Loading branch information
1 parent
c0b0096
commit 831551b
Showing
13 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Unity.Entities; | ||
using UnityEngine; | ||
|
||
namespace NSprites | ||
{ | ||
public class FullScreenSpriteAuthoring : MonoBehaviour | ||
{ | ||
[SerializeField] private SpriteRendererAuthoring _spriteAuthoring; | ||
|
||
private partial class Baker : Baker<FullScreenSpriteAuthoring> | ||
{ | ||
public override void Bake(FullScreenSpriteAuthoring authoring) | ||
{ | ||
if(authoring._spriteAuthoring == null) | ||
return; | ||
|
||
var entity = GetEntity(TransformUsageFlags.None); | ||
AddComponent<FullScreenSpriteTag>(entity); | ||
AddComponent(entity, new NativeSpriteSize{ Value = authoring._spriteAuthoring.NativeSpriteSize }); | ||
|
||
DependsOn(authoring._spriteAuthoring); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Unity.Entities; | ||
|
||
namespace NSprites | ||
{ | ||
public struct FullScreenSpriteTag : IComponentData | ||
{ | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Unity.Entities; | ||
using Unity.Mathematics; | ||
|
||
namespace NSprites | ||
{ | ||
public struct NativeSpriteSize : IComponentData | ||
{ | ||
public float2 Value; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Unity.Burst; | ||
using Unity.Entities; | ||
using Unity.Mathematics; | ||
|
||
namespace NSprites | ||
{ | ||
[UpdateAfter(typeof(UpdateCullingDataSystem))] | ||
public partial struct FullScreenSpriteSystem : ISystem | ||
{ | ||
[BurstCompile] | ||
[WithAll(typeof(FullScreenSpriteTag))] | ||
private partial struct RecalculateSpritesJob : IJobEntity | ||
{ | ||
public float2 CameraPosition; | ||
public float2 ScreenSize; | ||
|
||
private void Execute(ref Scale2D size, ref WorldPosition2D position, ref UVTilingAndOffset uvTilingAndOffset, in NativeSpriteSize nativeSpriteSize) | ||
{ | ||
size.value = ScreenSize; | ||
position.value = CameraPosition; | ||
uvTilingAndOffset.value = new float4(size.value / nativeSpriteSize.Value, CameraPosition / nativeSpriteSize.Value - size.value / nativeSpriteSize.Value / 2f); | ||
} | ||
} | ||
|
||
private struct SystemData : IComponentData | ||
{ | ||
public float2 LastCameraPosition; | ||
public Bounds2D LastCameraBounds; | ||
} | ||
|
||
[BurstCompile] | ||
public void OnCreate(ref SystemState state) | ||
{ | ||
_ = state.EntityManager.AddComponent<SystemData>(state.SystemHandle); | ||
} | ||
|
||
[BurstCompile] | ||
public void OnUpdate(ref SystemState state) | ||
{ | ||
if(!SystemAPI.TryGetSingleton<SpriteFrustumCullingSystem.CameraData>(out var cameraData)) | ||
return; | ||
|
||
var sysData = SystemAPI.GetComponentRW<SystemData>(state.SystemHandle); | ||
|
||
if(cameraData.CullingBounds2D != sysData.ValueRO.LastCameraBounds) | ||
{ | ||
sysData.ValueRW.LastCameraBounds = cameraData.CullingBounds2D; | ||
|
||
var recalculateSpriteJob = new RecalculateSpritesJob | ||
{ | ||
CameraPosition = cameraData.Position, | ||
ScreenSize = cameraData.CullingBounds2D.Size | ||
}; | ||
state.Dependency = recalculateSpriteJob.ScheduleByRef(state.Dependency); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters