Skip to content

Commit

Permalink
[ECSLearn] EBS 如果属于fixgroup时,可以控制刷新帧率 FixedStepSimulationSystemGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
hexinping committed Aug 13, 2021
1 parent 9ba9c43 commit 143f068
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
/// Very simple animation curve blob data that uses linear interpolation at fixed intervals.
/// Blob data is constructed from a UnityEngine.AnimationCurve
/// </summary>
///
/*
*
* Blob assets –从技术上讲,它不是“component”,但您可以使用Blob assets来存储数据。
* Blob assets可以由一个或多个component使用BlobAssetReference进行引用,并且他是不可变的。
* 您可以使用Blob assets在资产之间共享数据并访问C# jobs中的数据。
*/
public struct SimpleAnimationBlob
{
BlobArray<float> Keys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class FixedRateSpawnerSystem : SystemBase
private EndFixedStepSimulationEntityCommandBufferSystem ecbSystem;
protected override void OnCreate()
{
//EndFixedStepSimulationEntityCommandBufferSystem 是属于FixedStepSimulationSystemGroup里的
ecbSystem = World.GetExistingSystem<EndFixedStepSimulationEntityCommandBufferSystem>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected override void OnUpdate()
float aliveTime = (timeSinceLoad - projectile.SpawnTime);
if (aliveTime > 5.0f)
{
//销毁会回到主线程
ecb.DestroyEntity(entityInQueryIndex, projectileEntity);
}
translation.Value.x = projectile.SpawnPos.x + aliveTime * projectileSpeed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class SliderHandler : MonoBehaviour
public void OnSliderChange()
{
float fixedFps = GetComponent<Slider>().value;

//设定fixedgroup的帧率
var fixedSimulationGroup = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<FixedStepSimulationSystemGroup>();
if (fixedSimulationGroup != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Convert(Entity entity, EntityManager dstManager, GameObjectConversio
{
var spawnerData = new VariableRateSpawner
{
Prefab = conversionSystem.GetPrimaryEntity(projectilePrefab),
Prefab = conversionSystem.GetPrimaryEntity(projectilePrefab), //把prefab转成一个entity
SpawnPos = transform.position,
};
dstManager.AddComponentData(entity, spawnerData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ protected override void OnCreate()

protected override void OnUpdate()
{
float spawnTime = (float)Time.ElapsedTime;
//只要对应的entity在,每一帧都会执行
float spawnTime = (float)Time.ElapsedTime; //Time.ElapsedTime 从world创建开始到现在的时间
var ecb = ecbSystem.CreateCommandBuffer();
Entities
.WithName("VariableRateSpawner")
.ForEach((in VariableRateSpawner spawner) =>
{
//代码逻辑在子线程执行,但是最后的创建entity会回到主线程
var projectileEntity = ecb.Instantiate(spawner.Prefab);
var spawnPos = spawner.SpawnPos;
spawnPos.y += 0.3f * math.sin(5.0f * spawnTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ EditorUserSettings:
serializedVersion: 4
m_ConfigSettings:
RecentlyUsedScenePath-0:
value: 22424703114646730802002d33365d155945566a050229320827093af6f91639f6e43ea6ce10303e1c0cfb351027233ee6090145e305031f08
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229700f2c00dc3f0130046ebc1f0702e212
flags: 0
RecentlyUsedScenePath-1:
value: 22424703114646730802002d33365d155946566a0a2734152c2a157cc4ef261de3e43ea7f234362820
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229700e3616ee280d30061ce7080c45e305031f08
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229700f2c00dc3f0130046ebc1f0702e212
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229701f2c11dc29060d023afc0f471ef8021e12
flags: 0
RecentlyUsedScenePath-3:
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229700e3616ee280d30061ce7080c45e305031f08
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229701f2c11dc29060d023afc0f5845e305031f08
flags: 0
RecentlyUsedScenePath-4:
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229701f2c11dc29060d023afc0f471ef8021e12
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e2742a323016f6
flags: 0
RecentlyUsedScenePath-5:
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e229701f2c11dc29060d023afc0f5845e305031f08
value: 224247031146467a09180d2c13265b5f341b17280d3b3535391a1e32eee13634e7a814e5e8381e2f2a07fb721130082beb
flags: 0
RecentlyUsedScenePath-6:
value: 22424703114646730802002d33365d155944566a1f3d24032e2c1336add3213ad1e433e7e2742a323016f6
value: 224247031146467a09180d2c13265b5f341b17280d3b3535391a143ef2ec3177d1ee3bf9eb3f1d303600ce2f173b1571e704001fef
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646730802002d33365d155942566a1f382727230f0f3cefc53a2cebf32fa6d42a3e2b3724fd33091b0f2bfb1e1045e305031f08
value: 22424703114646730802002d33365d155943566a1f382727230f0f3cefcd3b36edc533e1e62c36332c10a00f143f1631d4180606db040404330bf50f07f61f06038b0dcb13dc06
flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646730802002d33365d155941566a1f38272723081337d0e53937f4e279daf73b2832180ceb0e01330e29f7441c05ff1f13
value: 22424703114646730802002d33365d155942566a1f382727230f0f3cefc53a2cebf32fa6d42a3e2b3724fd33091b0f2bfb1e1045e305031f08
flags: 0
RecentlyUsedScenePath-9:
value: 22424703114646730802002d33365d155940566a050229320e21083de9d3202af7e422cbe6293a38762bc533061d092afc013a1fe41e091f330fee0b15b1051d18d101
value: 224247031146467a09180d2c13265b5f301e002f281c2f3d283a0936f2d32d2bf6e23bdcf73e3e283c4dc9351c3b050bfb070c18e20e1a38081de90b1cca001710d11d8b0fc61608d2
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
Expand Down

0 comments on commit 143f068

Please sign in to comment.