I know the hurdle is well known: Can’t set the UI OnClick() shortcut target singleton objects due to losing connection when loading/reloading into screens. Unfortunately it seems pertinent threads are over a year old, so I want to get a bit of updated info, particularly if my current approach would be considered best practice, and if there are any possible limitations/hurdles my approach may create in the future.
Currently, I’m using a singleton to manage data persistence and game loading (inventively named “Game Controller”).
My buttons each have a script to call the method. Rather than take the public variable (or FindObject) approach and adding listeners, I’ve inherited IPointerEventHandler and call the Game Controller method needed:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class gameButton_Launch : MonoBehaviour, IPointerClickHandler {
public void OnPointerClick (PointerEventData pointerEventData)
{
GameController.Singleton.LoadIntoGame ();
}
}
If it’s not obvious by the existence of this thread, my experience with Unity is limited at best, but right now, the only downside I see at all is cluttering my asset folder with scripts (though I consider myself a connoisseur of the arts of “creating subdirectories for everything” ^_^)
Are there obvious limitations I’m overlooking, or even hidden hurdles I won’t notice until I end up jumping into large scale projects? Or has a different, newer approach altogether that eliminates the dozen(s) of < 10 line scripts?