private void OnWheelSelect(GameObject selection) { if (selection == null) { Debug.LogError("Invalid TrackWheel selection - selected object is null."); return; } if (selection.GetComponentInParent <RigidBody>() == null) { Debug.LogError("Invalid TrackWheel selection - unable to find RigidBody component.", selection); return; } var createNewComponent = selection.GetComponent <TrackWheel>() == null; if (createNewComponent) { Undo.RegisterCreatedObjectUndo(TrackWheel.Create(selection), "Create TrackWheel"); } else if (Track.Contains(selection.GetComponent <TrackWheel>())) { Debug.Log("TrackWheel already part of Track - ignoring selection."); return; } // Reconfigure TrackWheel given new or the same selection. else { selection.GetComponent <TrackWheel>().Configure(selection); } if (!Track.Add(selection.GetComponent <TrackWheel>())) { Debug.LogError("Track failed to add TrackWheel instance.", Track); if (createNewComponent) { Object.DestroyImmediate(selection.GetComponent <TrackWheel>()); } return; } InspectorGUI.GetItemToolArrayGUIData(Track, "Wheels", selection.GetComponent <TrackWheel>()).Bool = true; EditorUtility.SetDirty(Track); }