TylerTemp / SaintsField

A Unity Inspector extension tool focusing on script fields inspector enhancement
MIT License
148 stars 9 forks source link

Show if not working for Generic type variables #27

Closed fawad0dev closed 3 months ago

fawad0dev commented 3 months ago

Here is my code

[Serializable]
    public enum RCType
    {
        Int,
        Float,
        Bool,
        String,
        Long,
        Json
    }
    [Serializable]
    public class ValueDetail<T>
    {
        public T Value;
        public T defaultValue;
    }
    [SerializeField] RCValue[] rCValues;
    [Serializable]
    public class RCValue
    {
        public string key;
        public RCType valueType;
        [ShowIf(nameof(valueType), RCType.Int)] public ValueDetail<int> intValue; //this is not working
        [ShowIf(nameof(valueType), RCType.Int)] public UnityEvent<int> onIntValueFetched; //this is not working
        [ShowIf(nameof(valueType), RCType.Float)] public ValueDetail<float> floatValue; //this is not working
        [ShowIf(nameof(valueType), RCType.Float)] public UnityEvent<float> onFloatValueFetched; //this is not working
        [ShowIf(nameof(valueType), RCType.Bool)] public ValueDetail<bool> boolValue; //this is not working
        [ShowIf(nameof(valueType), RCType.Bool)] public UnityEvent<bool> onBoolValueFetched; //this is not working
        [ShowIf(nameof(valueType), RCType.String)] public ValueDetail<string> stringValue; //this is not working
        [ShowIf(nameof(valueType), RCType.String)] public UnityEvent<string> onStringValueFetched; //this is not working
        [ShowIf(nameof(valueType), RCType.Long)] public ValueDetail<long> longValue; //this is not working
        [ShowIf(nameof(valueType), RCType.Long)] public UnityEvent<long> onLongValueFetched; //this is not working
        [ShowIf(nameof(valueType), RCType.Json)] public ValueDetail<string> jsonValue; //this is not working
        [ShowIf(nameof(valueType), RCType.Json)] public UnityEvent<string> onJsonValueFetched; //this is not working
    }
    [Serializable]
    public enum EnumToggle
    {
        Off,
        On,
    }
    public EnumToggle enum1;
    [ShowIf(nameof(enum1), EnumToggle.On)] public string enum1Show; // this is working fine

Read Comments also it is giving this error

InvalidOperationException: This operation is only valid on generic types.
System.RuntimeType.GetGenericTypeDefinition () (at <dc753a1061284f8e971ee88ee4826eee>:0)
SaintsField.Editor.Core.SaintsPropertyDrawer.FindOtherPropertyDrawer (System.Reflection.FieldInfo fieldInfo) (at Assets/SaintsField/Editor/Core/SaintsPropertyDrawer.cs:513)
SaintsField.Editor.Core.SaintsPropertyDrawer.UnityFallbackUIToolkit (System.Reflection.FieldInfo fieldInfo, UnityEditor.SerializedProperty property) (at Assets/SaintsField/Editor/Core/SaintsPropertyDrawer.cs:599)
SaintsField.Editor.Core.SaintsPropertyDrawer.CreatePropertyGUI (UnityEditor.SerializedProperty property) (at Assets/SaintsField/Editor/Core/SaintsPropertyDrawer.cs:839)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.SerializedProperty newProperty) (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.UIElements.SerializedPropertyBindEvent evt) (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEditor.UIElements.PropertyField.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtCurrentTargetAndPhase (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetAndDefaultPhase (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.SendBindingEvent[TEventType] (TEventType evt, UnityEngine.UIElements.VisualElement target) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEditor.UIElements.Bindings.ListViewSerializedObjectBinding.BindListViewItem (UnityEngine.UIElements.VisualElement ve, System.Int32 index) (at <048d7ee56c5c4cc8ada009ff13759d47>:0)
UnityEngine.UIElements.ListViewController.BindItem (UnityEngine.UIElements.VisualElement element, System.Int32 index) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CollectionViewController.InvokeBindItem (UnityEngine.UIElements.ReusableCollectionItem reusableItem, System.Int32 index) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.BaseListViewController.InvokeBindItem (UnityEngine.UIElements.ReusableCollectionItem reusableItem, System.Int32 index) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.VerticalVirtualizationController`1[T].Setup (T recycledItem, System.Int32 newIndex) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.DynamicHeightVirtualizationController`1[T].Resize (UnityEngine.Vector2 size) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.Resize (UnityEngine.Vector2 size) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.OnSizeChanged (UnityEngine.UIElements.GeometryChangedEvent evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.EventCallbackRegistry.InvokeCallbacks (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtCurrentTargetAndPhase (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetAndDefaultPhase (UnityEngine.UIElements.EventBase evt) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.UIRLayoutUpdater.DispatchChangeEvents (System.Collections.Generic.List`1[T] changeEvents, System.Int32 currentLayoutPass) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.UIRLayoutUpdater.Update () (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.UIElements.Panel.UpdateWithoutRepaint () (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEditor.EditorElementUpdater.CreateInspectorElementsForViewport (UnityEngine.UIElements.ScrollView viewport, UnityEngine.UIElements.VisualElement contentContainer) (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEditor.PropertyEditor.RebuildContentsContainers () (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEditor.PropertyEditor.OnGUI () (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect dockAreaRect) (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEditor.DockArea.OldOnGUI () (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <f67debe1efd242948106f1922bfac1c7>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

image

TylerTemp commented 3 months ago

Hi,

Thanks for reporting this bug. The fix has been submitted to dev branch, and I'll release a new version tomorrow which will include this bug fix.

TylerTemp commented 3 months ago

Hi,

Please check if it's fixed in 3.0.8

image

TylerTemp commented 3 months ago

Hi, if you still have any issue about this feature, plz comment and I'll re-open it.

Closed as fixed.