コード例 #1
0
        public AssetBundleConfigNode InsertNode(int idx, int level)
        {
            int newID = allDependNodes.Count > 0 ? allDependNodes[allDependNodes.Count - 1].ID + 1 : 1;
            AssetBundleConfigNode newNode = new AssetBundleConfigNode(newID, level);

            allDependNodes.Insert(idx, newNode);
            return(newNode);
        }
コード例 #2
0
        public AssetBundleConfigNode AddNode(int level)
        {
            int newID = allDependNodes.Count > 0 ? allDependNodes[allDependNodes.Count - 1].ID + 1 : 1;
            AssetBundleConfigNode newNode = new AssetBundleConfigNode(newID, level);

            allDependNodes.Add(newNode);
            return(newNode);
        }
コード例 #3
0
        public void RemoveNode(AssetBundleConfigNode node)
        {
            int idx = allDependNodes.IndexOf(node);

            for (int ii = idx + 1; ii < allDependNodes.Count; ++ii)
            {
                if (allDependNodes[ii].level <= node.level)
                {
                    break;
                }
                --allDependNodes[ii].level;
            }
            allDependNodes.RemoveAt(idx);
        }
コード例 #4
0
        private void Update()
        {
            if (_hasPendingSelection)
            {
                _selectedNode        = _pendingSelection;
                _pendingSelection    = null;
                _hasPendingSelection = false;
            }

            if (_beginBuild)
            {
                Build();
                _beginBuild = false;
            }
        }
コード例 #5
0
        public void PopNode(AssetBundleConfigNode node, bool bPop)
        {
            int idx     = allDependNodes.IndexOf(node);
            int swapIdx = idx + (bPop ? -1 : 1);

            if (swapIdx < 0 || swapIdx >= allDependNodes.Count)
            {
                return;
            }

            AssetBundleConfigNode swapNode = allDependNodes[swapIdx];

            allDependNodes[swapIdx] = node;
            allDependNodes[idx]     = swapNode;
        }
