Created
November 8, 2025 00:15
-
-
Save Vavassor/3ec3850234f4678d744491e6534508ad to your computer and use it in GitHub Desktop.
VRChat U# example for setting a singleton manager reference on many objects, using a button.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UdonSharpEditor; | |
| using UnityEditor; | |
| using UnityEngine; | |
| [CustomEditor(typeof(PropManager)), CanEditMultipleObjects] | |
| public class PropManagerEditor : UnityEditor.Editor | |
| { | |
| public override void OnInspectorGUI() | |
| { | |
| if (UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target)) return; | |
| var propManager = (PropManager)target; | |
| if (GUILayout.Button("Add Manager to Props")) | |
| { | |
| var props = FindObjectsOfType<Prop>(true); | |
| foreach (var propComponent in props) | |
| { | |
| var prop = new SerializedObject(propComponent); | |
| prop.FindProperty("propManager").objectReferenceValue = propManager; | |
| prop.ApplyModifiedProperties(); | |
| } | |
| } | |
| GUILayout.Space(); | |
| // DrawDefaultInspector adds all the other fields. So you don't need to customize | |
| // everything in the inspector! | |
| DrawDefaultInspector(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment