Coder Social home page Coder Social logo

pushing-unity's Introduction

Pushing Unity's rendering capabilities to the max!

The project contains all 9 levels featured in the video https://youtu.be/6mNj3M1il_c

Some techniques used:

Unity DOTS (burst, jobs, ecs)
RenderMeshInstanced
DrawMeshInstancedIndirect
Data-Oriented Design
Avoiding extern calls

Leave a ⭐ if you found it helpful!

pushing-unity's People

Contributors

matthew-j-spencer 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  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

pushing-unity's Issues

[SOLVED] Fixes to PlayerSpawnerSystem and MoveToPositionAspect class when upgrading ECS packages

Replace existing code with the below, if you are getting error. AspectTransform is not found.

using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

public readonly partial struct MoveToPositionAspect : IAspect
{
    public readonly Entity Self;
    readonly RefRW<LocalTransform> Transform;
    private readonly RefRO<TargetPositionComponent> _targetPosition;

    public float3 Position
    {
        get => Transform.ValueRO.Position;
        set => Transform.ValueRW.Position = value;
    }

    public Unity.Mathematics.quaternion Rotation
    {
        get => Transform.ValueRO.Rotation;
        set => Transform.ValueRW.Rotation = value;
    }

    public void Move(float time)
    {
        var (pos, rot) = CalculatePosBurst(Position,_targetPosition.ValueRO.Value.y, time);

        Rotation = rot;
        Position = pos;
    }

    //this is a hack. Copied extenstion code and put here
    public (float3 pos, Unity.Mathematics.quaternion rot) CalculatePosBurst(float3 pos, float yOffset, float time)
    {
        var t = math.unlerp(yOffset, SceneTools.BURST_HEIGHT_SCALE + yOffset, pos.y);
        pos.y = SceneTools.BURST_HEIGHT_SCALE * noise.cnoise(new float2(pos.x * SceneTools.NOISE_SCALE + time, pos.z * SceneTools.NOISE_SCALE + time)) +
                yOffset * SceneTools.DEPTH_OFFSET;
        var rot = math.nlerp(quaternion.identity, SceneTools.RotGoal, t);
        return (pos, rot);
    }}
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Transforms;

[BurstCompile]
[DisableAutoCreation]
public partial class PlayerSpawnerSystem : SystemBase
{
    protected override void OnUpdate()
    {
        // This is bad code. Can somebody tell me how to instantiate entities at a position using a command buffer?
        /*if (EntityManager.CreateEntityQuery(typeof(TargetPositionComponent)).CalculateEntityCount() != 0)
        {
            foreach (var (aspect, targetPos) in SystemAPI.Query<AspectTransform, TargetPositionComponent>())
            {
                aspect.Position = targetPos.Value;
            }

            Enabled = false;
            return;
        }*/

        // Create a query to get entities with TargetPositionComponent
        var targetPositionQuery = GetEntityQuery(typeof(TargetPositionComponent));

        if (targetPositionQuery.CalculateEntityCount() != 0)
        {
            // Create a native array to hold entities with both components
            using (var entities = targetPositionQuery.ToEntityArray(Allocator.TempJob))
            {
                // Iterate over each entity and set its position
                Entities.WithAll<LocalTransform>().ForEach((Entity entity, ref LocalTransform translation, in TargetPositionComponent targetPos) =>
                {
                    // Check if the entity has TargetPositionComponent
                    if (entities.Contains(entity))
                    {
                        // Set the position of the entity to the target position
                        translation.Position = targetPos.Value;
                    }
                }).Run();
            }

            // Disable the system
            Enabled = false;
        }



        var buffer = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>().CreateCommandBuffer(World.Unmanaged);
        var prefab = SystemAPI.GetSingleton<PlayerSpawnerComponent>().PlayerPrefab;
        SceneTools.LoopPositions((i, p) =>
        {
            var entity = buffer.Instantiate(prefab);
            buffer.SetComponent(entity, new TargetPositionComponent
            {
                Value = p
            });
        });
    }
}

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.