コード例 #6
0
        private void Draw()
        {
            InitStyles();

            // 工具栏
            EditorGUILayout.BeginHorizontal(Styles.toolbar);
            {
                if (GUILayout.Button("Add", EditorStyles.toolbarButton))
                {
                    if (_selectedNode == null)
                    {
                        SetSelected(_config.AddNode(_config.allDependNodes.Count > 0 ? _config.allDependNodes[_config.allDependNodes.Count - 1].level : 0));
                    }
                    else
                    {
                        SetSelected(_pendingSelection = _config.InsertNode(_config.allDependNodes.IndexOf(_selectedNode) + 1, _selectedNode.level));
                    }
                }

                if (GUILayout.Button("Delete", EditorStyles.toolbarButton))
                {
                    if (_selectedNode != null)
                    {
                        _config.RemoveNode(_selectedNode);
                        _selectedNode = null;
                    }
                }

                if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                {
                    Save();
                }

                // 配置文件格式
                GUILayout.Label("Format:");
                _config.bundleInfoFileFormt = (AssetBundleBuildConfig.Format)EditorGUILayout.EnumPopup(_config.bundleInfoFileFormt, EditorStyles.toolbarPopup, GUILayout.Width(50));

                // 配置文件路径
                GUILayout.Label("Path:");
                GUI.enabled        = false;
                _config.bundlePath = GUILayout.TextField(_config.bundlePath, GUILayout.MinWidth(120f), GUILayout.ExpandWidth(true));
                GUI.enabled        = true;
                if (GUILayout.Button("...", EditorStyles.toolbarButton))
                {
                    string selectedPath = EditorUtility.OpenFolderPanel("Path", Application.dataPath, "");
                    if (!string.IsNullOrEmpty(selectedPath))
                    {
                        _config.bundlePath = selectedPath.Replace("\\", "/");
                    }
                }

                // 节点层级控制
                GUILayout.Space(20f);
                if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(20f), GUILayout.Height(16f)))
                {
                    if (_selectedNode != null)
                    {
                        int idx = _config.allDependNodes.IndexOf(_selectedNode);
                        if (idx > 0 && _config.allDependNodes[idx - 1].level >= _selectedNode.level)
                        {
                            ++_selectedNode.level;
                        }
                    }
                }
                if (GUILayout.Button("-", EditorStyles.miniButtonMid, GUILayout.Width(20f), GUILayout.Height(16f)))
                {
                    if (_selectedNode != null && _selectedNode.level > 0)
                    {
                        --_selectedNode.level;
                    }
                }
                if (GUILayout.Button("x", EditorStyles.miniButtonRight, GUILayout.Width(20f), GUILayout.Height(16f)))
                {
                    if (_selectedNode != null)
                    {
                        _selectedNode.needDelete = true;
                        _selectedNode            = null;
                    }
                }
                if (GUILayout.Button("U", EditorStyles.miniButtonLeft, GUILayout.Width(20f), GUILayout.Height(16f)))
                {
                    if (_selectedNode != null)
                    {
                        _config.PopNode(_selectedNode, true);
                    }
                }
                if (GUILayout.Button("D", EditorStyles.miniButtonRight, GUILayout.Width(20f), GUILayout.Height(16f)))
                {
                    if (_selectedNode != null)
                    {
                        _config.PopNode(_selectedNode, false);
                    }
                }

                GUILayout.FlexibleSpace();

                // 目标平台
                GUILayout.Label("Target:");
                _buildTarget = (BuildTarget)EditorGUILayout.EnumPopup(_buildTarget, EditorStyles.toolbarPopup, GUILayout.Width(150));

                // 编版本
                if (GUILayout.Button("Build", EditorStyles.toolbarButton))
                {
                    _beginBuild = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                // 依赖层级结构
                DrawHierarchy();

                // 分割线
                DrawSplit();

                // 选中节点信息
                DrawInspector(_selectedNode);
            }
            EditorGUILayout.EndHorizontal();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_config);
            }
        }
