예제 #1
0
        private void DrawPanelComponent()
        {
            if (!panelCompnent)
            {
                return;
            }

            using (var hor = new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button(new GUIContent("→", "快速绑定"), EditorStyles.toolbarButton, GUILayout.Width(20)))
                {
                    GenCodeUtil.BindingUI(panelCompnent, components);
                }
            }

            GUILayout.Space(5);

            if (panelDrawer == null && panelCompnent != null)
            {
                panelDrawer = UnityEditor.Editor.CreateEditor(panelCompnent);
            }

            if (panelDrawer != null)
            {
                panelDrawer.OnInspectorGUI();
            }
        }
        private void DrawTarget(Rect targetRect, ComponentItem item)
        {
            EditorGUI.BeginChangeCheck();
            var newTarget = EditorGUI.ObjectField(targetRect, item.target, item.componentType, true);

            if (newTarget != item.target)
            {
                var prefabTarget = PrefabUtility.GetPrefabParent(newTarget);
                if (prefabTarget != null)
                {
                    newTarget = prefabTarget;
                }
                item.target = newTarget.GetType().GetProperty("gameObject").GetValue(newTarget, null) as GameObject;
            }

            if (EditorGUI.EndChangeCheck() && item.target)
            {
                var parent = PrefabUtility.GetPrefabParent(item.target);
                if (parent)
                {
                    item.target = parent as GameObject;
                }
                if (string.IsNullOrEmpty(item.name))
                {
                    item.name = item.target.name;
                }
                item.components = GenCodeUtil.SortComponent(item.target as GameObject);
            }
        }
예제 #3
0
 private void SwitchComponent(MonoBehaviour v)
 {
     panelCompnent = v;
     if (panelCompnent != null)
     {
         panelDrawer = UnityEditor.Editor.CreateEditor(panelCompnent);
     }
     GenCodeUtil.AnalysisComponent(panelCompnent, components, rule);
 }
        public static bool OnOpenAsset(int instanceID, int line)
        {
            var prefab = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

            if (prefab != null && prefab.GetComponent <RectTransform>())
            {
                GenCodeUtil.ChoiseAnUserMonobehiver(prefab, v => {
                    if (v)
                    {
                        var window = GetWindow <BindingWindow>();
                        window.OpenWith(v);
                    }
                });
                return(true);
            }
            return(false);
        }
 private void DrawObjectField()
 {
     using (var hor = new EditorGUILayout.HorizontalScope())
     {
         if (GUILayout.Button("预制体:", EditorStyles.toolbarButton, GUILayout.Width(lableWidth)))
         {
             ToggleOpen();
         }
         EditorGUI.BeginChangeCheck();
         prefab = EditorGUILayout.ObjectField(prefab, typeof(GameObject), false) as GameObject;
         if (EditorGUI.EndChangeCheck())
         {
             GenCodeUtil.ChoiseAnUserMonobehiver(prefab, v => {
                 OpenWith(v);
             });
         }
     }
 }
