public override bool OnNUI(Rect rect, SerializedProperty property, GUIContent label) { List <string> options = new List <string> { "[no axle]" }; // Try to get vehicle controller from parent property vc = property.serializedObject.targetObject as VehicleController; if (vc == null) { selectedIndex = EditorGUI.Popup(rect, "Belongs to", 0, options.ToArray()); return(false); } // Find the name and index of currently selected output groupIndexProperty = property.FindPropertyRelative("index"); if (groupIndexProperty == null) { Debug.LogWarning("Property axleIndex not found."); return(false); } int axleIndex = groupIndexProperty.intValue; int selectorIndex = axleIndex + 1; string name = axleIndex >= vc.powertrain.wheelGroups.Count || axleIndex < 0 ? "" : vc.powertrain.wheelGroups[axleIndex].name; // Add the names of other powertrain components for (int i = 0; i < vc.powertrain.wheelGroups.Count; i++) { options.Add($"{vc.powertrain.wheelGroups[i].name} [Group {i.ToString()}]"); } // Display dropdown menu selectedIndex = EditorGUI.Popup(new Rect(rect.x, rect.y, rect.width, NUISettings.FIELD_HEIGHT), "Belongs to", selectorIndex, options.ToArray()); // Display currently selected output groupIndexProperty.intValue = selectedIndex - 1; if (selectedIndex > 0 && selectedIndex <= vc.powertrain.wheelGroups.Count) { WheelComponent wheelComponent = SerializedPropertyHelper.GetTargetObjectWithProperty(property) as WheelComponent; if (wheelComponent != null) { wheelComponent.wheelGroup = vc.powertrain.wheelGroups[selectedIndex - 1]; } else { Debug.LogWarning("WheelComponent property not found. Wheel group will not be set."); } } return(true); }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { drawer.BeginProperty(position, property, label); // Draw label string fullName = drawer.FindProperty("fullName").stringValue.Replace("NWH.VehiclePhysics.", ""); string shortName = fullName.Split('.').Last(); GUIStyle miniStyle = EditorStyles.centeredGreyMiniLabel; miniStyle.alignment = TextAnchor.MiddleLeft; Rect labelRect = drawer.positionRect; labelRect.x += 5f; Rect miniRect = drawer.positionRect; miniRect.x += 200f; EditorGUI.LabelField(labelRect, shortName, EditorStyles.boldLabel); EditorGUI.LabelField(miniRect, fullName, miniStyle); drawer.Space(NUISettings.FIELD_HEIGHT); StateSettings stateSettings = SerializedPropertyHelper.GetTargetObjectWithProperty(property) as StateSettings; if (stateSettings == null) { drawer.EndProperty(); return(false); } ComponentNUIPropertyDrawer.DrawStateSettingsBar ( position, stateSettings.LODs.Count, property.FindPropertyRelative("isOn"), property.FindPropertyRelative("isEnabled"), property.FindPropertyRelative("lodIndex") ); drawer.EndProperty(); return(true); }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { if (!base.OnNUI(position, property, label)) { return(false); } VehicleController vehicleController = SerializedPropertyHelper.GetTargetObjectWithProperty(property) as VehicleController; if (vehicleController == null) { drawer.EndProperty(); return(false); } ModuleManager moduleManager = SerializedPropertyHelper.GetTargetObjectOfProperty(property) as ModuleManager; if (moduleManager == null) { drawer.EndProperty(); return(false); } moduleManager.VehicleController = vehicleController; if (!Application.isPlaying && (int)EditorApplication.timeSinceStartup % 2 == 0) { moduleManager.ReloadModulesList(); } drawer.Space(); ModuleWrapper[] wrappers = vehicleController.gameObject.GetComponents <ModuleWrapper>(); if (wrappers.Length == 0) { drawer.Info("Use 'Add Component' button to add a module. Modules will appear here as they are added."); drawer.EndProperty(); return(true); } drawer.Label("Module Categories:"); VehicleModule.ModuleCategory[] moduleCategories = moduleManager.modules.Select(m => m.GetModuleCategory()).Distinct().OrderBy(x => x).ToArray(); int categoryIndex = drawer.HorizontalToolbar("moduleCategories", moduleCategories.Select(m => m.ToString()).ToArray()); if (categoryIndex < 0) { categoryIndex = 0; } if (categoryIndex >= moduleCategories.Length) { drawer.EndProperty(); return(true); } drawer.Space(3); VehicleModule.ModuleCategory activeCategory = moduleCategories[categoryIndex]; foreach (ModuleWrapper wrapper in wrappers) { if (wrapper == null || wrapper.GetModule() == null) { continue; } if (wrapper.GetModule().GetModuleCategory() != activeCategory) { continue; } drawer.EmbeddedObjectEditor(wrapper, drawer.positionRect); } drawer.EndProperty(); return(true); }