Automatically initialize the only instance of a script in Unity edit mode (gradually updated)

1. When you want to integrate all debugging class Button and Toggle on the Manager script, instead of placing all debugging code in the Manager script, you need to call the debugging code in other scripts in the Manager. At this time, you need to initialize other scripts. , you can use ContextMenu to manually initialize instances in other scripts to call methods in this class.

[ContextMenu("BuildThis")]
public void BuildThis()
{
    instance = this;
}

But for convenience, I hope other scripts can initialize their own instances. You can write the instance to OnDrawGizmos()

private void OnDrawGizmos()
    {
        if(instance == null) instance = this;
    }

Guess you like

Origin blog.csdn.net/HeDanTou_/article/details/129434092