예제 #6
0
        protected virtual void InitPanelNode()
        {
            if (preComponentList == null)
            {
                preComponentList = new ReorderableList(components, typeof(ComponentItem));
                preComponentList.drawHeaderCallback = DrawComponetHeader;
                //preComponentList.elementHeight = itemDrawer.singleLineHeight;
                preComponentList.showDefaultBackground  = true;
                preComponentList.elementHeightCallback += (index) =>
                {
                    var prop = components[index];
                    return(itemDrawer.GetItemHeight(prop, BindingAble));
                };
                preComponentList.drawElementCallback += (rect, index, isFocused, isActive) =>
                {
                    itemDrawer.DrawItemOnRect(rect, index, components[index], BindingAble);
                };
                preComponentList.drawElementBackgroundCallback += (rect, index, isFocused, isActive) =>
                {
                    if (components.Count > index && index >= 0)
                    {
                        itemDrawer.DrawBackground(rect, isFocused, components[index], BindingAble);
                    }
                };
            }

            if (components != null)
            {
                components.ForEach((x) =>
                {
                    if (x.target != null)
                    {
                        x.components = GenCodeUtil.SortComponent(x.target);
                    }
                });
            }

            if (panelCompnent)
            {
                GenCodeUtil.AnalysisComponent(panelCompnent, components);
            }
        }
        private void DrawPreComponents()
        {
            using (var hor = new EditorGUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(new GUIContent("←", "快速解析"), EditorStyles.toolbarButton, GUILayout.Width(20)))
                {
                    var component = prefab.GetComponent <MonoBehaviour>();
                    if (component == null)
                    {
                        EditorApplication.Beep();
                    }
                    else
                    {
                        //从旧的脚本解析出
                        GenCodeUtil.AnalysisComponent(component, components);
                    }
                }
            }

            using (var hor = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("BaseType:", GUILayout.Width(lableWidth));
                rule.baseTypeIndex = EditorGUILayout.Popup(rule.baseTypeIndex, GenCodeUtil.supportBaseTypes);
                if (GUILayout.Button(new GUIContent("update", "更新脚本控件信息"), EditorStyles.miniButton, GUILayout.Width(60)))
                {
                    var go = prefab;
                    rule.bindingAble = BindingAble;
                    GenCodeUtil.UpdateScripts(go, components, rule);
                }
            }


            preComponentList.DoLayoutList();

            var addRect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);

            if (addRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.DragUpdated)
                {
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        foreach (var item in DragAndDrop.objectReferences)
                        {
                            if (item is GameObject || item is ScriptableObject)
                            {
                                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                            }
                        }
                    }
                }
                else if (Event.current.type == EventType.DragPerform)
                {
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        foreach (var item in DragAndDrop.objectReferences)
                        {
                            if (item is GameObject)
                            {
                                var obj    = item as GameObject;
                                var parent = PrefabUtility.GetPrefabParent(obj);
                                if (parent)
                                {
                                    obj = parent as GameObject;
                                }
                                var c_item = new ComponentItem(obj);
                                c_item.components = GenCodeUtil.SortComponent(obj);
                                components.Add(c_item);
                            }

                            else if (item is ScriptableObject)
                            {
                                var c_item = new ComponentItem(item as ScriptableObject);
                                components.Add(c_item);
                            }
                        }
                        DragAndDrop.AcceptDrag();
                    }
                }
            }
        }
예제 #8
0
        private void DrawPreComponents()
        {
            using (var hor = new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("命名空间", GUILayout.Width(60));
                rule.nameSpace = GUILayout.TextField(rule.nameSpace);
                if (GUILayout.Button(new GUIContent("←", "快速解析"), EditorStyles.toolbarButton, GUILayout.Width(20)))
                {
                    GenCodeUtil.ChoiseAnReferenceMonobehiver(prefab, component =>
                    {
                        if (component == null)
                        {
                            EditorApplication.Beep();
                        }
                        else
                        {
                            //从旧的脚本解析出
                            GenCodeUtil.AnalysisComponent(component, components, rule);
                        }
                    });
                }
            }

            using (var hor = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("BaseType:", GUILayout.Width(lableWidth));
                EditorGUI.BeginChangeCheck();
                rule.baseTypeIndex = EditorGUILayout.Popup(rule.baseTypeIndex, GenCodeUtil.supportBaseTypes);
                if (EditorGUI.EndChangeCheck())
                {
                    UpdateBindingAble();
                }
                if (GUILayout.Button("update", EditorStyles.miniButton, GUILayout.Width(60)))
                {
                    var go = prefab;
                    rule.bindingAble = bindingAble;
                    GenCodeUtil.UpdateBindingScripts(go, components, rule);
                }
            }


            preComponentList.DoLayoutList();

            var addRect = GUILayoutUtility.GetRect(BridgeUI.Drawer.BridgeEditorUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);

            if (addRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.DragUpdated)
                {
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        foreach (var item in DragAndDrop.objectReferences)
                        {
                            if (item is GameObject || item is ScriptableObject)
                            {
                                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                            }
                        }
                    }
                }
                else if (Event.current.type == EventType.DragPerform)
                {
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        foreach (var item in DragAndDrop.objectReferences)
                        {
                            if (item is GameObject)
                            {
                                var obj    = item as GameObject;
                                var parent = PrefabUtility.GetCorrespondingObjectFromSource(obj);
                                if (parent)
                                {
                                    obj = parent as GameObject;
                                }
                                var c_item = new ComponentItem(obj);
                                c_item.components = GenCodeUtil.SortComponent(obj);
                                components.Add(c_item);
                            }

                            else if (item is ScriptableObject)
                            {
                                var c_item = new ComponentItem(item as ScriptableObject);
                                components.Add(c_item);
                            }
                        }
                        DragAndDrop.AcceptDrag();
                    }
                }
            }
        }