public enum E_Style_Switch
{On,Off,
}
public class baseControl : MonoBehaviour
{//位置信息public basePos pos;//内容信息public GUIContent content;//自定义样式public GUIStyle style;public E_Style_Switch styleSwitch = E_Style_Switch.Off;private void OnGUI(){switch (styleSwitch){case E_Style_Switch.On:StyleOn();break;case E_Style_Switch.Off:StyleOff();break;}}protected virtual void StyleOn(){}protected virtual void StyleOff(){}
}
[ExecuteAlways]
public class root : MonoBehaviour
{private baseControl[] allControls;private void Start(){allControls = GetComponentsInChildren<baseControl>();}private void OnGUI(){//得到所有子对象上的父类脚本//在编辑状态下才一直执行if (!Application.isPlaying){allControls = GetComponentsInChildren<baseControl>();}for (int i = 0; i < allControls.Length; i++){allControls[i].DrawGUI();}}
}