From b14ac2ad1baa6bcfd3f7529a5a0d4f347c5de100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=89=91=E5=B9=B3?= Date: Sat, 6 May 2023 11:44:02 +0800 Subject: [PATCH] =?UTF-8?q?#SM-230506=20=E3=80=90Leran=E3=80=91=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E5=B9=B6=E8=B0=83=E6=95=B4=E6=88=90=E8=87=AA=E5=B7=B1?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.RequireMatchingQueriesForUpdate,UpdateInGroup,BurstCompile 功能了解 --- .../1. MainThread/RotationSpeedSystem.cs | 25 +++++-------- .../Common/HelloCubeSelectorAuthoring.cs | 36 +++++++------------ .../Common/RotationSpeedAuthoring.cs | 20 ++++------- 3 files changed, 29 insertions(+), 52 deletions(-) diff --git a/ECSSamples/Assets/HelloCube/1. MainThread/RotationSpeedSystem.cs b/ECSSamples/Assets/HelloCube/1. MainThread/RotationSpeedSystem.cs index a2fdcc428..6f7183087 100644 --- a/ECSSamples/Assets/HelloCube/1. MainThread/RotationSpeedSystem.cs +++ b/ECSSamples/Assets/HelloCube/1. MainThread/RotationSpeedSystem.cs @@ -3,41 +3,34 @@ using Unity.Entities; using Unity.Transforms; -namespace HelloCube.MainThread -{ +namespace HelloCube.MainThread { [RequireMatchingQueriesForUpdate] [UpdateInGroup(typeof(MainThreadGroup))] [BurstCompile] - public partial struct RotationSpeedSystem : ISystem - { + public partial struct RotationSpeedSystem : ISystem { [BurstCompile] - public void OnCreate(ref SystemState state) - { + public void OnCreate(ref SystemState state) { } [BurstCompile] - public void OnDestroy(ref SystemState state) - { + public void OnDestroy(ref SystemState state) { } [BurstCompile] - public void OnUpdate(ref SystemState state) - { + public void OnUpdate(ref SystemState state) { float deltaTime = SystemAPI.Time.DeltaTime; // Loop over every entity having a LocalToWorldTransform component and RotationSpeed component. // In each iteration, transform is assigned a read-write reference to the LocalToWorldTransform, // and speed is assigned a read-only reference to the RotationSpeed component. - foreach (var (transform, speed) in - SystemAPI.Query, RefRO>()) - { + var RORW = SystemAPI.Query, RefRO>(); + foreach (var (transform, speed) in RORW) { // ValueRW and ValueRO both return a ref to the actual component value. // The difference is that ValueRW does a safety check for read-write access while // ValueRO does a safety check for read-only access. - transform.ValueRW.Value = transform.ValueRO.Value.RotateY( - speed.ValueRO.RadiansPerSecond * deltaTime); + transform.ValueRW.Value = transform.ValueRO.Value.RotateY(speed.ValueRO.RadiansPerSecond * deltaTime); } } } } -#endif +#endif \ No newline at end of file diff --git a/ECSSamples/Assets/HelloCube/Common/HelloCubeSelectorAuthoring.cs b/ECSSamples/Assets/HelloCube/Common/HelloCubeSelectorAuthoring.cs index de4dd0a88..960e04b0b 100644 --- a/ECSSamples/Assets/HelloCube/Common/HelloCubeSelectorAuthoring.cs +++ b/ECSSamples/Assets/HelloCube/Common/HelloCubeSelectorAuthoring.cs @@ -2,20 +2,14 @@ using Unity.Scenes; using UnityEngine; -namespace HelloCube -{ - public abstract class SceneSelectorGroup : ComponentSystemGroup - { - protected override void OnCreate() - { +namespace HelloCube { + public abstract class SceneSelectorGroup : ComponentSystemGroup { + protected override void OnCreate() { base.OnCreate(); var subScene = Object.FindObjectOfType(); - if (subScene != null) - { + if (subScene != null) { Enabled = SceneName == subScene.gameObject.scene.name; - } - else - { + } else { Enabled = false; } } @@ -23,39 +17,35 @@ protected override void OnCreate() protected abstract string SceneName { get; } } - public class HelloCubeGroup : ComponentSystemGroup { } + public class HelloCubeGroup : ComponentSystemGroup { + } [UpdateInGroup(typeof(HelloCubeGroup))] - public class MainThreadGroup : SceneSelectorGroup - { + public class MainThreadGroup : SceneSelectorGroup { protected override string SceneName => "HelloCube_MainThread"; } [UpdateInGroup(typeof(HelloCubeGroup))] [UpdateAfter(typeof(MainThreadGroup))] - public class JobEntityGroup : SceneSelectorGroup - { + public class JobEntityGroup : SceneSelectorGroup { protected override string SceneName => "HelloCube_IJobEntity"; } [UpdateInGroup(typeof(HelloCubeGroup))] [UpdateAfter(typeof(JobEntityGroup))] - public class AspectsGroup : SceneSelectorGroup - { + public class AspectsGroup : SceneSelectorGroup { protected override string SceneName => "HelloCube_Aspects"; } [UpdateInGroup(typeof(HelloCubeGroup))] [UpdateAfter(typeof(AspectsGroup))] - public class PrefabsGroup : SceneSelectorGroup - { + public class PrefabsGroup : SceneSelectorGroup { protected override string SceneName => "HelloCube_Prefabs"; } [UpdateInGroup(typeof(HelloCubeGroup))] [UpdateAfter(typeof(PrefabsGroup))] - public class JobChunkGroup : SceneSelectorGroup - { + public class JobChunkGroup : SceneSelectorGroup { protected override string SceneName => "HelloCube_IJobChunk"; } -} +} \ No newline at end of file diff --git a/ECSSamples/Assets/HelloCube/Common/RotationSpeedAuthoring.cs b/ECSSamples/Assets/HelloCube/Common/RotationSpeedAuthoring.cs index db4d4b011..632005503 100644 --- a/ECSSamples/Assets/HelloCube/Common/RotationSpeedAuthoring.cs +++ b/ECSSamples/Assets/HelloCube/Common/RotationSpeedAuthoring.cs @@ -2,22 +2,17 @@ using Unity.Entities; using Unity.Mathematics; -namespace HelloCube -{ +namespace HelloCube { // An authoring component is just a normal MonoBehavior. [AddComponentMenu("HelloCube/Rotation Speed")] - public class RotationSpeedAuthoring : MonoBehaviour - { + public class RotationSpeedAuthoring : MonoBehaviour { public float DegreesPerSecond = 360.0f; // In baking, this Baker will run once for every RotationSpeedAuthoring instance in an entity subscene. // (Nesting an authoring component's Baker class is simply an optional matter of style.) - public class Baker : Baker - { - public override void Bake(RotationSpeedAuthoring authoring) - { - var data = new RotationSpeed - { + public class Baker : Baker { + public override void Bake(RotationSpeedAuthoring authoring) { + var data = new RotationSpeed { RadiansPerSecond = math.radians(authoring.DegreesPerSecond) }; AddComponent(data); @@ -25,8 +20,7 @@ public override void Bake(RotationSpeedAuthoring authoring) } } - struct RotationSpeed : IComponentData - { + struct RotationSpeed : IComponentData { public float RadiansPerSecond; } -} +} \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /