Ejemplo n.º 1
0
    private void DrawEventListener(Rect position, int index, bool isActive, bool isFocused)
    {
        GetInspectorState(serializedProperty);
        if (inspectorState == null || !inspectorState.inspectorDataIsNotNull || inspectorState.inspectorData == null || inspectorState.inspectorData.persistentCallData == null)
        {
            return;
        }

        // Calculate control positions
        int   indentLevel = EditorGUI.indentLevel;
        int   divisions   = 3;
        float top         = position.y + 4f;
        float left        = position.x + ToggleWidth - indentLevel * IndentValue;
        float fullWidth   = position.width - ToggleWidth;

        Rect  dynamicSize = new Rect(position.x - indentLevel * IndentValue, top, fullWidth, ControlHeight);
        float itemWidth   = dynamicSize.width / divisions;

        Rect controlRect0 = new Rect(left - ToggleWidth, top, ToggleWidth + indentLevel * IndentValue - 1f, ControlHeight);
        Rect controlRect1 = new Rect(left + 0f * itemWidth + 1f, top, itemWidth + indentLevel * IndentValue - 1f, ControlHeight);
        Rect controlRect2 = new Rect(left + 1f * itemWidth + 1f, top, itemWidth + indentLevel * IndentValue - 1f, ControlHeight);
        Rect controlRect3 = new Rect(left + 2f * itemWidth + 2f, top, itemWidth + indentLevel * IndentValue - 1f, ControlHeight);

        PersistentCallData persistentCall = inspectorState.inspectorData.persistentCallData[index];

        // Draw listener state toggle (enabled / disabled)
        EditorGUI.PropertyField(controlRect0, persistentCall.isCallEnabledProperty, GUIContent.none);
        // Draw target object field
        EditorGUI.BeginChangeCheck();
        EditorGUI.PropertyField(controlRect1, persistentCall.targetProperty, GUIContent.none);
        if (EditorGUI.EndChangeCheck())
        {
            // If the target object field has changed, update the inspector data and the dropdown selection
            inspectorState.inspectorData = new InspectorData(serializedProperty, inspectorState.inspectorData.label, position, inspectorState.inspectorData.indentLevel, GenericMenuSelectionHandler, NoFunctionHandler, fieldInfo);
            UpdateInspectorState(serializedProperty, inspectorState.reorderableList, inspectorState.inspectorData, true);
            persistentCall = inspectorState.inspectorData.persistentCallData[index];
            GenericMenuSelectionHandler(new MemberMenuIndex(serializedProperty, index, persistentCall.componentIndexProperty.intValue, persistentCall.memberIndexProperty.intValue, persistentCall.isDynamicDataProperty.boolValue));
        }

        if (persistentCall.targetProperty.objectReferenceValue == null)
        {
            GUI.enabled = false;
        }
        else if (Event.current != null && Event.current.type == EventType.MouseDown && controlRect2.Contains(Event.current.mousePosition))
        {
            persistentCall.genericMenu.DropDown(new Rect(controlRect2.x, controlRect2.y + 9f, 0f, 0f));
        }

        GUIStyle popupStyle = new GUIStyle(EditorStyles.popup);

        popupStyle.fixedHeight = ControlHeight;
        EditorGUI.LabelField(controlRect2, new GUIContent(persistentCall.shortSelectedOptionText, persistentCall.selectedOptionText), popupStyle);
        GUI.enabled = true;

        if (persistentCall.targetProperty.objectReferenceValue != null && persistentCall.componentIndexProperty.intValue != -1 && !persistentCall.isDynamicProperty.boolValue)
        {
            DrawArgumentField(controlRect3, index);
        }
    }
