Beispiel #1
0
        public PrettyListViewer(
            SerializedObject serializedObject,
            SerializedProperty elements,
            HeaderCallbackDelegate onDrawHeader,
            ElementCallbackDelegate onDrawElement,
            ElementHeightCallbackDelegate elementHeightGetter,
            ReorderCallbackDelegate onReorder = null,
            AddCallbackDelegate onAdd         = null,
            RemoveCallbackDelegate onRemove   = null
            ) : base(serializedObject, elements)
        {
            drawHeaderCallback    = onDrawHeader;
            drawElementCallback   = onDrawElement;
            elementHeightCallback = elementHeightGetter;

            if (onReorder != null)
            {
                draggable         = true;
                onReorderCallback = onReorder;
            }
            else
            {
                draggable = false;
            }

            if (onAdd != null)
            {
                displayAdd    = true;
                onAddCallback = onAdd;
            }
            else
            {
                displayAdd = false;
            }

            if (onRemove != null)
            {
                displayRemove    = true;
                onRemoveCallback = onRemove;
            }
            else
            {
                displayRemove = false;
            }
        }
Beispiel #2
0
        private void InitUIBinds()
        {
            AddCallbackDelegate onAddCallback = list =>
            {
                list.serializedProperty.arraySize++;
                var element = list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1);
                if (element.propertyType == SerializedPropertyType.String)
                {
                    element.stringValue = null;
                }
                else if (element.propertyType == SerializedPropertyType.ObjectReference)
                {
                    element.objectReferenceValue = null;
                }
            };

            RemoveCallbackDelegate onRemoveCallback = list =>
            {
                list.serializedProperty.DeleteArrayElementAtIndex(list.index);
            };

            m_ObjectBinds                    = property.FindPropertyRelative("m_ObjectBinds");
            m_ObjectList                     = new ReorderableList(property.serializedObject, m_ObjectBinds);
            m_ObjectList.headerHeight        = 0;
            m_ObjectList.draggable           = false;
            m_ObjectList.onAddCallback       = onAddCallback;
            m_ObjectList.onRemoveCallback    = onRemoveCallback;
            m_ObjectList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                var element = m_ObjectBinds.GetArrayElementAtIndex(index);
                element.objectReferenceValue = EditorGUI.ObjectField(rect, element.objectReferenceValue, typeof(MonoBehaviour), allowSceneObjects: true);
            };

            m_Events     = property.FindPropertyRelative("m_Events");
            m_EventsList = new ReorderableList(property.serializedObject, m_Events);
            m_EventsList.headerHeight        = 0;
            m_EventsList.draggable           = false;
            m_EventsList.onAddCallback       = onAddCallback;
            m_EventsList.onRemoveCallback    = onRemoveCallback;
            m_EventsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                var element = m_Events.GetArrayElementAtIndex(index);
                element.stringValue = EditorGUI.TextField(rect, element.stringValue);
            };
            m_EventsList.onSelectCallback = list =>
            {
                var element   = m_Events.GetArrayElementAtIndex(list.index);
                var table     = property.serializedObject.targetObject as UIMaster;
                var binders   = table.GetComponentsInChildren <UIEventBindBase>(true);
                var eventName = element.stringValue;
                if (string.IsNullOrEmpty(eventName))
                {
                    return;
                }
                foreach (var binder in binders)
                {
                    if (binder.EventTable == table && binder.IsListenEvent(eventName))
                    {
                        Debug.Log(string.Format("EventTable:{2}, 监听事件:{0}, 节点名:{1}", eventName, binder.ToString(), table.ToString()), binder);
                    }
                }
            };

            m_VariableBinds                    = property.FindPropertyRelative("m_VariableBinds");
            m_VariableList                     = new ReorderableList(property.serializedObject, m_VariableBinds);
            m_VariableList.headerHeight        = 0;
            m_VariableList.elementHeight      *= 2;
            m_VariableList.draggable           = false;
            m_VariableList.onAddCallback       = onAddCallback;
            m_VariableList.onRemoveCallback    = onRemoveCallback;
            m_VariableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                var element = m_VariableBinds.GetArrayElementAtIndex(index);
                EditorGUI.PropertyField(rect, element);
            };
            m_VariableList.onSelectCallback = list =>
            {
                var element      = m_VariableBinds.GetArrayElementAtIndex(list.index);
                var table        = property.serializedObject.targetObject as UIMaster;
                var binders      = table.GetComponentsInChildren <UIVariableBindBase>(true);
                var variableName = element.FindPropertyRelative("Name").stringValue;
                if (string.IsNullOrEmpty(variableName))
                {
                    return;
                }
                foreach (var binder in binders)
                {
                    if (binder.VariableTable == table && binder.IsVariableBinded(variableName))
                    {
                        Debug.Log(string.Format("VariableTable:{2}, 监听变量:{0}, 节点名:{1}", variableName, binder.ToString(), table.ToString()), binder);
                    }
                }
            };
        }
Beispiel #3
0
    public ReorderableList CreateRecordList(SerializedObject serializedObject, string varName, string title,
                                            ReorderCallbackDelegate onreorder, SelectCallbackDelegate onselect, AddCallbackDelegate onadd, RemoveCallbackDelegate onremove)
    {
        var reordList = new ReorderableList(serializedObject, serializedObject.FindProperty(varName), true, true, true, true);

        reordList.displayAdd         = reordList.displayRemove = true;
        reordList.drawHeaderCallback = (Rect rect) =>
        {
            EditorGUI.LabelField(rect, title, EditorStyles.boldLabel);
            Texture2D btnTexture = reordList.elementHeight == 0f ? EditorGUIUtility.FindTexture("winbtn_win_max_h") : EditorGUIUtility.FindTexture("winbtn_win_min_h");
            if (GUI.Button(new Rect(rect.width + 4, rect.y + 2, rect.height, rect.height), btnTexture, EditorStyles.label))
            {
                reordList.elementHeight = reordList.elementHeight == 0f ? 21f : 0f;
                reordList.draggable     = reordList.elementHeight > 0f;
            }
        };
        reordList.onReorderCallback = onreorder;
        reordList.onSelectCallback  = onselect;
        reordList.onAddCallback     = onadd;
        reordList.onRemoveCallback  = onremove;
        return(reordList);
    }