Exemplo n.º 1
0
        private void Init(SerializedProperty property)
        {
            _property       = property;
            _methodDropdown = new MethodsDropdown(new AdvancedDropdownState(), null);
            _methodDropdown.OnItemSelected = OnMethodSelected;
            _targetEventEntry = property.GetValue <EnhancedEventEntry>();

            if (_targetEventEntry.Delegate != null)
            {
                _eventTargetObject = _targetEventEntry.Delegate.Target as Object;
                _selectedInfo      = new DelegateInfo(_eventTargetObject, _targetEventEntry.Delegate.Method);
                _parameters        = _selectedInfo.Method.GetParameters();
            }
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (_targetEventEntry == null)
            {
                Init(property);
            }

            SetRects(position);

            _eventTargetObject = EditorGUI.ObjectField(_objectFieldRect, _eventTargetObject, typeof(Object), true);

            if (_methodDropdown.Target != _eventTargetObject)
            {
                _methodDropdown = new MethodsDropdown(new AdvancedDropdownState(), _eventTargetObject);
                _methodDropdown.OnItemSelected = OnMethodSelected;
            }

            string selectedName = "No Function";

            if (_selectedInfo != null)
            {
                selectedName = $" {_selectedInfo.Target.GetType().Name}.{_selectedInfo.Method.Name}";
            }

            using (new EditorGUI.DisabledScope(_eventTargetObject == null))
            {
                if (GUI.Button(_popupFieldRect, selectedName, "MiniPopup"))
                {
                    _methodDropdown.Show(_popupFieldRect);
                }
            }

            // Draw parameters.
            if (_selectedInfo != null)
            {
                foreach (ParameterInfo parameter in _parameters)
                {
                    DrawParameterField(parameter);
                }
            }
        }