示例#1
0
    EventBindingConnection GetConnectionByComponent(EventBindInfo config)
    {
        if (config.component is Button)
        {
            return(new ButtonEventBindingConnection(ViewModel, config));
        }
        else if (config.component is Toggle)
        {
            return(new ToggleEventBindingConnection(ViewModel, config));
        }
        else if (config.component is Slider)
        {
            return(new SliderEventBindingConnection(ViewModel, config));
        }

        return(null);
    }
示例#2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        EventBindInfo bindingInfo  = property.GetSerializedValue <EventBindInfo>();
        string        title        = bindingInfo.component == null ? "NULL" : bindingInfo.component.ToString();
        GUIContent    titleContent = new GUIContent(title);

        if (property.isExpanded)
        {
            property.isExpanded = EditorGUI.Foldout(new Rect(position.position - new Vector2(0, 20), position.size), property.isExpanded, titleContent, false);
        }
        else
        {
            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, titleContent, true);
        }
        if (property.isExpanded)
        {
            var amountRect = new Rect(position.x, position.y + 20, position.width, 20);
            var unitRect   = new Rect(position.x, position.y + 40, position.width, 20);

            EditorGUI.PropertyField(amountRect, property.FindPropertyRelative("component"), GUIContent.none);

            SerializedObject   o  = property.serializedObject;
            Type               tO = o.targetObject.GetType();
            PropertyInfo       viewModelProperty = tO.GetProperty("ViewModel", BindingFlags.Public | BindingFlags.Instance);
            string             typeModel         = viewModelProperty.PropertyType.Name;
            SerializedProperty propertyProperty  = property.FindPropertyRelative("invokeFunctionName");
            List <string>      propertyList      = EditorPropertyCache.GetMethodAndPropertys(typeModel, bindingInfo.component.GetType());

            if (propertyList.Count > 0)
            {
                int index = propertyList.IndexOf(propertyProperty.stringValue);
                index = EditorGUI.Popup(unitRect, index, propertyList.ToArray());
                if (index >= 0)
                {
                    propertyProperty.stringValue = propertyList[index];
                }
            }
        }

        EditorGUI.EndProperty();
    }
        /// <summary>
        /// 增加控件绑定事件
        /// </summary>
        void AddCtrlBindEvent(XmlTemplate xml)
        {
            var _cc = ParseControlConfig.GetControlConfig(CurrentSelectedSetEventControl.GetType().Name);
            var _be = _cc.Events.Where(p => p.Name.Equals(this.EventName)).GetFirst <BindEvent>();

            EventBindInfo _ebi = new EventBindInfo();

            _ebi.ControlName = this.EventControlName;
            _ebi.Item        = new List <CtrlBindEventInfo>();

            CtrlBindEventInfo _cbei = new CtrlBindEventInfo();

            _cbei.EventName        = this.EventName;
            _cbei.AssemblyName     = _be.AssemblyName;
            _cbei.BindFunctionName = _be.BindFunctionName;
            _ebi.Item.Add(_cbei);

            xml.EventBindItem.Add(_ebi);
            IDesignFramework.UpdateCurrentTemplate();
        }
示例#4
0
 public SliderEventBindingConnection(BaseViewModel viewModel, EventBindInfo eventBindInfo) : base(viewModel, eventBindInfo)
 {
 }
示例#5
0
 public ToggleEventBindingConnection(BaseViewModel viewModel, EventBindInfo eventBindInfo) : base(viewModel, eventBindInfo)
 {
 }
示例#6
0
 public ButtonEventBindingConnection(BaseViewModel viewModel, EventBindInfo eventBindInfo) : base(viewModel, eventBindInfo)
 {
 }
 public EventBindingConnection(BaseViewModel viewModel, EventBindInfo eventBindInfo) : base(viewModel, eventBindInfo)
 {
     Component = (T)eventBindInfo.component;
 }
示例#8
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        DataBindInfoDrawer.InitErrorStyle();

        EditorGUI.BeginProperty(position, label, property);

        EventBindInfo bindingInfo = property.GetSerializedValue <EventBindInfo>();

        if (bindingInfo == null)
        {
            return;
        }

        string title = bindingInfo.component == null ? "NULL" : bindingInfo.component.ToString();

        bool error = bindingInfo.component == null ||
                     string.IsNullOrEmpty(bindingInfo.invokeFunctionName);

        GUIStyle   style        = error ? DataBindInfoDrawer.errorStyle : EditorStyles.foldout;
        GUIContent titleContent = new GUIContent(title);

        property.isExpanded = EditorGUI.Foldout(new Rect(position.position, new Vector2(position.width, 20)),
                                                property.isExpanded, titleContent, true, style);

        if (property.isExpanded)
        {
            var amountRect = new Rect(position.x, position.y + 20, position.width, 20);
            var unitRect   = new Rect(position.x, position.y + 40, position.width, 20);

            EditorGUI.PropertyField(amountRect, property.FindPropertyRelative("component"), GUIContent.none);
            if (bindingInfo.component != null)
            {
                SerializedObject   o  = property.serializedObject;
                Type               tO = o.targetObject.GetType();
                FieldInfo          viewModelProperty = tO.GetField("ViewModel", BindingFlags.NonPublic | BindingFlags.Instance);
                Type               vmType            = viewModelProperty.FieldType;
                SerializedProperty propertyProperty  = property.FindPropertyRelative("invokeFunctionName");

                GetArgumentByComponentEvent(bindingInfo.component.GetType(), out Type argType);
                lstTemp.Clear();
                ReflectionTool.GetVmMethodByParameter1Type(vmType, argType, lstTemp);
                ReflectionTool.GetVmPropertyByType(vmType, argType, lstTemp);

                if (lstTemp.Count > 0)
                {
                    int index = lstTemp.IndexOf(propertyProperty.stringValue);
                    index = Mathf.Max(0, index);
                    index = EditorGUI.Popup(unitRect, index, lstTemp.ToArray());
                    propertyProperty.stringValue = lstTemp[index];
                }
                else
                {
                    propertyProperty.stringValue = "";
                }

                o.ApplyModifiedProperties();
            }
        }

        EditorGUI.EndProperty();
    }