Exemplo n.º 1
0
        static UnityEngine.Object[] bindableObjects; // = new List<Behaviour>();
        public override void OnInspectorGUI()
        {
            // base.OnInspectorGUI ();
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Drag(BindableObject) to add", GUILayout.Width(200));
            EditorGUILayout.Space();
            UnityEngine.Component addComponent = null;
            addComponent = (UnityEngine.Component)EditorGUILayout.ObjectField(addComponent, typeof(UnityEngine.Component), true, GUILayout.Height(40));

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Bindable List", GUILayout.Width(200));
            EditorGUILayout.Space();

            var temp = target as BindableContainer;

            Undo.RecordObject(target, "F");
            BindableObject objComponent;

            if (temp.children != null)
            {
                for (int i = 0; i < temp.children.Count; i++)
                {
                    // EditorGUILayout.BeginHorizontal ();
                    // GUILayout.Label ((i + 1).ToString (), GUILayout.Width (20));
                    objComponent = temp.children[i];
                    // EditorGUILayout.ObjectField (objComponent, typeof (UnityEngine.Object));
                    // objComponent = PopupGameObjectComponents (GetbindableObjects (temp, i).target, i); //选择绑定的component type类型
                    // if (objComponent != null) AddbindableObjects (temp, i, objComponent); //绑定选中的类型
                    // //显示选中的对象
                    // AddbindableObjects (temp, i, EditorGUILayout.ObjectField (GetbindableObjects (temp, i).target, typeof (UnityEngine.Object), true, GUILayout.MaxWidth (80)));
                    // //选择可绑定属性
                    // PopupComponentsProperty (temp, i);
                    BindalbeObjectUtilty.BindableObjectField(objComponent, i);
                    if (GUILayout.Button("Del", GUILayout.Width(30)))
                    {
                        RemoveAtbindableObjects(temp, i);
                    }

                    // EditorGUILayout.EndHorizontal ();
                    //设置binding属性
                    SetBindingProperties(temp, i);
                    EditorGUILayout.Space();
                }
            }
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();

            if (addComponent)
            {
                AddbindableObjects(temp, addComponent);  //allcomps[allcomps.Length - 1]);
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndHorizontal();

            //EditorUtility.SetDirty (target);
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.Separator();
            var temp = target as CustomBinder;

            // base.OnInspectorGUI();
            GUILayout.BeginHorizontal();

            temp.target = (Component)BindalbeEditorUtilty.DrawPopUpComponents("Binder Target", temp.target, GUILayout.MinWidth(150));
            GUILayout.EndHorizontal();
            BindalbeObjectUtilty.BindableObjectField(temp, 0);
        }
Exemplo n.º 3
0
        public void AddbindableObjects(BindableContainer refer, UnityEngine.Component obj)
        {
            if (refer.children == null) //需要新增加
            {
                List <Binding> bindings = new List <Binding>();
                refer.children = new List <BindableObject>(); // bindings.ToArray ();
            }

            var            children = refer.children;
            BindableObject bindable = null;

            if (obj is BindableObject)
            {
                bindable = obj as BindableObject;
            }
            else
            {
                if (bindable == null)
                {
                    Component[] allcomps = obj.GetComponents <Component>(); //默认绑定最后一个组件
                    Component   target   = null;
                    Type        addType  = typeof(Hugula.Databinding.BindableObject);
                    Type        findType;
                    foreach (var comp in allcomps)
                    {
                        if (comp is BindableObject)
                        {
                            bindable = (BindableObject)comp;
                            break;
                        }
                        else if ((findType = BindalbeObjectUtilty.FindBinderType(comp.GetType())) != null)
                        {
                            target  = comp;
                            addType = findType;
                        }
                    }

                    if (bindable == null)
                    {
                        bindable = (BindableObject)obj.gameObject.AddComponent(addType);
                    }
                }
            }

            if (bindable != null && children.IndexOf(bindable) < 0)
            {
                refer.AddChild(bindable);
            }
        }
Exemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            // base.OnInspectorGUI ();
            EditorGUILayout.Separator();
            var temp = target as CustomBinder;

            // base.OnInspectorGUI();
            GUILayout.BeginHorizontal();

            // GUILayout.Label(new GUIContent("Binder Target"), GUILayout.MinWidth(60));
            // content = GUILayout.TextField(content, options);
            // GUILayout.EndHorizontal();
            // if (!string.IsNullOrEmpty(content)) content = content.Replace(",", "").Replace("=", "");
            // temp.binderTarget = (Component)EditorGUILayout.ObjectField(temp.binderTarget, typeof(Component), false, GUILayout.MaxWidth(150)); //显示绑定对象
            temp.target = (Component)BindalbeEditorUtilty.DrawPopUpComponents("Binder Target", temp.target, GUILayout.MinWidth(150));
            GUILayout.EndHorizontal();
            BindalbeObjectUtilty.BindableObjectField(temp, 0);
        }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.Separator();
            var temp = target as BindableObject;
            var tp   = temp.GetType();
            var prop = tp.GetProperty("target", BindingFlags.Public | BindingFlags.Instance);

            if (prop != null)
            {
                if (prop.GetValue(target) == null)
                {
                    prop.SetValue(target, temp.GetComponent(prop.PropertyType));
                }
            }
            // else
            base.OnInspectorGUI();
            BindalbeObjectUtilty.BindableObjectField(temp, 0);
        }
