예제 #1
0
        void OnGUIRule(ABPackRuleConfig.Rule rule, bool selected)
        {
            ABPackRuleConfig config = AutoABNamePostprocessor.config;

            EditorGUILayout.BeginVertical(selected ? GUI.skin.button : GUI.skin.box);
            EditorGUILayout.BeginHorizontal();
            rule.path = EditorGUILayout.TextField("Path: ", rule.path);
            if (Event.current.type == EventType.DragUpdated && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
            {
                if (DragAndDrop.objectReferences[0] is DefaultAsset)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                    DragAndDrop.AcceptDrag();
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.DragPerform && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
            {
                rule.path = GetAssetPath(DragAndDrop.paths[0]);
                Event.current.Use();
                EditorUtility.SetDirty(config);
            }
            if (GUILayout.Button("Select", GUILayout.Width(100)))
            {
                string result = EditorUtility.OpenFolderPanel("", "选择目录", "");
                if (result != null)
                {
                    rule.path = GetAssetPath(result);
                    GUI.FocusControl(null);
                    EditorUtility.SetDirty(config);
                }
            }
            EditorGUILayout.EndHorizontal();
            if (!string.IsNullOrEmpty(rule.path))
            {
                rule.typeFilter = EditorGUILayout.TextField("TypeFilter: ", rule.typeFilter);
                if (Event.current.type == EventType.DragUpdated && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                    DragAndDrop.AcceptDrag();
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.DragPerform && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                {
                    rule.typeFilter = string.Join(",", DragAndDrop.objectReferences.Select(x => x.GetType().Name).Distinct().ToArray());
                    Event.current.Use();
                    EditorUtility.SetDirty(config);
                }
                rule.ruleType = EditorGUILayout.Popup("Rule: ", rule.ruleType, AutoABNamePostprocessor.packRuleNames.ToArray());
            }
            EditorGUILayout.EndVertical();
        }
예제 #2
0
        private void OnGUI()
        {
            ABPackRuleConfig config = AutoABNamePostprocessor.config;

            EditorGUILayout.BeginHorizontal(GUI.skin.box);
            AutoABNamePostprocessor.autoPack = EditorGUILayout.ToggleLeft("autoPack", AutoABNamePostprocessor.autoPack);
            if (GUILayout.Button("Apply"))
            {
                AutoABNamePostprocessor.PackAll();
            }
            EditorGUILayout.EndHorizontal();
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            int count = config.rules.Count;

            EditorGUI.BeginChangeCheck();
            for (int i = 0; i < count; i++)
            {
                OnGUIRule(config.rules[i], selectIndex == i);
                if (Event.current.type == EventType.MouseUp && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                {
                    selectIndex = i;
                    Event.current.Use();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(config);
            }
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add Rule"))
            {
                config.rules.Add(new ABPackRuleConfig.Rule());
                EditorUtility.SetDirty(config);
            }
            if (count > 0 && selectIndex >= 0 && GUILayout.Button("Remove Rule"))
            {
                config.rules.RemoveAt(selectIndex);
                selectIndex = -1;
                EditorUtility.SetDirty(config);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();
        }