Exemplo n.º 1
0
        public static void BindableObjectField(CustomBinder target, int index)
        {
            if (target == null)
            {
                return;
            }
            int    key = target.GetHashCode();
            string propertyName;

            dicPropertyName.TryGetValue(key, out propertyName);
            EditorGUILayout.Separator();
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            var temp = target as CustomBinder;

            GUILayout.Label(target.name, GUILayout.Width(100));
            GUILayout.Label("property:", GUILayout.MinWidth(60));
            // EditorGUILayout.ObjectField(temp.binderTarget, typeof(CustomBinder), false, GUILayout.MaxWidth(150)); //显示绑定对象
            int selectedIndex = PopupComponentsProperty(temp.target, propertyName, GUILayout.MaxWidth(150)); //绑定属性

            propertyName         = GetSelectedPropertyByIndex(selectedIndex);
            dicPropertyName[key] = propertyName;
            if (GUILayout.Button("+", GUILayout.MaxWidth(50)))
            {
                if (selectedIndex == 0)
                {
                    Debug.LogWarningFormat("please choose a property to binding");
                    return;
                }
                if (temp.bindings == null)
                {
                    temp.bindings = new List <Binding>();
                }

                Binding expression = new Binding();
                expression.propertyName = propertyName;
                temp.bindings.Add(expression);
            }
            Undo.RecordObject(target, "F");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            if (temp.bindings != null)
            {
                for (int i = 0; i < temp.bindings.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    var binding = temp.bindings[i];
                    BindableExpressionEditor.Expression(binding, i);

                    if (GUILayout.Button("-", GUILayout.Width(30)))
                    {
                        RemoveAtbindableObjects(temp, i);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
        }