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 void TestCompound() { var data3 = new Data3 { data1 = new Data1 { i = 890 }, f = -2689789f, data2 = new Data2 { f = 7892f, i = -25742, s = "øøøøøøøøøøøø" } }; var dataProp = containerSO.FindProperty(nameof(DataContainer.data3)); SerializedPropertyHelper.SetValue(dataProp, data3); Assert.AreEqual(data3.data1.i, container.data3.data1.i); Assert.AreEqual(data3.f, container.data3.f); Assert.AreEqual(data3.data2.f, container.data3.data2.f); Assert.AreEqual(data3.data2.i, container.data3.data2.i); Assert.AreEqual(data3.data2.s, container.data3.data2.s); }
private IValuePresentation GetValuePresentation(IObjectValueRole <TValue> serializedPropertyRole, SerializedPropertyKind propertyType, IPresentationOptions options, out string extraDetail) { extraDetail = null; var valueProperty = GetValueFieldName(propertyType); var valueReference = valueProperty == null ? null : serializedPropertyRole.GetInstancePropertyReference(valueProperty); if (propertyType == SerializedPropertyKind.Enum) { extraDetail = SerializedPropertyHelper.GetEnumValueIndexAsEnumName(serializedPropertyRole, valueReference, options); } else if (propertyType == SerializedPropertyKind.Character) { extraDetail = SerializedPropertyHelper.GetIntValueAsPrintableChar(valueReference, options); } else if (propertyType == SerializedPropertyKind.Integer) { var type = serializedPropertyRole.GetInstancePropertyReference("type")?.AsStringSafe(options) ?.GetString(); if (type == "char") { extraDetail = SerializedPropertyHelper.GetIntValueAsPrintableChar(valueReference, options); } } return(valueReference?.ToValue(ValueServices)?.GetValuePresentation(options)); }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { drawer.BeginProperty(position, property, label); VehicleModule = SerializedPropertyHelper.GetTargetObjectOfProperty(drawer.serializedProperty) as VehicleModule; if (VehicleModule == null) { Debug.LogError( "VehicleModule is not a target object of ModuleDrawer. Make sure all modules inherit from VehicleModule."); drawer.EndProperty(); return(false); } bool expanded = drawer.Header(VehicleModule.GetType().Name); if (Application.isPlaying && VehicleModule.VehicleController != null) { if (VehicleModule.VehicleController.stateSettings != null) { DrawStateSettingsBar( position, VehicleModule.VehicleController.stateSettings.LODs.Count, drawer.FindProperty("state.isOn"), drawer.FindProperty("state.isEnabled"), drawer.FindProperty("state.lodIndex")); } } return(expanded); }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { if (!base.OnNUI(position, property, label)) { return(false); } MetricsModule metrics = SerializedPropertyHelper.GetTargetObjectOfProperty(property) as MetricsModule; if (metrics == null) { drawer.EndProperty(); return(false); } drawer.Label($"Top Speed: {metrics.topSpeed.value}"); drawer.Label($"Average Speed: {metrics.averageSpeed.value}"); drawer.Label($"Odometer: {metrics.odometer.value}"); drawer.Label($"Cont. Drift Distance: {metrics.continousDriftDistance.value}"); drawer.Label($"Cont. Drift Time: {metrics.continousDriftTime.value}"); drawer.Label($"Total Drift Distance: {metrics.totalDriftDistance.value}"); drawer.Label($"Total Drift Time: {metrics.totalDriftTime.value}"); drawer.EndProperty(); return(true); }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { if (!base.OnNUI(position, property, label)) { return(false); } drawer.Field("useForcedInduction"); drawer.Field("forcedInductionType"); drawer.Field("powerGainMultiplier"); EngineComponent.ForcedInduction forcedInduction = SerializedPropertyHelper.GetTargetObjectOfProperty(property) as EngineComponent.ForcedInduction; if (forcedInduction != null && forcedInduction.forcedInductionType == EngineComponent.ForcedInduction.ForcedInductionType.Turbocharger) { drawer.Field("spoolUpTime", true, "s"); drawer.Field("linearity"); } drawer.Field("boost", false); drawer.EndProperty(); return(true); }
public void TestJustAnInt() { var justAnIntProp = containerSO.FindProperty(nameof(DataContainer.justAnInt)); SerializedPropertyHelper.SetValue(justAnIntProp, 13); Assert.AreEqual(13, container.justAnInt); }
private object GetDebugValue(SerializedProperty property) { object parent = SerializedPropertyHelper.GetParent(property); Type parentType = parent.GetType(); FieldInfo targetField = parentType.GetField("_debugValue", BindingFlags.Instance | BindingFlags.NonPublic); return(targetField.GetValue(parent)); }
protected override List <string> GetExcludedPropertiesInInspector() { List <string> excluded = base.GetExcludedPropertiesInInspector(); if (!Target.m_UseCommonLensSetting) { excluded.Add(SerializedPropertyHelper.PropertyName(() => Target.m_Lens)); } return(excluded); }
public void TestSetData1Value() { var data = new Data1 { i = 15 }; var dataProp = containerSO.FindProperty(nameof(DataContainer.data1)); SerializedPropertyHelper.SetValue(dataProp, data); Assert.AreEqual(15, container.data1.i); }
public void TestSetData2Value() { var data2 = new Data2 { i = 2345, s = "1dkløasgjp+", f = 58582f }; var dataProp = containerSO.FindProperty(nameof(DataContainer.data2)); SerializedPropertyHelper.SetValue(dataProp, data2); Assert.AreEqual(data2.i, container.data2.i); Assert.AreEqual(data2.s, container.data2.s); Assert.AreEqual(data2.f, container.data2.f); }
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); } drawer.Field("groundDetectionPreset"); GroundDetectionPreset gdPreset = ((GroundDetection)(SerializedPropertyHelper.GetTargetObjectOfProperty(property) as VehicleComponent))?.groundDetectionPreset; if (gdPreset != null) { drawer.EmbeddedObjectEditor(gdPreset, drawer.positionRect); } drawer.BeginSubsection("Debug Info"); GroundDetection groundDetection = SerializedPropertyHelper.GetTargetObjectOfProperty(drawer.serializedProperty) as GroundDetection; if (groundDetection != null && groundDetection.VehicleController != null) { for (int i = 0; i < groundDetection.VehicleController.powertrain.wheels.Count; i++) { WheelComponent wheelComponent = groundDetection.VehicleController.powertrain.wheels[i]; if (wheelComponent != null) { drawer.Label($"{wheelComponent.name}: {wheelComponent.surfacePreset?.name} SurfacePreset"); } } } else { drawer.Info("Debug info is available only in play mode."); } drawer.EndSubsection(); drawer.EndProperty(); return(true); }
public void DrawClipsSection(List <string> clipNames = null, int minClipCount = 1, int maxClipCount = 1, int defaultClipCount = 1) { soundComponentObject = (SerializedPropertyHelper.GetTargetObjectOfProperty(drawer.serializedProperty) as VehicleComponent) as SoundComponent; drawer.ReorderableList("clips"); if (soundComponentObject == null) { return; } if (soundComponentObject.clips.Count > defaultClipCount) { drawer.Space(); drawer.Info("If more than clip is supplied for sound components that require only one, " + "a random clip will be selected each time sound is played."); } }
protected override string[] GetExcludedPropertiesInInspector() { string[] excluded = Target.m_ExcludedPropertiesInInspector; if (Target.m_UseCommonLensSetting) { return(excluded); } // If not using a common lens, hide the lens settings int len = (excluded == null) ? 0 : excluded.Length; string[] excluded2 = new string[len + 1]; for (int i = 0; i < len; ++i) { excluded2[i] = excluded[i]; } excluded2[len] = SerializedPropertyHelper.PropertyName(() => Target.m_LensAttributes); return(excluded2); }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { if (!base.OnNUI(position, property, label)) { return(false); } drawer.Field("physicsQuality"); drawer.Space(); if (Application.isPlaying) { Solver solver = SerializedPropertyHelper.GetTargetObjectOfProperty(property) as Solver; drawer.Label($"Simulating {solver.Components.Count} powertrain components.", false, false); } drawer.EndProperty(); return(true); }
private IEnumerable <IValueReference <TValue> > DecorateCharacterValue(IEnumerable <IValueReference <TValue> > references, IValueFetchOptions options) { foreach (var reference in references) { if (reference.DefaultName == "intValue" || reference.DefaultName == "longValue") { var extraDetail = SerializedPropertyHelper.GetIntValueAsPrintableChar(reference, options); if (extraDetail != null) { yield return(new ExtraDetailValueReferenceDecorator <TValue>(reference, ValueServices.RoleFactory, extraDetail)); continue; } } yield return(reference); } }
private IEnumerable <IValueReference <TValue> > DecorateEnumValue(IObjectValueRole <TValue> serializedProperty, IEnumerable <IValueReference <TValue> > references, IPresentationOptions options) { foreach (var reference in references) { if (reference.DefaultName == "enumValueIndex") { var extraDetail = SerializedPropertyHelper.GetEnumValueIndexAsEnumName(serializedProperty, reference, options); if (extraDetail != null) { yield return(new ExtraDetailValueReferenceDecorator <TValue>(reference, ValueServices.RoleFactory, extraDetail)); continue; } } yield return(reference); } }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { if (!base.OnNUI(position, property, label)) { return(false); } _transmissionComponent = SerializedPropertyHelper.GetTargetObjectOfProperty(property) as TransmissionComponent; SerializedProperty transmissionType = property.FindPropertyRelative("_transmissionType"); TransmissionComponent.Type type = (TransmissionComponent.Type)transmissionType.enumValueIndex; DrawCommonProperties(); drawer.BeginSubsection("General"); drawer.Field("_transmissionType"); drawer.Field("reverseType"); drawer.EndSubsection(); drawer.BeginSubsection("Gearing"); drawer.Field("finalGearRatio"); drawer.Field("gearingProfile"); drawer.EmbeddedObjectEditor(_transmissionComponent.gearingProfile, drawer.positionRect); if (type == TransmissionComponent.Type.CVT) { drawer.Field("cvtMaxInputTorque"); } drawer.EndSubsection(); if (type != TransmissionComponent.Type.CVT) { drawer.BeginSubsection("Shifting"); drawer.Field("shiftDuration", true, "s"); drawer.Field("postShiftBan", true, "s"); if (type != TransmissionComponent.Type.Manual) { drawer.Field("_upshiftRPM", true, "rpm"); drawer.Field("_downshiftRPM", true, "rpm"); drawer.Field("_currentGearIndex"); if (drawer.Field("variableShiftPoint").boolValue) { drawer.Field("variableShiftIntensity"); drawer.Field("inclineEffectCoeff"); drawer.Info( "High Incline Effect Coefficient values can prevent vehicle from changing gears as it is possible to get the Target Upshift RPM value higher than Rev Limiter RPM value. " + "This is intentional to prevent heavy vehicles from upshifting on steep inclines."); drawer.Field("_targetUpshiftRPM", false, "rpm"); drawer.Field("_targetDownshiftRPM", false, "rpm"); } drawer.EndSubsection(); drawer.BeginSubsection("Shift Conditions"); drawer.Field("shiftCheckCooldown"); drawer.Field("noWheelSpin", false); drawer.Field("noWheelSkid", false); drawer.Field("noWheelAir", false); drawer.Field("clutchEngaged", false); drawer.Field("externalShiftChecksValid", false); drawer.EndSubsection(); } else { drawer.EndSubsection(); } drawer.BeginSubsection("Events"); drawer.Space(2); drawer.Field("onShift"); drawer.Field("onUpshift"); drawer.Field("onDownshift"); drawer.EndSubsection(); } EditorGUI.EndDisabledGroup(); drawer.EndProperty(); return(true); }
private void UpdateMediaQueries(SerializedProperty declaration) { var mediaQueries = declaration.FindPropertyRelative("MediaQueries"); var oldCount = mediaQueries.arraySize; List <SerializedProperty> oldProps = new List <SerializedProperty>(); for (int i = 0; i < oldCount; i++) { var prop = mediaQueries.GetArrayElementAtIndex(i); oldProps.Add(prop); } List <string> newQueryIDs = new List <string>(); StringBuilder sb = new StringBuilder(); foreach (MediaQuery query in MediaQueries) { var id = query.Name; newQueryIDs.Add(id); sb.AppendLine(id); } // Remove non-existing (reverse loop) for (int i = mediaQueries.arraySize - 1; i >= 0; i--) { var query = mediaQueries.GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue; if (!newQueryIDs.Contains(query)) { mediaQueries.DeleteArrayElementAtIndex(i); } } //Debug.Log("New size after deletion: " + properties.arraySize); // walk through new properties // if no corresponding property found in the old serialized array: // 1) make room for the property // 2) copy new name and type var newCount = MediaQueries.Count; for (int i = 0; i < newCount; i++) { var name = MediaQueries[i].Name; var type = MediaQueries[i].Type; bool shouldInsertOrAddNewElement = i > mediaQueries.arraySize - 1; if (!shouldInsertOrAddNewElement) { string oldQueryId = mediaQueries.GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue; if (oldQueryId != name) { shouldInsertOrAddNewElement = true; } } if (shouldInsertOrAddNewElement) { if (i == mediaQueries.arraySize) { mediaQueries.arraySize++; } else { mediaQueries.InsertArrayElementAtIndex(i); } //Debug.Log(" --> " + properties.arraySize); var prop = mediaQueries.GetArrayElementAtIndex(i); prop.FindPropertyRelative("Name").stringValue = name; // apply type, value etc. SerializedPropertyHelper.Apply(prop, MediaQueries[i]); } } }
private void UpdateProperties(SerializedProperty declaration) { var properties = declaration.FindPropertyRelative("Properties"); var oldCount = properties.arraySize; List <SerializedProperty> oldProps = new List <SerializedProperty>(); for (int i = 0; i < oldCount; i++) { SerializedProperty prop = properties.GetArrayElementAtIndex(i); oldProps.Add(prop); } List <string> newPropertyNames = new List <string>(); StringBuilder sb = new StringBuilder(); foreach (StyleProperty styleProperty in StyleProperties) { var name = styleProperty.Name; newPropertyNames.Add(name); sb.AppendLine(name); } // Remove non-existing (reverse loop) for (int i = properties.arraySize - 1; i >= 0; i--) { var propName = properties.GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue; if (!newPropertyNames.Contains(propName)) { properties.DeleteArrayElementAtIndex(i); } } //Debug.Log("New size after deletion: " + properties.arraySize); // walk through new properties // if no corresponding property found in the old serialized array: // 1) make room for the property // 2) copy new name and type var newCount = StyleProperties.Count; for (int i = 0; i < newCount; i++) { var name = StyleProperties[i].Name; bool shouldInsertOrAddNewElement = i > properties.arraySize - 1; if (!shouldInsertOrAddNewElement) { string oldPropName = properties.GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue; if (oldPropName != name) { shouldInsertOrAddNewElement = true; } } if (shouldInsertOrAddNewElement) { if (i == properties.arraySize) { properties.arraySize++; } else { properties.InsertArrayElementAtIndex(i); } //Debug.Log(" --> " + properties.arraySize); var prop = properties.GetArrayElementAtIndex(i); prop.FindPropertyRelative("Name").stringValue = name; SerializedPropertyHelper.Apply(prop, StyleProperties[i]); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position.height = StyleDeclarationInsetRenderer.HeaderHeight; SerializedProperty module = property.FindPropertyRelative("Module"); _insetRenderer.Error = string.IsNullOrEmpty(module.stringValue) ? "Style module not defined" : null; SerializedProperty type = property.FindPropertyRelative("Type"); SerializedProperty classname = property.FindPropertyRelative("Class"); SerializedProperty id = property.FindPropertyRelative("Id"); var selectorString = StyleSelector.BuildString(type.stringValue, classname.stringValue, id.stringValue); var title = selectorString; SerializedProperty mediaQueries = property.FindPropertyRelative("MediaQueries"); int size = mediaQueries.arraySize; if (size > 0) { /*var mkList = new System.Collections.Generic.List<string>(); * for (int i = 0; i < size; i++) * { * var query = mediaQueries.GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue; * mkList.Add(query); * }*/ //title += string.Format(" @media {0}", string.Join(", ", mkList.ToArray())); title += string.Format(" @media"); } var isScanning = EditorSettings.LiveStyling && Application.isPlaying; var passed = 0 == size || !isScanning; if (!passed) { // let's assume it will pass passed = true; // loop thgough each query for (int i = 0; i < size; i++) { var query = mediaQueries.GetArrayElementAtIndex(i); var name = query.FindPropertyRelative("Name").stringValue; var value = SerializedPropertyHelper.Read(query); //Debug.Log("value: " + value); passed = MediaQueryManager.Instance.EvaluateQuery(name, value); // when a single query doesn't pass, break the loop if (!passed) { break; } } //GUI.backgroundColor = mediaQueryPasses ? Color.green : Color.red; } _insetRenderer.MediaQueriesPassed = passed; CurrentType = type.stringValue; Rect pos2 = new Rect(position.x, position.y, position.width, property.isExpanded ? GetPropertyHeight(property, label) : position.height); /*label = */ EditorGUI.BeginProperty(position, label, property); property.isExpanded = _insetRenderer.RenderStart(pos2, title, property.isExpanded); EditorGUI.EndProperty(); if (!property.isExpanded) { return; } position.y += StyleDeclarationInsetRenderer.HeaderHeight; if (!eDrivenStyleSheetEditor.EditorLocked) { position.y += ToolbarHeight; } position.width -= BorderMetrics.Right; //EditorGUI.indentLevel += 1; position.x += BorderMetrics.Left; /** * 1. Render media queries * */ var numberOfMediaQueries = RenderMediaQueries(ref position, property); /** * 2. Render properties * */ var numberOfProperties = RenderProperties(position, property); /*if (Event.current.type == EventType.ValidateCommand) * { * Debug.Log(Event.current.type); * }*/ /*var isUndo = Event.current.type == EventType.ValidateCommand && * Event.current.commandName == "UndoRedoPerformed";*/ if (GUI.changed /* || isUndo*/) { eDrivenStyleSheet edss = (eDrivenStyleSheet)property.serializedObject.targetObject; StyleSheet ss = edss.StyleSheet; StyleDeclaration declaration = null; foreach (StyleDeclaration dec in ss.Declarations) { //Debug.Log(StyleSelector.BuildString(dec.Type, dec.Class, dec.Id)); /* Note: this is buggy, think about how to reference it without using the selector */ if (StyleSelector.BuildString(dec.Type, dec.Class, dec.Id) == selectorString) { //Debug.Log("Found declaration: " + dec); declaration = dec; break; } } if (null == declaration) { return; // nothing found? } /** * 1. Get old properties * */ DictionaryDelta propertiesDelta = new DictionaryDelta(); propertiesDelta.SnapshotBefore(declaration.Properties); /** * 2. Apply changes * */ var propertiesChanged = property.serializedObject.ApplyModifiedProperties(); /** * 3. Get new properties * */ propertiesDelta.SnapshotAfter(declaration.Properties); /** * 4. Process delta * */ propertiesDelta.Process(); /** * 1. Get old media queries * */ DictionaryDelta mediaQueriesDelta = new DictionaryDelta(); mediaQueriesDelta.SnapshotBefore(declaration.MediaQueries); /** * 2. Apply changes * */ var mediaQueriesChanged = property.serializedObject.ApplyModifiedProperties(); /** * 3. Get new properties * */ mediaQueriesDelta.SnapshotAfter(declaration.MediaQueries); /** * 4. Process delta * */ propertiesDelta.Process(); var selector = Selector.BuildSelector(type.stringValue, classname.stringValue, id.stringValue); var propertyCountChanged = _oldNumberOfProperties != numberOfProperties; var mediaQueryCountChanged = _oldNumberOfMediaQueries != numberOfMediaQueries; if (propertiesChanged || mediaQueriesChanged || propertyCountChanged || mediaQueryCountChanged) { var moduleId = property.FindPropertyRelative("Module").stringValue; if (string.IsNullOrEmpty(moduleId)) { Debug.Log("Module not defined (unknown module ID)"); } else { StyleModuleManager.Instance.GetModule(moduleId).UpdateStyles(selector, propertiesDelta); } if (propertyCountChanged) { _oldNumberOfProperties = numberOfProperties; } if (mediaQueryCountChanged) { _oldNumberOfMediaQueries = numberOfMediaQueries; } StyleSheetPropertyDrawer.ShouldProcessStyles = true; } GUI.changed = false; } }
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); }
public override bool OnNUI(Rect position, SerializedProperty property, GUIContent label) { if (!base.OnNUI(position, property, label)) { return(false); } DamageHandler damageHandler = SerializedPropertyHelper.GetTargetObjectOfProperty(property) as DamageHandler; if (damageHandler == null) { drawer.EndProperty(); return(false); } drawer.BeginSubsection("Collision"); drawer.Field("decelerationThreshold", true, "m/s2"); drawer.Field("collisionTimeout", true, "s"); drawer.ReorderableList("collisionIgnoreTags"); drawer.EndSubsection(); drawer.BeginSubsection("Damage"); drawer.Field("damageIntensity"); if (damageHandler.VehicleController != null) { drawer.Label($"Current Damage: {damageHandler.Damage} ({damageHandler.Damage * 100f}%)"); drawer.Label($"Engine Damage: {damageHandler.VehicleController.powertrain.engine.ComponentDamage}"); drawer.Label( $"Transmission Damage: {damageHandler.VehicleController.powertrain.transmission.ComponentDamage}"); foreach (WheelComponent wheelComponent in damageHandler.VehicleController.Wheels) { drawer.Label($"Wheel {wheelComponent.wheelController.name} Damage: {wheelComponent.Damage}"); } } else { drawer.Info("Damage debug info available in play mode."); } drawer.EndSubsection(); drawer.BeginSubsection("Mesh Deformation"); if (drawer.Field("meshDeform").boolValue) { drawer.Field("deformationVerticesPerFrame"); drawer.Field("deformationRadius", true, "m"); drawer.Field("deformationStrength"); drawer.Field("deformationRandomness"); drawer.ReorderableList("deformationIgnoreTags"); } drawer.EndSubsection(); drawer.BeginSubsection("Actions"); if (drawer.Button("Repair")) { damageHandler.Repair(); } drawer.EndSubsection(); drawer.BeginSubsection("Events"); drawer.Field("OnCollision"); drawer.EndSubsection(); drawer.EndProperty(); return(true); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { _nameStr = property.FindPropertyRelative("Name").stringValue; _propType = GetType(property); Type type = null; SerializedProperty prop = GetSlot(property, ref type); var isScanning = EditorSettings.LiveStyling && Application.isPlaying; bool mediaQueryPasses = false; //var oldColor = GUI.backgroundColor; if (isScanning) { var value = SerializedPropertyHelper.Read(property); //Debug.Log("value: " + value); mediaQueryPasses = MediaQueryManager.Instance.EvaluateQuery(_nameStr, value); //GUI.backgroundColor = mediaQueryPasses ? Color.green : Color.red; } /*_name = new GUIContent(" " + _nameStr, mediaQueryPasses ? * TextureCache.Instance.MediaQueryPass : TextureCache.Instance.MediaQueryFail);*/ _name = new GUIContent(" " + _nameStr); /* draw icon */ GUI.Label(position, mediaQueryPasses ? TextureCache.Instance.MediaQueryPass : TextureCache.Instance.MediaQueryFail); /* move a bit to the right */ position.x += 16; position.width -= 16; position.height = 16; // height for the rest try { if (null != type) { // 1. Object reference prop.objectReferenceValue = EditorGUI.ObjectField(position, _name, prop.objectReferenceValue, type, false); } else { if (_propType.IsEnum) { prop.stringValue = EnumHelper.Popup(position, _name, _propType, prop.stringValue); } else { // 2. Normal values EditorGUI.PropertyField(position, prop, _name); //, new GUIContent(label)); } } } catch (Exception) { // NOTE: Silent fail! GUI.Label(position, new GUIContent(" " + _nameStr + " ???", TextureCache.Instance.MediaQuery)); } /*if (isScanning) * { * GUI.backgroundColor = oldColor; * }*/ }