Recently, in my Unity projects, I found that to create a more modular application, it helps to have a static list in the class that contains links to all or some of the created objects so that they can be easily accessed from other parts of the program. The following is an example:
private static List<Canvas> availableCanvases = new List<Canvas>(); void Start () { availableCanvases.Add(this); } public static void AddComponentToCanvas(Transform component) { for (int i = 0; i < availableCanvases; i++) {
It just allows you to instantiate an object at runtime to add itself to an accessible canvas without having to access it using the findWithTag or findWithType method, which can hurt performance if used too much.
Is this a bad practice or a good one? My colleague believes that this is a one-point programming, but, of course, this is not because it allows you to use and use several objects.
source share