Exemplo n.º 6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // var serializedObject = property.serializedObject;

            var temp = (BindableObject)property.objectReferenceValue;

            if (temp == null)
            {
                return;
            }

            var tp   = temp.GetType();
            var prop = tp.GetProperty("target", BindingFlags.Public | BindingFlags.Instance);

            if (prop != null)
            {
                if (prop.GetValue(temp) == null)
                {
                    prop.SetValue(temp, temp.GetComponent(prop.PropertyType));
                }
            }

            var rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(34));
            //selected
            bool isExpanded = property.isExpanded;

            var   rect1 = rect;
            float w     = rect.width;

            EditorGUI.HelpBox(rect, "", MessageType.None);
            rect1.height -= BindableObjectStyle.kExtraSpacing * 2;
            rect1.y      += BindableObjectStyle.kExtraSpacing;

            rect1.x            += BindableObjectStyle.kExtraSpacing;
            rect1.width         = 26f;
            isExpanded          = EditorGUI.Toggle(rect1, isExpanded);
            property.isExpanded = isExpanded;
            rect1.x             = rect1.xMax + BindableObjectStyle.kExtraSpacing;
            rect1.width         = w * .35f;


            CustomBinder customer = null;

            if (temp is CustomBinder)
            {
                customer = (CustomBinder)temp;
                EditorGUI.ObjectField(rect1, customer.target, typeof(Component), false); //显示绑定对象
            }
            else
            {
                EditorGUI.ObjectField(rect1, temp, typeof(BindableObject), false); //显示绑定对象
            }
            rect1.x     = rect1.xMax + BindableObjectStyle.kExtraSpacing;
            rect1.width = w * .35f;


            if (customer != null)
            {
                propertyName = BindalbeObjectUtilty.PopupComponentsProperty(rect1, customer.target, propertyName); //绑定属性
            }
            else
            {
                propertyName = BindalbeObjectUtilty.PopupComponentsProperty(rect1, temp, propertyName); //绑定属性
            }
            rect1.x     = rect1.xMax + BindableObjectStyle.kExtraSpacing;
            rect1.width = w * .2f - BindableObjectStyle.kExtraSpacing * 4;
            if (GUI.Button(rect1, "add"))
            {
                if (string.Equals(propertyName, BindableObjectStyle.FIRST_PROPERTY_NAME))
                {
                    Debug.LogWarningFormat("please choose a property to binding");
                    return;
                }
                Binding expression = new Binding();
                expression.propertyName = propertyName;
                temp.AddBinding(expression);
                property.isExpanded = true;
            }
            EditorGUILayout.Separator();
            EditorGUILayout.EndHorizontal();

            if (isExpanded)
            {
                //显示列表
                if (temSerialziedObject == null || temSerialziedObject.targetObject != temp)
                {
                    temSerialziedObject = new SerializedObject(temp);
                }
                {
                    var bindings = temSerialziedObject.FindProperty("bindings");
                    // serializedObject.targetObject
                    if (bindings != null && bindings.isArray)
                    {
                        selectedList.Clear();
                        temSerialziedObject.Update();

                        var len = bindings.arraySize;
                        SerializedProperty bindingProperty;
                        for (int i = 0; i < len; i++)
                        {
                            bindingProperty = bindings.GetArrayElementAtIndex(i);
                            EditorGUILayout.PropertyField(bindingProperty, true);
                            if (bindingProperty.isExpanded)
                            {
                                selectedList.Add(i);
                            }
                        }


                        rect    = EditorGUILayout.BeginHorizontal(GUILayout.Height(20));
                        rect.y += BindableObjectStyle.kExtraSpacing;

                        float width;
                        //删除数据
                        if (selectedList.Count > 0)
                        {
                            width      = 102;
                            rect.x     = rect.xMax - width;
                            rect.width = width;
                            if (GUI.Button(rect, "del property " + selectedList.Count))
                            {
                                selectedList.Sort((int a, int b) =>
                                {
                                    if (a < b)
                                    {
                                        return(1);
                                    }
                                    else if (a == b)
                                    {
                                        return(0);
                                    }
                                    else
                                    {
                                        return(-1);
                                    }
                                });

                                foreach (var i in selectedList)
                                {
                                    bindings.DeleteArrayElementAtIndex(i);
                                }
                            }
                            EditorGUILayout.Separator();
                        }
                        else
                        {
                            string DELETE_TIPS = BindableObjectStyle.PROPPERTY_CHOOSE_TIPS;
                            width      = DELETE_TIPS.Length * BindableObjectStyle.kExtraSpacing;
                            rect.x     = rect.xMax - width;
                            rect.width = width;
                            GUI.Box(rect, DELETE_TIPS);
                        }

                        temSerialziedObject.ApplyModifiedProperties();

                        EditorGUILayout.Separator();
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
            else
            {
                // GUILayout.Box("click checkbox  to see detail or delete!");
            }
        }
Exemplo n.º 7
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.Separator();
            var temp = target as BindableObject;
            var tp   = temp.GetType();
            var prop = tp.GetProperty("target", BindingFlags.Public | BindingFlags.Instance);

            if (prop != null)
            {
                if (prop.GetValue(target) == null)
                {
                    prop.SetValue(target, temp.GetComponent(prop.PropertyType));
                }
            }

            base.OnInspectorGUI();

            var   rect  = EditorGUILayout.BeginHorizontal(GUILayout.Height(34));
            var   rect1 = rect;
            float w     = rect.width;

            EditorGUI.HelpBox(rect, "", MessageType.None);

            rect1.height -= BindableObjectStyle.kExtraSpacing * 2;
            rect1.x      += BindableObjectStyle.kExtraSpacing;
            rect1.y      += BindableObjectStyle.kExtraSpacing;
            rect1.width   = w * .4f;

            //
            CustomBinder customer = null;

            if (temp is CustomBinder)
            {
                customer = (CustomBinder)temp;
                EditorGUI.ObjectField(rect1, customer.target, typeof(Component), false); //显示绑定对象
            }
            else
            {
                EditorGUI.ObjectField(rect1, temp, typeof(BindableObject), false); //显示绑定对象
            }
            rect1.x     = rect1.xMax + BindableObjectStyle.kExtraSpacing;
            rect1.width = w * .4f;

            if (customer != null)
            {
                propertyName = BindalbeObjectUtilty.PopupComponentsProperty(rect1, customer.target, propertyName); //绑定属性
            }
            else
            {
                propertyName = BindalbeObjectUtilty.PopupComponentsProperty(rect1, temp, propertyName); //绑定属性
            }
            rect1.x     = rect1.xMax + BindableObjectStyle.kExtraSpacing;
            rect1.width = w * .2f - BindableObjectStyle.kExtraSpacing * 4;
            if (GUI.Button(rect1, "add"))
            {
                if (string.Equals(propertyName, BindableObjectStyle.FIRST_PROPERTY_NAME))
                {
                    Debug.LogWarningFormat("please choose a property to binding");
                    return;
                }
                Binding expression = new Binding();
                expression.propertyName = propertyName;
                temp.AddBinding(expression);
            }
            EditorGUILayout.Separator();
            EditorGUILayout.EndHorizontal();

            //显示列表
            if (bindings.isArray)
            {
                selectedList.Clear();
                serializedObject.Update();

                var len = temp.GetBindings().Count;
                SerializedProperty bindingProperty;
                for (int i = 0; i < len; i++)
                {
                    bindingProperty = bindings.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(bindingProperty, true);
                    if (bindingProperty.isExpanded)
                    {
                        selectedList.Add(i);
                    }
                }

                //删除数据
                if (selectedList.Count > 0)
                {
                    rect       = EditorGUILayout.BeginHorizontal(GUILayout.Height(20));
                    rect.x     = rect.xMax - 100;
                    rect.width = 100;
                    if (GUI.Button(rect, "del property " + selectedList.Count))
                    {
                        selectedList.Sort((int a, int b) =>
                        {
                            if (a < b)
                            {
                                return(1);
                            }
                            else if (a == b)
                            {
                                return(0);
                            }
                            else
                            {
                                return(-1);
                            }
                        });

                        foreach (var i in selectedList)
                        {
                            bindings.DeleteArrayElementAtIndex(i);
                        }
                    }
                    EditorGUILayout.Separator();
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    GUILayout.Box(BindableObjectStyle.PROPPERTY_CHOOSE_TIPS);
                }
                serializedObject.ApplyModifiedProperties();
            }
        }
Exemplo n.º 8
0
        static UnityEngine.Object[] bindableObjects; // = new List<Behaviour>();
        public override void OnInspectorGUI()
        {
            // base.OnInspectorGUI ();
            EditorGUILayout.Separator();
            var temp = target as BindableContainer;

            EditorGUILayout.LabelField("Drag(BindableObject) to add", GUILayout.Width(200));
            EditorGUILayout.Space();
            UnityEngine.Component addComponent = null;
            addComponent = (UnityEngine.Component)EditorGUILayout.ObjectField(addComponent, typeof(UnityEngine.Component), true, GUILayout.Height(40));

            EditorGUILayout.Separator();
            EditorGUILayout.Space();
            if (GUILayout.Button("auto add hierarchy  children", GUILayout.MaxWidth(300)))
            {
                //清理
                var children = temp.children;
                for (int i = 0; i < children.Count;)
                {
                    if (children[i] != null)
                    {
                        i++;
                    }
                    else
                    {
                        children.RemoveAt(i);
                    }
                }
                AddHierarchyChildren(temp.transform, temp, true);
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Bindable List", GUILayout.Width(200));
            EditorGUILayout.Space();

            Undo.RecordObject(target, "F");
            BindableObject objComponent;

            if (temp.children != null)
            {
                for (int i = 0; i < temp.children.Count; i++)
                {
                    objComponent = temp.children[i];
                    BindalbeObjectUtilty.BindableObjectField(objComponent, i);
                    if (GUILayout.Button("Del", GUILayout.Width(30)))
                    {
                        RemoveAtbindableObjects(temp, i);
                    }

                    //设置binding属性
                    SetBindingProperties(temp, i);
                    EditorGUILayout.Space();
                }
            }
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();

            if (addComponent)
            {
                AddbindableObjects(temp, addComponent); //allcomps[allcomps.Length - 1]);
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndHorizontal();

            //EditorUtility.SetDirty (target);
        }