private void DrawTopInfoBox() { AllEditorGUI.InfoMessageBox( "On AOT-compiled platforms, Unity's code stripping can remove classes that the serialization system needs, " + "or fail to generate code for needed variants of generic types. Therefore, ODIN can create an assembly that " + "directly references all functionality that is needed at runtime, to ensure it is available."); }
/// <summary> /// Draws a property in the inspector using a given label. /// </summary> public static void DrawProperty(InspectorProperty property, GUIContent label) { if (property == null) { throw new ArgumentNullException("property"); } bool popGUIEnabled = false; try { property.PushDraw(); if ((property.RecursiveDrawDepth + InlineEditorAttributeDrawer.CurrentInlineEditorDrawDepth) > GeneralDrawerConfig.Instance.MaxRecursiveDrawDepth) { AllEditorGUI.ErrorMessageBox("The property '" + property.NiceName + "' has exceeded the maximum recursive draw depth limit of " + GeneralDrawerConfig.Instance.MaxRecursiveDrawDepth + "."); return; } if (property.ValueEntry != null && !property.SupportsPrefabModifications && property.Tree.HasPrefabs && !GUIHelper.IsDrawingDictionaryKey && (property.Info.PropertyType == PropertyType.ReferenceType || property.Info.PropertyType == PropertyType.ValueType)) { if ((property.Parent == null || property.Parent.SupportsPrefabModifications) && GeneralDrawerConfig.Instance.ShowPrefabModificationsDisabledMessage) { AllEditorGUI.InfoMessageBox("The property '" + property.NiceName + "' does not support being modified on prefab instances. (You can disable this message the general drawer config.)"); } GUIHelper.PushGUIEnabled(false); popGUIEnabled = true; } OdinDrawer[] drawers = DrawerLocator.GetDrawersForProperty(property); GUIHelper.BeginLayoutMeasuring(); { try { if (drawers.Length > 0) { bool setIsBoldState = property.ValueEntry != null && Event.current.type == EventType.Repaint; if (setIsBoldState) { var boldState = property.ValueEntry.ValueChangedFromPrefab; if (GUIHelper.IsDrawingDictionaryKey) { // Always propagate changed state down through dictionary keys boldState |= GUIHelper.IsBoldLabel; } GUIHelper.PushIsBoldLabel(boldState); } drawers[0].DrawProperty(property, label); if (setIsBoldState) { GUIHelper.PopIsBoldLabel(); } } else { if (property.Info.PropertyType == PropertyType.Method) { EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the method property '" + property.Name + "' with signature '" + property.Info.MemberInfo.GetNiceName() + "'."); } else if (property.Info.PropertyType == PropertyType.Group) { var attr = property.Info.GetAttribute <PropertyGroupAttribute>(); if (attr != null) { EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the property group '" + property.Name + "' with property group attribute type '" + attr.GetType().GetNiceName() + "'."); } else { EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the property group '" + property.Name + "'."); } } //else if (property.Info.GetAttribute<HideInInspector>() == null) //{ // EditorGUILayout.LabelField(property.NiceName, "No drawers could be found for the value property '" + property.Name + "' of type '" + property.ValueEntry.TypeOfValue.GetNiceName() + "'."); //} } } catch (Exception ex) { if (ex is ExitGUIException || ex.InnerException is ExitGUIException) { throw ex; } else { var msg = "This error occurred while being drawn by ODIN. \n" + "ODIN Property Path: " + property.Path + "\n" + "ODIN Drawer Chain: " + string.Join(", ", drawers.Select(n => n.GetType().GetNiceName()).ToArray()) + "."; Debug.LogException(new OdinPropertyException(msg, ex)); } } } if (Event.current.type != EventType.Layout) { property.LastDrawnValueRect = GUIHelper.EndLayoutMeasuring(); } } finally { property.PopDraw(); if (popGUIEnabled) { GUIHelper.PopGUIEnabled(); } } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(InspectorProperty property, InfoBoxAttribute attribute, GUIContent label) { PropertyContext <InfoBoxContext> context = null; context = property.Context.Get(this, "Config_" + this.GetHashCode(), (InfoBoxContext)null); if (context.Value == null) { context.Value = new InfoBoxContext() { MessageHelper = new StringMemberHelper(property.ParentType, attribute.Message) }; context.Value.ErrorMessage = context.Value.MessageHelper.ErrorMessage; MemberInfo memberInfo; if (attribute.VisibleIf != null) { // Parameter functions if (property.ValueEntry != null && property.ParentType.FindMember() .IsMethod() .HasReturnType <bool>() .HasParameters(property.ValueEntry.BaseValueType) .IsNamed(attribute.VisibleIf) .TryGetMember(out memberInfo, out context.Value.ErrorMessage)) { if (context.Value.ErrorMessage == null) { if (memberInfo is MethodInfo) { if (memberInfo.IsStatic()) { context.Value.StaticValidationParameterMethod = memberInfo as MethodInfo; } else { context.Value.InstanceValidationParameterMethod = memberInfo as MethodInfo; } } else { context.Value.ErrorMessage = "Invalid member type!"; } } } // Fields, properties, and no-parameter functions. else if (property.ParentType.FindMember() .HasReturnType <bool>() .HasNoParameters() .IsNamed(attribute.VisibleIf) .TryGetMember(out memberInfo, out context.Value.ErrorMessage)) { if (context.Value.ErrorMessage == null) { if (memberInfo is FieldInfo) { if (memberInfo.IsStatic()) { context.Value.StaticValidationCaller = EmitUtilities.CreateStaticFieldGetter <bool>(memberInfo as FieldInfo); } else { context.Value.InstanceValueGetter = EmitUtilities.CreateWeakInstanceFieldGetter(property.ParentType, memberInfo as FieldInfo); } } else if (memberInfo is PropertyInfo) { if (memberInfo.IsStatic()) { context.Value.StaticValidationCaller = EmitUtilities.CreateStaticPropertyGetter <bool>(memberInfo as PropertyInfo); } else { context.Value.InstanceValueGetter = EmitUtilities.CreateWeakInstancePropertyGetter(property.ParentType, memberInfo as PropertyInfo); } } else if (memberInfo is MethodInfo) { if (memberInfo.IsStatic()) { context.Value.StaticValidationCaller = (Func <bool>)Delegate.CreateDelegate(typeof(Func <bool>), memberInfo as MethodInfo); } else { context.Value.InstanceValidationMethodCaller = EmitUtilities.CreateWeakInstanceMethodCallerFunc <bool>(memberInfo as MethodInfo); } } else { context.Value.ErrorMessage = "Invalid member type!"; } } } } } if (context.Value.ErrorMessage != null) { AllEditorGUI.ErrorMessageBox(context.Value.ErrorMessage); } else { if (Event.current.type == EventType.Layout) { var parentValue = property.ParentValues[0]; try { context.Value.DrawMessageBox = attribute.VisibleIf == null || (context.Value.StaticValidationParameterMethod != null && (bool)context.Value.StaticValidationParameterMethod.Invoke(null, new object[] { property.ValueEntry.WeakSmartValue })) || (context.Value.InstanceValidationParameterMethod != null && (bool)context.Value.InstanceValidationParameterMethod.Invoke(null, new object[] { property.ParentValues[0], property.ValueEntry.WeakSmartValue })) || (context.Value.InstanceValidationMethodCaller != null && context.Value.InstanceValidationMethodCaller(property.ParentValues[0])) || (context.Value.InstanceValueGetter != null && (bool)context.Value.InstanceValueGetter(ref parentValue)) || (context.Value.StaticValidationCaller != null && context.Value.StaticValidationCaller()); } catch (System.Exception ex) { Debug.LogException(ex); } } if (context.Value.DrawMessageBox) { switch (attribute.InfoMessageType) { case InfoMessageType.None: AllEditorGUI.MessageBox(context.Value.MessageHelper.GetString(property)); break; case InfoMessageType.Info: AllEditorGUI.InfoMessageBox(context.Value.MessageHelper.GetString(property)); break; case InfoMessageType.Warning: AllEditorGUI.WarningMessageBox(context.Value.MessageHelper.GetString(property)); break; case InfoMessageType.Error: AllEditorGUI.ErrorMessageBox(context.Value.MessageHelper.GetString(property)); break; default: AllEditorGUI.ErrorMessageBox("Unknown InfoBoxType: " + attribute.InfoMessageType.ToString()); break; } } } this.CallNextDrawer(property, label); }
private void DrawIntroInfoBox() { AllEditorGUI.InfoMessageBox(" 1. InfoMessageBox"); }