Пример #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var transforms = m_TransformGroup.GetTransformAccessArray();
            var entities   = m_TransformGroup.GetEntityArray();

            var transformStashes   = new NativeArray <TransformStash>(transforms.Length, Allocator.TempJob);
            var stashTransformsJob = new StashTransforms
            {
                transformStashes = transformStashes
            };

            var stashTransformsJobHandle = stashTransformsJob.Schedule(transforms, inputDeps);

            var copyTransformsJob = new CopyTransforms
            {
                positions        = m_Positions,
                rotations        = m_Rotations,
                localPositions   = m_LocalPositions,
                localRotations   = m_LocalRotations,
                transformStashes = transformStashes,
                entities         = entities
            };

            return(copyTransformsJob.Schedule(transformStashes.Length, 64, stashTransformsJobHandle));
        }
Пример #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var transforms = m_InitialTransformGroup.GetTransformAccessArray();
            var entities   = m_InitialTransformGroup.GetEntityArray();

            var transformStashes   = new NativeArray <TransformStash>(transforms.length, Allocator.TempJob);
            var stashTransformsJob = new StashTransforms
            {
                transformStashes = transformStashes
            };

            var stashTransformsJobHandle = stashTransformsJob.Schedule(transforms, inputDeps);

            var copyTransformsJob = new CopyTransforms
            {
                positions        = m_Positions,
                rotations        = m_Rotations,
                localPositions   = m_LocalPositions,
                localRotations   = m_LocalRotations,
                transformStashes = transformStashes,
                entities         = entities
            };

            var copyTransformsJobHandle = copyTransformsJob.Schedule(transformStashes.Length, 64, stashTransformsJobHandle);

            var removeComponentsJob = new RemoveCopyInitialTransformFromGameObjectComponent
            {
                entities            = entities,
                entityCommandBuffer = m_EndFrameBarrier.CreateCommandBuffer()
            };
            var removeComponentsJobHandle = removeComponentsJob.Schedule(copyTransformsJobHandle);

            return(removeComponentsJobHandle);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var transforms = m_InitialTransformGroup.GetTransformAccessArray();
            var entities   = m_InitialTransformGroup.ToEntityArray(Allocator.TempJob);

            var transformStashes   = new NativeArray <TransformStash>(transforms.length, Allocator.TempJob);
            var stashTransformsJob = new StashTransforms
            {
                transformStashes = transformStashes
            };

            var stashTransformsJobHandle = stashTransformsJob.Schedule(transforms, inputDeps);

            var copyTransformsJob = new CopyTransforms
            {
                transformStashes = transformStashes,
            };

            var copyTransformsJobHandle = copyTransformsJob.ScheduleGroup(m_InitialTransformGroup, stashTransformsJobHandle);

            var removeComponentsJob = new RemoveCopyInitialTransformFromGameObjectComponent
            {
                entities            = entities,
                entityCommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer()
            };
            var removeComponentsJobHandle = removeComponentsJob.Schedule(copyTransformsJobHandle);

            m_EntityCommandBufferSystem.AddJobHandleForProducer(removeComponentsJobHandle);
            return(removeComponentsJobHandle);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var transforms = m_TransformGroup.GetTransformAccessArray();
            var entities   = m_TransformGroup.ToEntityArray(Allocator.TempJob);

            var copyTransformsJob = new CopyTransforms
            {
                LocalToWorlds = GetComponentDataFromEntity <LocalToWorld>(true),
                entities      = entities
            };

            return(copyTransformsJob.Schedule(transforms, inputDeps));
        }
