-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using RMC.DOTS.Systems.StateMachine; | ||
using Unity.Entities; | ||
using Unity.Mathematics; | ||
using UnityEngine; | ||
|
||
namespace RMC.DOTS.Demos.StateMachine.Light | ||
{ | ||
public class MyMovementEntityTagAuthoring : MonoBehaviour | ||
{ | ||
public Vector3 RotationDelta = new float3(0, 1f, 0); | ||
public float RotationDurationInSeconds = 1; | ||
|
||
[Header("Translation")] | ||
public Vector3 TranslationDelta = new float3(0, 0.5f, 0); | ||
public float TranslationDurationInSeconds = 1; | ||
|
||
public class Test01AuthoringBaker : Baker<MyMovementEntityTagAuthoring> | ||
{ | ||
public override void Bake(MyMovementEntityTagAuthoring authoring) | ||
{ | ||
var entity = GetEntity(TransformUsageFlags.Dynamic); | ||
|
||
// TODO: Remove this? How else can I turn on the first state easily? | ||
//(This is more of a "how to easily find an entity?" question than an SM question) | ||
AddComponent<MyMovementEntityTag>(entity); | ||
|
||
//Give this entity 1) an ID and 2) a state to be in | ||
AddComponent<StateID>(entity); | ||
AddComponent<MyMovementStateSystemTag>(entity); | ||
|
||
AddComponent<RotationComponent>(entity, | ||
new RotationComponent() | ||
{ | ||
RotationDelta = authoring.RotationDelta, | ||
DurationInSeconds = authoring.RotationDurationInSeconds | ||
}); | ||
|
||
AddComponent<TranslationComponent>(entity, | ||
new TranslationComponent() | ||
{ | ||
TranslationDelta = authoring.TranslationDelta, | ||
DurationInSeconds = authoring.TranslationDurationInSeconds | ||
}); | ||
|
||
} | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "RMC.DOTS.Demos.StateMachine01_Light.Runtime", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:d28bf24cef16ed84cb4cb180b9c77ac3", | ||
"GUID:330ce21097b4d554fa95a74295bc3b8f", | ||
"GUID:2665a8d13d1b3f18800f46e256720795", | ||
"GUID:734d92eba21c94caba915361bd5ac177", | ||
"GUID:63afb046c8423dd448ae7aba042ea63d", | ||
"GUID:a5baed0c9693541a5bd947d336ec7659", | ||
"GUID:e0cd26848372d4e5c891c569017e11f1", | ||
"GUID:d8b63aba1907145bea998dd612889d6b", | ||
"GUID:5f3cf485eb0554709a8abbeace890c86", | ||
"GUID:8819f35a0fc84499b990e90a4ca1911f", | ||
"GUID:75469ad4d38634e559750d17036d5f7c", | ||
"GUID:f2381d29563bc3c49ab35691478f3482" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using RMC.DOTS.Systems.StateMachine; | ||
using UnityEngine; | ||
using Unity.Entities; | ||
|
||
namespace RMC.DOTS.Demos.StateMachine.Light | ||
{ | ||
public class MyMovementBaseState : StateMachineSystemBase.State | ||
{ | ||
protected float StateElapsedTimeInSeconds { get; private set; } | ||
|
||
protected virtual void RequestStateChangePerTransitions(Entity entity) | ||
{ | ||
// Toggle | ||
if (IsInState<MyMovementRotationState>(entity)) | ||
{ | ||
RequestStateChange<MyMovementTranslationState>(entity); | ||
} | ||
else if (IsInState<MyMovementTranslationState>(entity)) | ||
{ | ||
RequestStateChange<MyMovementRotationState>(entity); | ||
} | ||
else | ||
{ | ||
Debug.LogError("Unknown State"); | ||
} | ||
} | ||
|
||
public override void OnEnter(Entity entity) | ||
{ | ||
base.OnEnter(entity); | ||
StateElapsedTimeInSeconds = 0; | ||
Debug.LogFormat("{0}.OnEnter() {1}\n\n", entity.ToString(), GetType().Name); | ||
} | ||
|
||
public override void OnUpdate(Entity entity) | ||
{ | ||
base.OnUpdate(entity); | ||
StateElapsedTimeInSeconds += World.Time.DeltaTime; | ||
//Debug.LogFormat("{0}.OnUpdate() {1}\n\n", entity.ToString(), GetType().Name); | ||
} | ||
|
||
public override void OnExit(Entity entity) | ||
{ | ||
base.OnExit(entity); | ||
//Debug.LogFormat("{0}.OnExit() {1}\n\n", entity.ToString(), GetType().Name); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using RMC.DOTS.Systems.StateMachine; | ||
|
||
namespace RMC.DOTS.Demos.StateMachine.Light | ||
{ | ||
partial class MyMovementStateMachineSystem : StateMachineSystem<MyMovementStateSystemTag> | ||
{ | ||
protected override void OnCreate() | ||
{ | ||
base.OnCreate(); | ||
|
||
//Requires | ||
RequireForUpdate<RotationComponent>(); | ||
RequireForUpdate<TranslationComponent>(); | ||
|
||
//Registers | ||
RegisterState<MyMovementTranslationState>(); | ||
RegisterState<MyMovementRotationState>(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using RMC.DOTS.Systems.StateMachine; | ||
using Unity.Entities; | ||
|
||
namespace RMC.DOTS.Demos.StateMachine.Light | ||
{ | ||
struct MyMovementStateSystemTag : IComponentData{} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.