コード例 #7
0
        private void DrawInspector(AssetBundleConfigNode node)
        {
            EditorGUILayout.BeginVertical();
            {
                string[] inspectorTypes = { "Properties", "PersistentAssets" };
                _inspectorType = GUILayout.Toolbar(_inspectorType, inspectorTypes, EditorStyles.toolbarButton);

                if (_inspectorType == 0)
                {
                    if (node != null)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            node.enabled = GUILayout.Toggle(node.enabled, "", GUILayout.ExpandWidth(false));

                            GUILayout.Label("Name:", GUILayout.ExpandWidth(false));
                            node.name = EditorGUILayout.TextField(node.name, GUILayout.ExpandWidth(false));

                            GUILayout.Label("Dir:", GUILayout.ExpandWidth(false));
                            GUI.enabled = false;
                            node.dir    = EditorGUILayout.TextField(node.dir, GUILayout.ExpandWidth(true));
                            GUI.enabled = true;

                            if (GUILayout.Button("...", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                            {
                                string selectedPath = EditorUtility.OpenFolderPanel("Path", Application.dataPath, "");
                                if (!string.IsNullOrEmpty(selectedPath))
                                {
                                    node.dir = AssetBundleUtils.ConvertToAssetPath(selectedPath);
                                }
                            }

                            GUILayout.Label("Independent:", GUILayout.ExpandWidth(false));
                            node.isIndependent = GUILayout.Toggle(node.isIndependent, "", GUILayout.ExpandWidth(false));

                            GUILayout.Label("Export:", GUILayout.ExpandWidth(false));
                            node.exportType = (ExportType)EditorGUILayout.EnumPopup(node.exportType, GUILayout.Width(80f));
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        {
                            if (GUILayout.Button("AddFilter", EditorStyles.miniButtonLeft))
                            {
                                node.filters.Add(new AssetBundleFilter(true));
                            }
                            if (GUILayout.Button("AddFile", EditorStyles.miniButtonRight))
                            {
                                node.filters.Add(new AssetBundleFilter(false));
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        _inspectorScrollPos = EditorGUILayout.BeginScrollView(_inspectorScrollPos);
                        {
                            for (int ii = 0; ii < node.filters.Count; ++ii)
                            {
                                AssetBundleFilter filter = node.filters[ii];
                                EditorGUILayout.BeginHorizontal();
                                {
                                    GUI.enabled  = true;
                                    filter.valid = GUILayout.Toggle(filter.valid, "", GUILayout.ExpandWidth(false));
                                    GUI.enabled  = filter.valid;

                                    GUI.enabled = false;
                                    filter.path = GUILayout.TextField(filter.path, GUILayout.ExpandWidth(true));
                                    GUI.enabled = true;

                                    GUI.enabled = filter.valid;

                                    if (GUILayout.Button("...", GUILayout.ExpandWidth(false)))
                                    {
                                        if (string.IsNullOrEmpty(node.dir))
                                        {
                                            ShowNotification(new GUIContent("需要先指定节点目录"));
                                        }
                                        else
                                        {
                                            string selectedPath = filter.isFolder ? EditorUtility.OpenFolderPanel("Path", node.dir, "") : EditorUtility.OpenFilePanel("Path", node.dir, "");
                                            if (!string.IsNullOrEmpty(selectedPath))
                                            {
                                                selectedPath = AssetBundleUtils.ConvertToAssetPath(selectedPath);
                                                if (selectedPath.StartsWith(node.dir))
                                                {
                                                    filter.path = selectedPath.Substring((node.dir + "/").Length).Replace("\\", "/");
                                                }
                                                else
                                                {
                                                    ShowNotification(new GUIContent("不能在" + node.dir + "目录之外!"));
                                                }
                                            }
                                        }
                                    }

                                    if (filter.isFolder)
                                    {
                                        filter.filter       = EditorGUILayout.TextField(filter.filter, GUILayout.Width(100));
                                        filter.searchOption = (System.IO.SearchOption)EditorGUILayout.EnumPopup(filter.searchOption, GUILayout.Width(80));
                                    }

                                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                                    {
                                        node.filters.RemoveAt(ii);
                                        --ii;
                                    }
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                }
                else if (_inspectorType == 1)
                {
                    if (GUILayout.Button("AddFile", EditorStyles.miniButton))
                    {
                        _config.persistentAssets.Add(string.Empty);
                    }

                    EditorGUILayout.BeginScrollView(Vector2.zero);
                    {
                        for (int ii = 0; ii < _config.persistentAssets.Count; ++ii)
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                GUI.enabled = false;
                                GUILayout.TextField(_config.persistentAssets[ii], GUILayout.ExpandWidth(true));
                                GUI.enabled = true;

                                if (GUILayout.Button("...", GUILayout.ExpandWidth(false)))
                                {
                                    string selectedPath = EditorUtility.OpenFilePanel("Path", _config.persistentAssets[ii], "");
                                    if (!string.IsNullOrEmpty(selectedPath))
                                    {
                                        if (selectedPath.StartsWith(Application.dataPath))
                                        {
                                            _config.persistentAssets[ii] = AssetBundleUtils.ConvertToAssetPath(selectedPath);
                                        }
                                        else
                                        {
                                            ShowNotification(new GUIContent("不能在Assets目录之外!"));
                                        }
                                    }
                                }

                                if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                                {
                                    _config.persistentAssets.RemoveAt(ii);
                                    --ii;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
            }
            EditorGUILayout.EndVertical();
        }
コード例 #8
0
        private void DrawNode(AssetBundleConfigNode node)
        {
            bool isSelected = (node == _selectedNode);

            //bool bFoldOut = _expandedCache.IsExpanded(id);
            //bool bExpanded = bFoldOut;
            _content.text = node.name;
            Vector2 vector = Styles.lineStyle.CalcSize(_content);

            vector.x += 13f * node.level;
            Rect  position = GUILayoutUtility.GetRect(vector.x, 18f, GUILayout.ExpandWidth(true));
            Event curEvent = Event.current;

            if (curEvent.type == EventType.Repaint && isSelected)
            {
                Styles.lineStyle.Draw(position, false, false, isSelected, true);
            }

            /*if (node.children.Count > 0)
             * {
             *  Rect foldRect = position;
             *  foldRect.x += indent;
             *  foldRect.width = 13f;
             *  bExpanded = EditorGUI.Foldout(foldRect, bFoldOut, GUIContent.none, Styles.foldoutStyle);
             *  if (bExpanded != bFoldOut)
             *  {
             *      _expandedCache.SetExpanded(id, bExpanded);
             *      _hasFocus = true;
             *  }
             * }*/
            if (Event.current.type == EventType.Repaint)
            {
                Rect nameRect = position;
                nameRect.x     += 13f * node.level + 13f;
                nameRect.width -= 20f;
                if (node.enabled)
                {
                    Styles.lineStyle.Draw(nameRect, _content, false, false, isSelected, true);
                }
                else
                {
                    Styles.lineDisabledStyle.Draw(nameRect, _content, false, false, isSelected, true);
                }
            }

            /*if (bExpanded)
             * {
             *  DrawNodes(node.children);
             * }*/

            switch (curEvent.type)
            {
            case EventType.MouseUp:
                if (curEvent.button == 0 && _mouseWasDown && position.Contains(curEvent.mousePosition) /*&& bExpanded == bFoldOut*/)
                {
                    SetSelected(node);
                }
                break;

            case EventType.Repaint:
                _maxWidth = Mathf.Max(_maxWidth, position.width);
                break;
            }
        }
コード例 #9
0
 private void SetSelected(AssetBundleConfigNode node)
 {
     _pendingSelection    = node;
     _hasPendingSelection = true;
 }
コード例 #10
0
        private void AddTargets(AssetBundleConfigNode configNode)
        {
            if (!configNode.enabled)
            {
                return;
            }

            int idx = _config.allDependNodes.IndexOf(configNode);
            AssetBundleConfigNode nextConfigNode = idx >= 0 && idx < _config.allDependNodes.Count - 1 ? _config.allDependNodes[idx + 1] : null;
            bool            hasChild             = nextConfigNode != null && nextConfigNode.level > configNode.level;
            AssetBundleNode node = new AssetBundleNode(configNode.ID, configNode.level, configNode.isIndependent, hasChild);

            List <string> assetPaths = new List <string>();

            foreach (AssetBundleFilter filter in configNode.filters)
            {
                if (!filter.valid)
                {
                    continue;
                }

                string filterPath = AssetBundleUtils.ConvertToAbsolutePath(configNode.dir) + "/" + filter.path;
                if (Directory.Exists(filterPath))
                {
                    string[] filterList = filter.filter.Split(';');
                    foreach (string fil in filterList)
                    {
                        string[] paths = Directory.GetFiles(filterPath, fil, filter.searchOption);
                        foreach (string path in paths)
                        {
                            if (path.Contains("\\Editor\\") || path.EndsWith(".meta"))
                            {
                                continue;
                            }

                            assetPaths.Add(AssetBundleUtils.ConvertToAssetPath(path));
                        }
                    }
                }
                else
                {
                    assetPaths.Add(configNode.dir + "/" + filter.path);
                }
            }

            if (configNode.exportType == ExportType.Whole)
            {
                AssetBundleTarget at = new AssetBundleTarget(configNode.name, configNode.dir, node, null, ref assetPaths);
                node.targets.Add(at);
            }
            else
            {
                foreach (var path in assetPaths)
                {
                    AssetBundleTarget at = new AssetBundleTarget(configNode.name, configNode.dir, node, path, ref assetPaths);
                    node.targets.Add(at);
                }
            }

            _dependNodes.Add(node);
        }