Created
October 31, 2021 13:29
-
-
Save JohnnyTurbo/95a7a761e4979e091f9700016f302e00 to your computer and use it in GitHub Desktop.
Code used in System Lifecycle tutorial video on the Turbo Makes Games YouTube Channel - https://youtu.be/pViD_h8NXf0
This file contains hidden or 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
using Unity.Entities; | |
namespace TMG.SystemLifecycle | |
{ | |
[GenerateAuthoringComponent] | |
public struct CapsuleTag : IComponentData {} | |
} |
This file contains hidden or 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
using Unity.Entities; | |
using UnityEngine; | |
namespace TMG.SystemLifecycle | |
{ | |
[DisableAutoCreation] | |
public class IntroSystem : SystemBase | |
{ | |
protected override void OnCreate() | |
{ | |
Debug.Log("OnCreate()"); | |
} | |
protected override void OnStartRunning() | |
{ | |
Debug.Log("OnStartRunning()"); | |
} | |
protected override void OnUpdate() | |
{ | |
Debug.Log("OnUpdate()"); | |
Entities.WithAll<CapsuleTag>().ForEach((Entity e) => | |
{ | |
}).Run(); | |
} | |
protected override void OnStopRunning() | |
{ | |
Debug.Log("OnStopRunning()"); | |
} | |
protected override void OnDestroy() | |
{ | |
Debug.Log("OnDestroy()"); | |
} | |
} | |
} | |
This file contains hidden or 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
using Unity.Entities; | |
namespace TMG.SystemLifecycle | |
{ | |
[GenerateAuthoringComponent] | |
public struct SpawnCapsuleData : IComponentData | |
{ | |
public Entity CapsulePrefab; | |
} | |
} |
This file contains hidden or 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
using Unity.Entities; | |
using UnityEngine; | |
namespace TMG.SystemLifecycle | |
{ | |
public class SpawnCapsuleSystem : SystemBase | |
{ | |
private SpawnCapsuleData _spawnCapsuleData; | |
private Entity _spawnedCapsule; | |
protected override void OnStartRunning() | |
{ | |
_spawnCapsuleData = GetSingleton<SpawnCapsuleData>(); | |
} | |
protected override void OnUpdate() | |
{ | |
if (Input.GetKeyDown(KeyCode.Alpha1)) | |
{ | |
_spawnedCapsule = EntityManager.Instantiate(_spawnCapsuleData.CapsulePrefab); | |
} | |
if(Input.GetKeyDown(KeyCode.Alpha2)) | |
{ | |
EntityManager.DestroyEntity(_spawnedCapsule); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment