Exemplo n.º 1
0
        public static HReorderableList CreateInstance(SerializedObject serializedObject, string propertyName, int heightNum = 1, string headerName = "", bool drawer = false)
        {
            var s = new HReorderableList();

            s.Create(serializedObject, propertyName, heightNum, headerName, drawer);
            return(s);
        }
Exemplo n.º 2
0
        public static HReorderableList CreateInstance <T>(List <T> list, string headerName, int heightNum = 1) where T : class
        {
            var s = new HReorderableList();

            s.Create <T>(list, headerName, heightNum);
            return(s);
        }
Exemplo n.º 3
0
        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);
            }
        }