public static SerializedProperty FindRelativeProperty(SerializedProperty property, string propertyName) { if (property.depth == 0) { return(property.serializedObject.FindProperty(propertyName)); } var path = property.propertyPath.Replace(".Array.data[", "["); var elements = path.Split('.'); var nestedProperty = NestedPropertyOrigin(property, elements); // if nested property is null = we hit an array property if (nestedProperty == null) { var cleanPath = path.Substring(0, path.IndexOf('[')); var arrayProp = property.serializedObject.FindProperty(cleanPath); var target = arrayProp.serializedObject.targetObject; var who = "Property <color=brown>" + arrayProp.name + "</color> in object <color=brown>" + target.name + "</color> caused: "; var warning = who + "Array fields is not supported by [ConditionalFieldAttribute]"; WarningsPool.Log(warning, target); return(null); } return(nestedProperty.FindPropertyRelative(propertyName)); }
private void LogWarning(string log, SerializedProperty property) { var warning = "Property <color=brown>" + fieldInfo.Name + "</color>"; if (fieldInfo != null && fieldInfo.DeclaringType != null) { warning += " on behaviour <color=brown>" + fieldInfo.DeclaringType.Name + "</color>"; } warning += " caused: " + log; WarningsPool.Log(warning, property.serializedObject.targetObject); }
private static void CheckForUpdates() { MyEditorEvents.OnEditorStarts -= CheckForUpdates; MyBoxUtilities.GetMyBoxLatestVersionAsync(version => { _installedVersion = MyBoxUtilities.GetMyBoxInstalledVersion(); _latestVersion = version; if (!_installedVersion.VersionsMatch(_latestVersion)) { var versions = "Installed version: " + _installedVersion.AsSting + ". Latest version: " + _latestVersion.AsSting; var message = "It's time to update MyBox :)! Use \"Tools/MyBox/Update MyBox\". " + versions; WarningsPool.Log(message); } }); }
static MyBoxWindow() { if (AutoUpdateCheckIsEnabled) { MyBoxUtilities.GetMyBoxLatestVersionAsync(version => { _installedVersion = MyBoxUtilities.GetMyBoxInstalledVersion(); _latestVersion = version; if (!_installedVersion.VersionsMatch(_latestVersion)) { var versions = "Installed version: " + _installedVersion.AsSting + ". Latest version: " + _latestVersion.AsSting; var message = "It's time to update MyBox :)! Use \"Tools/MyBox/Update MyBox\". " + versions; WarningsPool.Log(message); } }); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { SerializedProperty minProp = property.FindPropertyRelative("Min"); SerializedProperty maxProp = property.FindPropertyRelative("Max"); if (minProp == null || maxProp == null) { WarningsPool.Log("MinMaxRangeAttribute used on <color=brown>" + property.name + "</color>. Must be used on types with Min and Max fields", property.serializedObject.targetObject); return; } var minValid = minProp.propertyType == SerializedPropertyType.Integer || minProp.propertyType == SerializedPropertyType.Float; var maxValid = maxProp.propertyType == SerializedPropertyType.Integer || maxProp.propertyType == SerializedPropertyType.Float; if (!maxValid || !minValid || minProp.propertyType != maxProp.propertyType) { WarningsPool.Log("MinMaxRangeAttribute used on <color=brown>" + property.name + "</color>. Min and Max fields must be of int or float type", property.serializedObject.targetObject); return; } MinMaxRangeAttribute rangeAttribute = (MinMaxRangeAttribute)attribute; label = EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, label); bool isInt = minProp.propertyType == SerializedPropertyType.Integer; float minValue = isInt ? minProp.intValue : minProp.floatValue; float maxValue = isInt ? maxProp.intValue : maxProp.floatValue; float rangeMin = rangeAttribute.Min; float rangeMax = rangeAttribute.Max; const float rangeBoundsLabelWidth = 40f; var rangeBoundsLabel1Rect = new Rect(position); rangeBoundsLabel1Rect.width = rangeBoundsLabelWidth; GUI.Label(rangeBoundsLabel1Rect, new GUIContent(minValue.ToString(isInt ? "F0" : "F2"))); position.xMin += rangeBoundsLabelWidth; var rangeBoundsLabel2Rect = new Rect(position); rangeBoundsLabel2Rect.xMin = rangeBoundsLabel2Rect.xMax - rangeBoundsLabelWidth; GUI.Label(rangeBoundsLabel2Rect, new GUIContent(maxValue.ToString(isInt ? "F0" : "F2"))); position.xMax -= rangeBoundsLabelWidth; EditorGUI.BeginChangeCheck(); EditorGUI.MinMaxSlider(position, ref minValue, ref maxValue, rangeMin, rangeMax); if (EditorGUI.EndChangeCheck()) { if (isInt) { minProp.intValue = Mathf.RoundToInt(minValue); maxProp.intValue = Mathf.RoundToInt(maxValue); } else { minProp.floatValue = minValue; maxProp.floatValue = maxValue; } } EditorGUI.EndProperty(); }