Closed ZeroUltra closed 6 months ago
Unity2021.3.33 Unity2022.3.16
Thanks for reporting.
This is because:
Directly using on list/array will apply to every direct element of the list, this is a limit from Unity.
The solution is to write one attribute for SaintsEditor
.
This will be implemented in the future. But please note, SaintsEditor
is not a core value of this project (it just works), so it‘s low priority and might take some time (versions) to see this happens.
Thank you for your reply. I look forward to this feature.
If someone desperately needs it, I have another plan, though not perfect.
[System.Serializable]
public class NestedArray<T>
{
public T[] Array;
}
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[AttributeUsage(AttributeTargets.Field, Inherited = true)] public class HideNestedArrayAttribute : PropertyAttribute {
}
[CustomPropertyDrawer(typeof(HideNestedArrayAttribute))] public class HideNestedArrayDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var array = property.FindPropertyRelative("Array"); EditorGUI.PropertyField(position, array, new GUIContent(property.displayName)); } public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { var array = property.FindPropertyRelative("Array"); // These numbers are tried out. I don't know how to get it. if (array.isExpanded) { return 70 + Mathf.Clamp((array.arraySize-1) * 20, 0, float.MaxValue); } else return 20; } }
ok, test it
using UnityEngine; using SaintsField;
public class NewMonoBehaviour : MonoBehaviour
{
public bool useIds;
[ShowIf("useIds"), HideNestedArray]
public NestedArray
public TestArray testArray;
public TestArray[] testArrays;
[System.Serializable]
public class TestArray
{
public bool useIds;
[ShowIf("useIds"), HideNestedArray]
public NestedArray<int> ids;
}
}
![image](https://github.com/TylerTemp/SaintsField/assets/38253805/119e3702-4b10-4902-913f-62917d327fc2)
Please update 2.1.12 to use PlayaShowIf
/PlayaHideIf
for array. Note: you need to enable SaintsEditor
to make it work. See Set Up SaintsEditor in document. And note:
Please note, any Editor level component can not work together with each other (it will not cause trouble, but only one will actually work). Which means, OdinInspector, NaughtyAttributes, MarkupAttributes, SaintsEditor can not work together.
If the attributes have any errors, please open a new issue )))
Hi !!! code like this: