Last active
May 6, 2020 16:28
-
-
Save jeffvella/57da54567c7127be4fff7e124a97f5f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct MovementData | |
{ | |
public float SomethingRelevent; | |
} | |
[StructLayout(LayoutKind.Explicit)] | |
public unsafe struct Movement : IComponentData,IMovementBehavior | |
{ | |
public enum MovementType : int | |
{ | |
None = 0, | |
Stumbling, | |
Running, | |
Idle | |
} | |
[FieldOffset(0)] | |
public MovementType Type; | |
[FieldOffset(4)] | |
public MovementData Data; | |
[FieldOffset(4)] | |
private StumblingBehavior _stumbling; | |
[FieldOffset(4)] | |
private RunningBehavior _running; | |
[FieldOffset(4)] | |
private IdleBehavior _idle; | |
public void Move() | |
{ | |
switch (Type) | |
{ | |
case MovementType.None: | |
break; | |
case MovementType.Stumbling: | |
_stumbling.Move(); | |
break; | |
case MovementType.Running: | |
_running.Move(); | |
break; | |
case MovementType.Idle: | |
_idle.Move(); | |
break; | |
default: | |
throw new ArgumentOutOfRangeException(); | |
} | |
} | |
} | |
public interface IMovementBehavior | |
{ | |
void Move(); | |
} | |
public struct StumblingBehavior : IMovementBehavior | |
{ | |
public MovementData Data; | |
public void Move() {} | |
} | |
public struct RunningBehavior : IMovementBehavior | |
{ | |
public MovementData Data; | |
public void Move() {} | |
} | |
public struct IdleBehavior : IMovementBehavior | |
{ | |
public MovementData Data; | |
public void Move() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment