Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

#SM-230506 【Leran】阅读并调整成自己的代码格式 #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions ECSSamples/Assets/HelloCube/1. MainThread/RotationSpeedSystem.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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<RefRW<LocalToWorldTransform>, RefRO<RotationSpeed>>())
{
var RORW = SystemAPI.Query<RefRW<LocalToWorldTransform>, RefRO<RotationSpeed>>();
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
36 changes: 13 additions & 23 deletions ECSSamples/Assets/HelloCube/Common/HelloCubeSelectorAuthoring.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,50 @@
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<SubScene>();
if (subScene != null)
{
if (subScene != null) {
Enabled = SceneName == subScene.gameObject.scene.name;
}
else
{
} else {
Enabled = false;
}
}

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";
}
}
}
20 changes: 7 additions & 13 deletions ECSSamples/Assets/HelloCube/Common/RotationSpeedAuthoring.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@
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<RotationSpeedAuthoring>
{
public override void Bake(RotationSpeedAuthoring authoring)
{
var data = new RotationSpeed
{
public class Baker : Baker<RotationSpeedAuthoring> {
public override void Bake(RotationSpeedAuthoring authoring) {
var data = new RotationSpeed {
RadiansPerSecond = math.radians(authoring.DegreesPerSecond)
};
AddComponent(data);
}
}
}

struct RotationSpeed : IComponentData
{
struct RotationSpeed : IComponentData {
public float RadiansPerSecond;
}
}
}

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