- Click anywhere in the CPU Usage graph
- We can see that our Update method is taking up a much larger portion of the frame
- Change the bottom section of the profiler from timeline to hierarchy view
- The timeline view is a good visualization, but the hierarchy view provides more actionable information
- Order the hierarchy view by “Time ms” and expand “PlayerLoop” all the way down to the script logic
- By ordering the view by “Time ms” we can narrow down what is taking the CPU so long to execute
- FindObjectsOfType is taking up some time, so let’s fix that
- Switch to Visual Studio
- Convert interactables to a private member variable
- Initialize interactables in the Start method
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
// TODO |
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
public class Combatant : MonoBehaviour | |
{ | |
public float Health; | |
public void Damage(int damage) | |
{ | |
Health = Math.Max(0, Health - damage); | |
} | |
} |
#TODO
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 Interactions; | |
using NUnit.Framework; | |
using UnityEngine; | |
using UnityEngine.TestTools; | |
public class InteractionHandlerTests | |
{ | |
public class FadeOutTests | |
{ | |
[UnityTest] |
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
public class Interactable : MonoBehaviour | |
{ | |
private InteractionHandler[] _handlers; | |
public void Awake() | |
{ | |
_handlers = GetComponents<InteractionHandler>(); | |
} | |
public void Interact() |
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
public class FadingInteractable : Interactable | |
{ | |
[SerializeField] private float duration = 3; | |
private Renderer _renderer; | |
public void Interact() | |
{ | |
StartCoroutine(FadeOut); | |
} |
OlderNewer