Пример #5
0
        protected override void OnUpdate()
        {
            // Enumerate all the instance data entries.
            EntityManager.GetAllUniqueSharedComponentDatas(_instanceDatas);
            foreach (var instanceData in _instanceDatas)
            {
                // Skip if it has no data.
                if (instanceData.templateMesh == null)
                {
                    continue;
                }

                // Get a copy of the instance entity array.
                // Don't directly use the iterator -- we're going to remove
                // the instance components, and it will invalidate the iterator.
                _instanceGroup.SetFilter(instanceData);
                var iterator = _instanceGroup.GetEntityArray();
                if (iterator.Length == 0)
                {
                    continue;
                }
                var instanceEntities = new NativeArray <Entity>(iterator.Length, Allocator.Temp);
                iterator.CopyTo(instanceEntities);

                // Accessor to the scene transform
                var transforms = _instanceGroup.GetTransformAccessArray();

                // Retrieve the mesh data.
                var vertices = instanceData.templateMesh.vertices;
                var indices  = instanceData.templateMesh.triangles;

                // Instantiate flies along with the instance entities.
                for (var instanceIndex = 0; instanceIndex < instanceEntities.Length; instanceIndex++)
                {
                    var instanceEntity = instanceEntities[instanceIndex];

                    Instantiate(
                        transforms[instanceIndex],
                        EntityManager.GetSharedComponentData <RenderSettings>(instanceEntity),
                        vertices, indices
                        );

                    // Remove the instance component from the entity.
                    EntityManager.RemoveComponent(instanceEntity, typeof(Instance));
                }

                instanceEntities.Dispose();
            }

            _instanceDatas.Clear();
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var transforms = m_TransformGroup.GetTransformAccessArray();
            var entities   = m_TransformGroup.GetEntityArray();

            var copyTransformsJob = new CopyTransforms
            {
                positions = GetComponentDataFromEntity <Position>(true),
                rotations = GetComponentDataFromEntity <Rotation>(true),
                entities  = entities
            };

            return(copyTransformsJob.Schedule(transforms, inputDeps));
        }
Пример #7
0
        protected override void OnUpdate()
        {
            var c_entity         = camera.GetEntityArray();
            var c_transform      = camera.GetTransformAccessArray();
            var c_positionOffset = camera.GetComponentDataArray <PositionOffset>();
            var c_trackingSpeed  = camera.GetComponentDataArray <TrackingSpeed>();

            var p_position = player.GetComponentDataArray <Position>();

            c_transform[0].position = Vector3.Lerp(
                c_transform[0].position,
                c_positionOffset[0].Value + p_position[0].Value,
                c_trackingSpeed[0].Value * Time.fixedDeltaTime
                );
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var transforms = m_TransformGroup.GetTransformAccessArray();
            var entities   = m_TransformGroup.GetEntityArray();

            var copyTransformsJob = new CopyTransforms
            {
                positions = m_Positions,
                rotations = m_Rotations,
                entities  = entities
            };

            var resultDeps = copyTransformsJob.Schedule(transforms, inputDeps);

            return(resultDeps);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var transforms         = m_TransformGroup.GetTransformAccessArray();
            var transformStashes   = new NativeArray <TransformStash>(transforms.length, Allocator.TempJob);
            var stashTransformsJob = new StashTransforms
            {
                transformStashes = transformStashes
            };

            var stashTransformsJobHandle = stashTransformsJob.Schedule(transforms, inputDeps);

            var copyTransformsJob = new CopyTransforms
            {
                transformStashes = transformStashes,
            };

            return(copyTransformsJob.ScheduleGroup(m_TransformGroup, stashTransformsJobHandle));
        }