Ejemplo n.º 2
0
    private void GenericMenuSelectionHandler(object menuIndexInfo)
    {
        MemberMenuIndex menuIndex = menuIndexInfo as MemberMenuIndex;

        GetInspectorState(menuIndex.property);
        PersistentCallData persistentCall = inspectorState.inspectorData.persistentCallData[menuIndex.persistentCallIndex];

        if (menuIndex == null || persistentCall.targetProperty.objectReferenceValue == null)
        {
            return;
        }

        persistentCall.componentIndexProperty.intValue = menuIndex.componentIndex;
        persistentCall.memberIndexProperty.intValue    = menuIndex.memberIndex;
        persistentCall.isDynamicDataProperty.boolValue = menuIndex.isDynamic;
        persistentCall.isDynamicProperty.boolValue     = menuIndex.isDynamic;

        // Get the info of the option we selected in the generic menu
        MemberMenuItem menuItem = persistentCall.genericMenuData.GetComponent(menuIndex.componentIndex).GetMemberItem(menuIndex.memberIndex, menuIndex.isDynamic);

        // Set target object to reference of component selected in generic dropdown menu
        persistentCall.targetProperty.objectReferenceValue = (menuIndex.componentIndex < 0) ? persistentCall.targetGameObject : persistentCall.genericMenuData.GetComponent(menuIndex.componentIndex).component;

        if (menuItem == null)
        {
            return;
        }

        // Set target object to reference of component selected in generic dropdown menu
        persistentCall.targetProperty.objectReferenceValue = persistentCall.genericMenuData.GetComponent(menuIndex.componentIndex).component;
        // Set memberName to string at selectedIndex
        persistentCall.memberNameProperty.stringValue = menuItem.memberInfo.Name;
        // Set memberType enum value
        persistentCall.memberTypeProperty.enumValueIndex = GetMemberTypeIndex(menuItem.memberInfo.MemberType);

        // Set the function argument type
        Type argumentType = typeof(void);

        if (menuItem.memberInfo.MemberType == MemberTypes.Method)
        {
            ParameterInfo[] parameterInfo = (menuItem.memberInfo as MethodInfo).GetParameters();
            argumentType = parameterInfo.Length == 0 ? typeof(void) : parameterInfo[0].ParameterType;
        }
        else if (menuItem.memberInfo.MemberType == MemberTypes.Property)
        {
            argumentType = (menuItem.memberInfo as PropertyInfo).PropertyType;
        }
        else if (menuItem.memberInfo.MemberType == MemberTypes.Field)
        {
            argumentType = (menuItem.memberInfo as FieldInfo).FieldType;
        }

        persistentCall.argumentTypeProperty.enumValueIndex = (int)GetArgumentType(argumentType);
        inspectorState.inspectorData.UpdateDataValues(menuIndex.persistentCallIndex);
        inspectorState.inspectorData.property.serializedObject.ApplyModifiedProperties(); //TODO?

        GUIUtility.hotControl = 0;
    }
Ejemplo n.º 3
0
        public InspectorData(SerializedProperty property, GUIContent label, Rect position, int indentLevel, GenericMenu.MenuFunction2 menuSelectionHandler, GenericMenu.MenuFunction2 noFunctionHandler, FieldInfo fieldInfo)
        {
            this.property     = property;
            this.listProperty = property.FindPropertyRelative("persistentCalls").FindPropertyRelative("calls");

            this.position             = position;
            this.indentLevel          = indentLevel;
            this.label                = label;
            this.menuSelectionHandler = menuSelectionHandler;
            this.noFunctionHandler    = noFunctionHandler;

            object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EventFilterAttribute), false);
            if (customAttributes.Length == 1)
            {
                filterAttribute = customAttributes[0] as EventFilterAttribute;
            }

            Type[] genericArguments = fieldInfo.FieldType.BaseType.GetGenericArguments();
            if (genericArguments.Length == 1)
            {
                eventType = genericArguments[0];
            }

            eventHeaderText = label.text + " (";
            for (int i = 0; i < genericArguments.Length; i++)
            {
                eventHeaderText += GetCleanTypeName(genericArguments[i]);
                if (i < genericArguments.Length - 1)
                {
                    eventHeaderText += ", ";
                }
            }
            eventHeaderText += ")";

            persistentCallData = new PersistentCallData[listProperty.arraySize];
            for (int i = 0; i < listProperty.arraySize; i++)
            {
                persistentCallData[i] = new PersistentCallData(this, i, indentLevel, position, property, listProperty, menuSelectionHandler, noFunctionHandler);
            }
        }
Ejemplo n.º 4
0
    private void NoFunctionHandler(object menuIndexInfo)
    {
        MemberMenuIndex menuIndex = menuIndexInfo as MemberMenuIndex;

        if (menuIndex == null)
        {
            return;
        }

        GetInspectorState(menuIndex.property);

        // Clear serialized member name and type info
        PersistentCallData persistentCall = inspectorState.inspectorData.persistentCallData[menuIndex.persistentCallIndex];

        persistentCall.componentIndexProperty.intValue     = -1;
        persistentCall.memberNameProperty.stringValue      = "";
        persistentCall.memberTypeProperty.enumValueIndex   = GetMemberTypeIndex(MemberTypes.Method);
        persistentCall.argumentTypeProperty.enumValueIndex = (int)QuickSupportedTypes.Void;

        inspectorState.inspectorData.UpdateDataValues(menuIndex.persistentCallIndex);
        inspectorState.inspectorData.property.serializedObject.ApplyModifiedProperties();

        GUIUtility.hotControl = 0;
    }
Ejemplo n.º 5
0
 public void UpdateDataValues(int index)
 {
     // Update PersistentCallData values
     persistentCallData[index] = new PersistentCallData(this, index, indentLevel, position, property, listProperty, menuSelectionHandler, noFunctionHandler);
 }