How does it work ?
The Highlight Manager is an independent framework designed to manage multiple highlights at the same time. Every Highlight can be customized.
The HighlightManager will register every Highlight in the scene provied they all have a unique Id.
When the StartHighlight
method is called, the Manager clones the Highlight component and its serialized fields to the targetted GameObject.
A GameObject can have multiple Highlights enabled at the same time. Note that the highlights with the higher priority on the GameObject will be on while highlights with lower priorities will stay off until the higher priorities highlights are stopped.
Prepare your scene
First, you need to put the HighlightManager in your scene. Use the provided prefab or add the HighlightManager component to a GameObject.
You can register highlights by adding their corresponding comoponents in the scene. These components will be used as templates and should be disabled by default.
You can create variants of an highlight with different parameters by adding as many components in the scene as needed and setting a different and unique Id to each of them.
Start and stop highlights through scripting
The Highlight Manager can start and stop highlights in various ways:
1- StartHighlight on one or multiple GameObjects
public void StartHighlight(GameObject gameObject, Highlight highlight)
public void StartHighlight(GameObject gameObjectToHighlight, string idHighlight)
public void StartHighlight(List<GameObject> gameObjects, Highlight highlight)
public void StartHighlight(List<GameObject> gameObjects, string idHighlight)
2- StopHighlight on one or multiple GameObjects.
public void StopHighlight(GameObject gameoBject, Highlight Highlight, bool force = false)
public void StopHighlight(GameObject gameObject, string idHighlight, bool force = false)
public void StopHighlight(List<GameObject> gameObjects, Highlight highlight, bool force = false)
public void StopHighlight(List<GameObject> gameObjects, string idHighlight, bool force = false)
The Highlight Manager keeps track of how many times an highlight has been started on each GameObject. It means that if you start the same highlight on the same GameObject twice, you will need (in order to disable the highlight) to either :
- Stop the highlight twice
- Stop the highlight with the
force
parameter set totrue
How to create a custom Highlight
While we provide the Highlight Manager with several Highlights (see the Libraries folder), it is possible to create custom Highlights. These need to inherit from the Highlight
class (which inherits from MonoBehaviour).
The HighlightChildObjects
field should be taken into account when an highlight might need to apply to multiple Components (for example when a GameObject is composed of multiple meshes).
When starting, Highlights will run the OnEnable()
Unity method.
When stopping, Highlights will run the OnDisable()
Unity method.
All other Unity component methods can be implemented if needed (for example, use the Update()
if the highlight must update each frame).