Пример #10
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            this.DisposeBuffers();
            var handle = inputDeps;

            var isUpdateCenter = this._updateCenterGroup.CalculateLength() > 0;
            var handles        = new NativeArray <JobHandle>(isUpdateCenter ? 3 : 2, Allocator.Temp);

            // コライダーの更新
            {
                this._colliderHashMap = new NativeMultiHashMap <int, SphereCollider>(
                    this._sphereColliderGroup.CalculateLength(), Allocator.TempJob);
                handles[0] = new UpdateColliderHashJob
                {
                    Entities = this._colliderGroup.GetEntityArray(),
                    ColliderGroupInstanceIDs        = base.GetComponentDataFromEntity <ColliderGroupInstanceID>(true),
                    ColliderGroupBlittableFieldsPtr =
                        base.GetComponentDataFromEntity <ColliderGroupBlittableFieldsPtr>(true),
                    ColliderHashMap = this._colliderHashMap.ToConcurrent(),
                }.Schedule(this._colliderGroup.GetTransformAccessArray());
            }

            // 回転値の更新
            {
                handles[1] = new UpdateRotationJob
                {
                    Entities  = this._spriteBoneGroup.GetEntityArray(),
                    Rotations = base.GetComponentDataFromEntity <Rotation>(),
                }.Schedule(this._spriteBoneGroup.GetTransformAccessArray());
            }

            // m_centerの更新
            if (isUpdateCenter)
            {
                handles[2] = new UpdateCenterJob
                {
                    Entities = this._updateCenterGroup.GetEntityArray(),
                    Centers  = base.GetComponentDataFromEntity <Center>(),
                }.Schedule(this._updateCenterGroup.GetTransformAccessArray());
            }

            // 物理演算
            {
                var preHandle = JobHandle.CombineDependencies(handle, JobHandle.CombineDependencies(handles));
                handle = new LogicJob
                {
                    Entities = this._spriteBoneGroup.GetEntityArray(),

                    SpringBoneBlittableFieldsPtr = base.GetComponentDataFromEntity <SpringBoneBlittableFieldsPtr>(true),
                    Lengths        = base.GetComponentDataFromEntity <Length>(true),
                    LocalRotations = base.GetComponentDataFromEntity <LocalRotation>(true),
                    BoneAxes       = base.GetComponentDataFromEntity <BoneAxis>(true),
                    ParentEntities = base.GetComponentDataFromEntity <ParentEntity>(true),
                    Rotations      = base.GetComponentDataFromEntity <Rotation>(true),

                    Centers        = base.GetComponentDataFromEntity <Center>(true),
                    CenterEntities = base.GetComponentDataFromEntity <CenterEntity>(true),

                    CurrentTails = base.GetComponentDataFromEntity <CurrentTail>(),
                    PrevTails    = base.GetComponentDataFromEntity <PrevTail>(),

                    DeltaTime       = Time.deltaTime,
                    ColliderHashMap = this._colliderHashMap,
                }.Schedule(_spriteBoneGroup.GetTransformAccessArray(), preHandle);
            }
            handles.Dispose();
            return(handle);
        }
