Skip to content

Commit

Permalink
【ECSLearn】 update
Browse files Browse the repository at this point in the history
  • Loading branch information
hexinping committed Aug 16, 2021
1 parent 621268a commit 6703ffc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ protected override void OnUpdate()
Center = boidSchoolLocalToWorld.Position,
Radius = boidSchool.InitialRadius
};

//这个参数不是很明白
Dependency = setBoidLocalToWorldJob.Schedule(boidSchool.Count, 64, Dependency);
Dependency = boidEntities.Dispose(Dependency);

EntityManager.DestroyEntity(entity);
}).Run();
}).Run(); //主线程执行 不會效率低吗
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)

public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
//给鱼群的Entity加上BoidSchool组件
dstManager.AddComponentData(entity, new BoidSchool
{
Prefab = conversionSystem.GetPrimaryEntity(Prefab),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// This system updates all entities in the scene with both a RotationSpeed_IJobChunk and Rotation component.

// ReSharper disable once InconsistentNaming
//[DisableAutoCreation] 禁止自动创建
public partial class RotationSpeedSystem_IJobChunk : SystemBase
{
EntityQuery m_Query;
Expand Down Expand Up @@ -42,7 +43,14 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
Value = math.mul(math.normalize(rotation.Value),
quaternion.AxisAngle(math.up(), rotationSpeed.RadiansPerSecond * DeltaTime))
};

}

//其他写法
// var chunkRotations1
// = batchInChunk.GetChunkComponentData(RotationTypeHandle);
// batchInChunk.SetChunkComponentData(RotationTypeHandle,
// new Rotation() { Value = new quaternion(0,0,0,0) });
}
}

Expand All @@ -61,7 +69,8 @@ protected override void OnUpdate()
RotationSpeedTypeHandle = rotationSpeedType,
DeltaTime = Time.DeltaTime
};


//这种调度变体将每个匹配块作为单个批处理。每个块都可以并行执行, 效率很高
Dependency = job.ScheduleParallel(m_Query, 1, Dependency);
}
}

0 comments on commit 6703ffc

Please sign in to comment.