コード例 #1
0
        private void CellGUI(Rect cellRect, BundleBuilderTreeViewItem item, int column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);

            switch (column)
            {
            case 0:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    if (bundleInfo.type == Manifest.BundleType.AssetBundle)
                    {
                        GUI.DrawTexture(cellRect, kIconFavorite, ScaleMode.ScaleToFit);
                    }
                    else
                    {
                        GUI.DrawTexture(cellRect, kIconZipArchive, ScaleMode.ScaleToFit);
                    }
                }
                break;

            case 1:
                // Do toggle
                var toggleRect = cellRect;
                var indent     = GetContentIndent(item);
                toggleRect.x    += indent;
                toggleRect.width = kToggleWidth;
                if (toggleRect.xMax < cellRect.xMax)
                {
                    item.enabled = EditorGUI.Toggle(toggleRect, item.enabled);     // hide when outside cell rect
                }
                // Default icon and label
                args.rowRect   = cellRect;
                cellRect.xMin += indent + kToggleWidth + 2f;
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    if (string.IsNullOrEmpty(bundleInfo.note))
                    {
                        EditorGUI.LabelField(cellRect, bundleInfo.name);
                    }
                    else
                    {
                        EditorGUI.LabelField(cellRect, string.Format("{0} ({1})", bundleInfo.note, bundleInfo.name));
                    }
                }
                else if (item.depth == 1)
                {
                    var target = (item as BundleBuilderTreeViewTarget).assetTarget;
                    if (target.targetPath.StartsWith("Assets/"))
                    {
                        var assetObject    = AssetDatabase.LoadMainAssetAtPath(target.targetPath);
                        var newAssetObject = EditorGUI.ObjectField(cellRect, GUIContent.none, assetObject, typeof(Object), false);
                        if (newAssetObject != assetObject)
                        {
                            target.targetPath = newAssetObject != null?AssetDatabase.GetAssetPath(newAssetObject) : string.Empty;

                            _data.MarkAsDirty();
                        }
                    }
                    else
                    {
                        var oldColor   = GUI.color;
                        var bundleInfo = (item.parent as BundleBuilderTreeViewBundle).bundleInfo;
                        if (bundleInfo.type == Manifest.BundleType.ZipArchive)
                        {
                            if (Directory.Exists(target.targetPath) || File.Exists(target.targetPath))
                            {
                                GUI.color = Color.yellow;
                                GUI.Label(cellRect, "<External>");
                            }
                            else
                            {
                                GUI.color = Color.red;
                                GUI.Label(cellRect, "<Invalid>");
                            }
                        }
                        else
                        {
                            GUI.color = Color.red;
                            GUI.Label(cellRect, "<Not Supported>");
                        }
                        GUI.color = oldColor;
                    }
                }
                else
                {
                    base.RowGUI(args);
                }
                break;

            case 2:
                if (item.depth == 1)
                {
                    var target        = (item as BundleBuilderTreeViewTarget).assetTarget;
                    var newTargetPath = GUI.TextField(cellRect, target.targetPath);

                    if (newTargetPath != target.targetPath)
                    {
                        target.targetPath = newTargetPath;
                        _data.MarkAsDirty();
                    }
                }
                break;

            case 3:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    var popupWidth = (cellRect.width - 20f) * 0.5f;
                    cellRect.width = 20f;
                    var streamingAssets = EditorGUI.Toggle(cellRect, bundleInfo.streamingAssets);
                    if (streamingAssets != bundleInfo.streamingAssets)
                    {
                        bundleInfo.streamingAssets = streamingAssets;
                        _data.MarkAsDirty();
                    }
                    cellRect.x    += cellRect.width;
                    cellRect.width = popupWidth;
                    var load = (Manifest.BundleLoad)EditorGUI.EnumPopup(cellRect, bundleInfo.load);
                    if (load != bundleInfo.load)
                    {
                        bundleInfo.load = load;
                        _data.MarkAsDirty();
                    }
                    cellRect.x    += cellRect.width;
                    cellRect.width = popupWidth;
                    var type = (Manifest.BundleType)EditorGUI.EnumPopup(cellRect, bundleInfo.type);
                    if (type != bundleInfo.type)
                    {
                        bundleInfo.type = type;
                        _data.MarkAsDirty();
                        Reload();
                    }
                }
                else if (item.depth == 1)
                {
                }
                break;

            case 4:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    var priority   = EditorGUI.IntSlider(cellRect, bundleInfo.priority, 0, _data.priorityMax);
                    if (priority != bundleInfo.priority)
                    {
                        bundleInfo.priority = priority;
                        _data.MarkAsDirty();
                    }
                }
                else if (item.depth == 1)
                {
                }
                break;

            case 5:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    var buildOrder = EditorGUI.IntField(cellRect, bundleInfo.buildOrder);
                    if (buildOrder != bundleInfo.buildOrder)
                    {
                        bundleInfo.buildOrder = buildOrder;
                        _data.MarkAsDirty();
                    }
                }
                break;
            }
        }