Пример #11
0
        protected override void OnUpdate()
        {
            // Enumerate all the instance data entries.
            EntityManager.GetAllUniqueSharedComponentDatas(_instanceDatas);
            foreach (var instanceData in _instanceDatas)
            {
                // Skip if it has no data.
                if (instanceData.templateMesh == null)
                {
                    continue;
                }

                // Get a copy of the instance entity array.
                // Don't directly use the iterator -- we're going to remove
                // the instance components, and it will invalidate the iterator.
                _instanceGroup.SetFilter(instanceData);
                var iterator = _instanceGroup.GetEntityArray();
                if (iterator.Length == 0)
                {
                    continue;
                }
                var instanceEntities = new NativeArray <Entity>(iterator.Length, Allocator.Temp);
                iterator.CopyTo(instanceEntities);

                // Accessor to the scene transform
                var transforms = _instanceGroup.GetTransformAccessArray();

                // Retrieve the mesh data.
                var vertices = instanceData.templateMesh.vertices;
                var indices  = instanceData.templateMesh.triangles;

                // Instantiate flies along with the instance entities.
                for (var j = 0; j < instanceEntities.Length; j++)
                {
                    // Retrieve the source data.
                    var instanceEntity = instanceEntities[j];

                    // Create a renderer for this group.
                    var renderer = new Renderer();
                    renderer.Settings = EntityManager.GetSharedComponentData <RenderSettings>(instanceEntity);
                    renderer.WorkMesh = new UnityEngine.Mesh();
                    renderer.Vertices = new NativeArray <float3>(Renderer.kMaxVertices, Allocator.Persistent);
                    renderer.Normals  = new NativeArray <float3>(Renderer.kMaxVertices, Allocator.Persistent);
                    renderer.Counter  = new NativeCounter(Allocator.Persistent);

                    _toBeDisposed.Add(renderer);

                    // Calculate the transform matrix.
                    var transform = transforms[j];
                    var matrix    = (float4x4)UnityEngine.Matrix4x4.TRS(
                        transform.position, transform.rotation, transform.localScale
                        );

                    // Populate entities.
                    for (var vi = 0; vi < indices.Length; vi += 3)
                    {
                        var v1 = math.mul(matrix, new float4(vertices[indices[vi + 0]], 1)).xyz;
                        var v2 = math.mul(matrix, new float4(vertices[indices[vi + 1]], 1)).xyz;
                        var v3 = math.mul(matrix, new float4(vertices[indices[vi + 2]], 1)).xyz;
                        var vc = (v1 + v2 + v3) / 3;

                        var entity = EntityManager.CreateEntity(_archetype);

                        EntityManager.SetComponentData(entity, new Facet {
                            Vertex1 = v1 - vc,
                            Vertex2 = v2 - vc,
                            Vertex3 = v3 - vc
                        });

                        EntityManager.SetComponentData(entity, new Position {
                            Value = vc
                        });

                        EntityManager.SetSharedComponentData(entity, renderer);
                    }

                    // Remove the instance component from the entity.
                    EntityManager.RemoveComponent(instanceEntity, typeof(Instance));
                }

                instanceEntities.Dispose();
            }

            _instanceDatas.Clear();
        }
Пример #12
0
        protected override void OnUpdate()
        {
            //
            // There are three levels of loops in this system:
            //
            // Loop 1: Through the array of unique instance settings. We'll get
            // an array of entities that share the same instance setting.
            //
            // Loop 2: Through the array of entities got in Loop 1.
            //
            // Loop 3: Through the array of vertices in the template mesh given
            // via the instance setting.
            //

            // Loop 1: Iterate over the unique instance data entries.
            EntityManager.GetAllUniqueSharedComponentDatas(_instanceDatas);
            foreach (var instanceData in _instanceDatas)
            {
                // Skip if it doesn't have any data.
                if (instanceData.TemplateMesh == null)
                {
                    continue;
                }

                // Get a copy of the entity array. We shouldn't directly use
                // the iterator because we're going to remove the instance
                // components that invalidates the iterator.
                _instanceGroup.SetFilter(instanceData);

                var iterator = _instanceGroup.GetEntityArray();
                if (iterator.Length == 0)
                {
                    continue;
                }

                var instanceEntities = new NativeArray <Entity>(
                    iterator.Length, Allocator.Temp,
                    NativeArrayOptions.UninitializedMemory
                    );
                iterator.CopyTo(instanceEntities);

                // Accessor to the scene transforms
                var transforms = _instanceGroup.GetTransformAccessArray();

                // Retrieve the template mesh data.
                var vertices = instanceData.TemplateMesh.vertices;
                var indices  = instanceData.TemplateMesh.triangles;

                // Loop 2: Iterate over the instance entities.
                for (var i = 0; i < instanceEntities.Length; i++)
                {
                    var instanceEntity   = instanceEntities[i];
                    var rendererSettings = EntityManager.
                                           GetSharedComponentData <RenderSettings>(instanceEntity);

                    // Loop 3: Iterate over the vertices in the template mesh.
                    CreateEntitiesOverMesh(
                        transforms[i], rendererSettings, vertices, indices
                        );

                    // Remove the instance component from the entity.
                    EntityManager.RemoveComponent(instanceEntity, typeof(Instance));
                }

                instanceEntities.Dispose();
            }

            _instanceDatas.Clear();
        }