void _Draw(SerializedProperty it, ref bool fold) { Type type = null; var field = ScriptAttributeUtility.GetFieldInfoFromProperty(it, ref type); var attrs = ScriptAttributeUtility.GetFieldAttributes(field); //Debug.Log(it.displayName); if (GetHas(attrs, typeof(GroupAttribute))) { if (!_foldLists.ContainsKey(it.displayName)) { _foldLists.Add(it.displayName, true); } var atb = Get <GroupAttribute>(attrs); var rect = GUILayoutUtility.GetRect(EditorHelper.TempContent(it.displayName), EditorStyles.helpBox); if (Event.current.type == EventType.Repaint) { var rect2 = rect; rect2.x -= 16; rect2.width += 16; EditorStyles.helpBox.Draw(rect2, false, false, false, false); } var sss = ""; if (atb.prefix) { sss = "Group - "; } sss += atb.name; _foldLists[it.displayName] = EditorGUI.Foldout(rect, _foldLists[it.displayName], sss, true); fold = _foldLists[it.displayName]; //EditorGUILayout.LabelField( it.displayName ); //if( _foldLists[ it.displayName ] ) { // EditorGUILayout.PropertyField( it, true ); //} //if( fold ) { // EditorGUI.indentLevel++; //} //else { // EditorGUI.indentLevel--; //} } if (fold == false) { return; } #if false if (it.isArray && type != typeof(string)) { HReorderableList lst = null; _reorderableLists.TryGetValue(it.displayName, out lst); if (lst == null) { lst = HReorderableList.CreateInstance(serializedObject, it.name); _reorderableLists.Add(it.displayName, lst); } //EditorGUILayout.LabelField( it.displayName ); lst.DoLayoutList(); } //else if( it.propertyType == SerializedPropertyType.Vector3 ) { //} else #endif //if( GetHas( attrs, typeof( PropertyAttribute ) ) { // var hander = UnityScriptAttributeUtility.GetHandler( it ); // hander.MethodInvoke<bool>( "OnGUI", new object[] { } ); //} //OnGUI( Rect position, SerializedProperty property, GUIContent label, bool includeChildren ) #if UNITY_2019_3_OR_NEWER if (it.propertyType == SerializedPropertyType.ManagedReference) { DrawSerializeReference(it); } else #endif if (it.propertyType == SerializedPropertyType.ObjectReference && !GetHas(attrs, typeof(PropertyAttribute))) { if (it.objectReferenceValue == null) { //EditorGUILayout.PropertyField( it, true ); //Debug.Log( it.GetTypeReflection().Name ); //if( it.GetTypeReflection() == typeof( Sprite ) ) { // it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue,typeof( Sprite), false ); //} //else { // EditorGUILayout.PropertyField( it, true ); //} ScopeHorizontal.Begin(); it.objectReferenceValue = EditorGUILayout.ObjectField(it.displayName, it.objectReferenceValue, type, true); if (HEditorGUILayout.IconButton(EditorIcon.plus, 3)) { var so = CreateInstance(type); var path = $"Assets/New {type.Name}.asset".GenerateUniqueAssetPath(); AssetDatabase.CreateAsset(so, path); AssetDatabase.Refresh(); it.objectReferenceValue = so; } ScopeHorizontal.End(); //it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, it.GetTypeReflection(), true ); //it.objectReferenceValue=EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, it.GetTypeReflection(), true, GUILayout.Height() ); } else if (it.objectReferenceValue.GetType() == typeof(Animator)) { HEditorGUI.PropertyField(it, EditorIcon.unityeditor_animationwindow, () => { EditorWindowUtils.Find(UnityTypes.UnityEditor_AnimationWindow); }, EditorIcon.unityeditor_graphs_animatorcontrollertool, () => { EditorWindowUtils.Find(UnityTypes.UnityEditor_Graphs_AnimatorControllerTool); }); } else if (it.objectReferenceValue.GetType().IsSubclassOf(typeof(ScriptableObject))) { Editor ed = null; if (_editorLists == null) { return; } _editorLists.TryGetValue(it.displayName, out ed); if (ed == null) { ed = Editor.CreateEditor(it.objectReferenceValue); _editorLists.Add(it.displayName, ed); } var h = EditorStyles.objectField.CalcHeight(GUIContent.none, 10); EditorGUILayout.PropertyField(it, EditorHelper.TempContent(" "), true); var r = GUILayoutUtility.GetLastRect(); r.y = r.yMax - h; r.height = h; it.isExpanded = EditorGUI.Foldout(r, it.isExpanded, EditorHelper.TempContent(it.displayName), true); if (it.isExpanded) { try { EditorGUI.indentLevel++; EditorGUIUtility.hierarchyMode = false; ScopeVertical.Begin(/*EditorStyles.helpBox*/); ed.OnInspectorGUI(); //GUILayout.FlexibleSpace(); ScopeVertical.End(); EditorGUIUtility.hierarchyMode = true; EditorGUI.indentLevel--; } catch (Exception e) { Debug.LogException(e); } } } else { //HGUIScope.Horizontal(_); //void _() { //it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, type, true ); EditorGUILayout.PropertyField(it, EditorHelper.TempContent(L10n.Tr(it.displayName)), true); // GUILayout.Button("aaaa"); //} } } else { //Debug.Log( type .Name); EditorGUILayout.PropertyField(it, EditorHelper.TempContent(L10n.Tr(it.displayName)), true); } }
public void Create(SerializedObject serializedObject, string propertyName, int heightNum = 1, string headerName = "", bool drawer = false) { m_serializedObject = serializedObject; m_serializedProperty = serializedObject.FindProperty(propertyName); m_headerName = headerName; m_lst = new ReorderableList(serializedObject, m_serializedProperty); m_lstMethod = new UnityEditorInternalReorderableList(m_lst); if (drawer) { m_lst.drawElementCallback = (rect, index, isActive, isFocused) => { var rc1 = rect; rc1.y += 1; rc1.height = EditorGUIUtility.singleLineHeight; EditorGUI.PropertyField(rc1, serializedObject.FindProperty(propertyName + ".Array.data[" + index + "]")); }; } else { m_lst.drawElementCallback = (rect, index, isActive, isFocused) => { var rc1 = rect; rc1.y += 1; rc1.height = EditorGUIUtility.singleLineHeight; var prop = serializedObject.FindProperty(propertyName + ".Array.data[" + index + "]"); var hander = new PropertyHandler(ScriptAttributeUtility.GetHandler(prop)); try { if (hander.hasPropertyDrawer) { //m_lst.elementHeightCallback = (index2) => { // var prop2 = serializedObject.FindProperty( propertyName + ".Array.data[" + index2 + "]" ); // var hander2 = UnityScriptAttributeUtility.GetHandler( prop2 ); // return hander2.GetProperty<PropertyDrawer>( "propertyDrawer" ).GetPropertyHeight( prop2, EditorHelper.TempContent( prop2.displayName ) ); //}; // m_lst.elementHeight = hander.GetProperty<PropertyDrawer>( "propertyDrawer" ).GetPropertyHeight( prop, EditorHelper.TempContent( prop.displayName ) ); EditorGUI.PropertyField(rc1, prop); } else if (prop != null) { if (prop.propertyType == SerializedPropertyType.Generic) { prop.Next(true); int ii = 0; int depth = prop.depth; do { EditorGUI.PropertyField(rc1, prop); rc1.y += EditorGUIUtility.singleLineHeight; //if( prop.propertyType == SerializedPropertyType.Vector3 ) { // rc1.y += EditorGUIUtility.singleLineHeight; // ii++; //} ii++; if (prop.Next(false) == false) { break; } } while(depth == prop.depth); m_lst.elementHeight = (EditorGUIUtility.singleLineHeight * ii) + 4; } else { var cont = EditorHelper.TempContent($"0x{index:X02}:"); var size = EditorStyles.label.CalcSize(cont); rc1.width = 40; EditorGUI.LabelField(rc1, cont); var rc2 = rect; rc2.x = rc1.xMax; rc2.width = rect.width - 40; rc2.y += 1; rc2.height = EditorGUIUtility.singleLineHeight; EditorGUI.PropertyField(rc2, prop, GUIContent.none); } } } catch (NullReferenceException e) { Debug.LogException(e); } //if( !prop.hasChildren ) { // return; //} //prop.Next( true ); //int ii = 0; //int depth = prop.depth; //do { // EditorGUI.PropertyField( rc1, prop ); // rc1.y += EditorGUIUtility.singleLineHeight; // ii++; // prop.Next( false ); //} while( depth == prop.depth ); //m_lst.elementHeight = ( EditorGUIUtility.singleLineHeight * ii ) + 4; }; } m_lst.drawHeaderCallback = (rect) => { var rc1 = rect; rc1.x += 10; string title; if (m_headerName.IsEmpty()) { title = $"{m_serializedProperty.displayName}"; } else { title = m_headerName; } if (!m_serializedProperty.isExpanded) { title = $"{title} [{m_serializedProperty.arraySize}]"; } m_serializedProperty.isExpanded = EditorGUI.Foldout(rc1, m_serializedProperty.isExpanded, title); }; m_lst.elementHeight = (EditorGUIUtility.singleLineHeight * heightNum) + 4; }