コード例 #2
0
        private void CellGUI(Rect cellRect, BundleBuilderTreeViewItem item, int column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);

            switch (column)
            {
            case 0:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    if (bundleInfo.type == Manifest.BundleType.AssetBundle)
                    {
                        GUI.DrawTexture(cellRect, kIconFavorite, ScaleMode.ScaleToFit);
                    }
                    // else if (bundleInfo.type == BundleType.SceneBundle)
                    // {
                    //     GUI.DrawTexture(cellRect, kIconSceneAsset, ScaleMode.ScaleToFit);
                    // }
                    else
                    {
                        GUI.DrawTexture(cellRect, kIconZipArchive, ScaleMode.ScaleToFit);
                    }
                }
                break;

            case 1:
                if (item.depth == 1)
                {
                    var target = (item as BundleBuilderTreeViewTarget).assetTarget;
                    if (target.target != null)
                    {
                        if (target.target is GameObject)
                        {
                            GUI.DrawTexture(cellRect, kIconPrefab.image, ScaleMode.ScaleToFit);
                        }
                        else if (target.target is TextAsset)
                        {
                            GUI.DrawTexture(cellRect, kIconTextAsset.image, ScaleMode.ScaleToFit);
                        }
                        else if (target.target is Texture)
                        {
                            GUI.DrawTexture(cellRect, kIconTexture.image, ScaleMode.ScaleToFit);
                        }
                        else if (target.target is Material)
                        {
                            GUI.DrawTexture(cellRect, kIconMaterial.image, ScaleMode.ScaleToFit);
                        }
                        else if (target.target is SceneAsset)
                        {
                            GUI.DrawTexture(cellRect, kIconSceneAsset, ScaleMode.ScaleToFit);
                        }
                        else
                        {
                            var assetPath = AssetDatabase.GetAssetPath(target.target);
                            if (Directory.Exists(assetPath))
                            {
                                GUI.DrawTexture(cellRect, kIconFolder, ScaleMode.ScaleToFit);
                            }
                        }
                    }
                }
                break;

            case 2:
                // Do toggle
                var toggleRect = cellRect;
                var indent     = GetContentIndent(item);
                toggleRect.x    += indent;
                toggleRect.width = kToggleWidth;
                if (toggleRect.xMax < cellRect.xMax)
                {
                    item.enabled = EditorGUI.Toggle(toggleRect, item.enabled);     // hide when outside cell rect
                }
                // Default icon and label
                args.rowRect   = cellRect;
                cellRect.xMin += indent + kToggleWidth + 2f;
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    if (string.IsNullOrEmpty(bundleInfo.note))
                    {
                        EditorGUI.LabelField(cellRect, bundleInfo.name);
                    }
                    else
                    {
                        EditorGUI.LabelField(cellRect, bundleInfo.note);
                    }
                }
                else if (item.depth == 1)
                {
                    var assetTarget = (item as BundleBuilderTreeViewTarget).assetTarget;
                    var target      = EditorGUI.ObjectField(cellRect, GUIContent.none, assetTarget.target, typeof(Object), false);
                    if (target != assetTarget.target)
                    {
                        assetTarget.target = target;
                        _data.MarkAsDirty();
                    }
                }
                else
                {
                    base.RowGUI(args);
                }
                break;

            case 3:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    if (bundleInfo != null)
                    {
                        var platforms = (BundleAssetPlatforms)EditorGUI.EnumFlagsField(cellRect, bundleInfo.platforms);
                        if (platforms != bundleInfo.platforms)
                        {
                            bundleInfo.platforms = platforms;
                            _data.MarkAsDirty();
                        }
                    }
                }
                else if (item.depth == 1)
                {
                }
                break;

            case 4:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    cellRect.width *= 0.5f;
                    var load = (BundleLoad)EditorGUI.EnumPopup(cellRect, bundleInfo.load);
                    if (load != bundleInfo.load)
                    {
                        bundleInfo.load = load;
                        _data.MarkAsDirty();
                    }
                    cellRect.x += cellRect.width;
                    var type = (Manifest.BundleType)EditorGUI.EnumPopup(cellRect, bundleInfo.type);
                    if (type != bundleInfo.type)
                    {
                        bundleInfo.type = type;
                        _data.MarkAsDirty();
                        Reload();
                    }
                }
                else if (item.depth == 1)
                {
                    // var bundleInfo = (item.parent as BundleBuilderTreeViewBundle).bundleInfo;
                    var target = (item as BundleBuilderTreeViewTarget).assetTarget;
                    if (target.target != null)
                    {
                        var assetPath = AssetDatabase.GetAssetPath(target.target);
                        if (Directory.Exists(assetPath))
                        {
                            var types = (BundleAssetTypes)EditorGUI.EnumFlagsField(cellRect, target.types);
                            if (types != target.types)
                            {
                                target.types = types;
                                _data.MarkAsDirty();
                            }
                        }
                    }
                }
                break;

            case 5:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    var priority   = EditorGUI.IntSlider(cellRect, bundleInfo.priority, 0, 10000);
                    if (priority != bundleInfo.priority)
                    {
                        bundleInfo.priority = priority;
                        _data.MarkAsDirty();
                    }
                }
                else if (item.depth == 1)
                {
                    var target = (item as BundleBuilderTreeViewTarget).assetTarget;
                    if (target.target != null)
                    {
                        var assetPath = AssetDatabase.GetAssetPath(target.target);
                        if (Directory.Exists(assetPath))
                        {
                            var extensions = EditorGUI.TextField(cellRect, target.extensions);
                            if (extensions != target.extensions)
                            {
                                target.extensions = extensions;
                                _data.MarkAsDirty();
                            }
                        }
                    }
                }
                break;

            case 6:
                if (item.depth == 0)
                {
                    var bundleInfo = (item as BundleBuilderTreeViewBundle).bundleInfo;
                    if (bundleInfo.type == Manifest.BundleType.AssetBundle)
                    {
                        var splitObjects = EditorGUI.IntSlider(cellRect, bundleInfo.splitObjects, 0, 100);
                        if (splitObjects != bundleInfo.splitObjects)
                        {
                            bundleInfo.splitObjects = splitObjects;
                            _data.MarkAsDirty();
                        }
                    }
                    // else if (bundleInfo.type == BundleType.SceneBundle)
                    // {
                    // }
                }
                break;
            }
        }