예제 #1
0
        public static void WriteClass(TextWriter writer, string nameSpace)
        {
            var assetBundleInfos = BuildAssetBundleTools.FileInfo2AssetConst(); // AddABInfo2ResDatas();//new List<AssetBundleInfo>();
            var compileUnit      = new CodeCompileUnit();
            var codeNamespace    = new CodeNamespace(nameSpace);

            compileUnit.Namespaces.Add(codeNamespace);

            foreach (var assetBundleInfo in assetBundleInfos)
            {
                var className = assetBundleInfo.assetBundleName;
//                className = DesignerTools.SimplifyName(Path2CamelName(className));
                var codeType = new CodeTypeDeclaration(DesignerTools.SimplifyName(Path2CamelName(className)));
                codeNamespace.Types.Add(codeType);
                var assetsRoot      = "Assets/";
                var bundleNameField = new CodeMemberField
                {
                    Attributes     = MemberAttributes.Public | MemberAttributes.Const,
                    Name           = "BundleName",
                    Type           = new CodeTypeReference(typeof(System.String)),
                    InitExpression = new CodePrimitiveExpression(className)
                };
                codeType.Members.Add(bundleNameField);

                var prefix = "_";
                //TODO 不去重处理,理论上不应该有重复名字的资源在同一个ab包中
                //				var checkRepeatDict = new Dictionary<string, string>();
                foreach (var asset in assetBundleInfo.assetNames)
                {
                    var content    = Path.GetFileNameWithoutExtension(asset);
                    var ext        = Path.GetExtension(asset)?.Substring(1).ToUpper() + prefix;
                    var assetField = new CodeMemberField
                    {
                        Attributes     = MemberAttributes.Public | MemberAttributes.Const,
                        Name           = ext + DesignerTools.SimplifyName(content?.ToUpperInvariant()),
                        Type           = new CodeTypeReference(typeof(System.String)),
                        InitExpression = new CodePrimitiveExpression(content)
                    };
                    //					if (!assetField.Name.StartsWith("[") && !assetField.Name.StartsWith(" [") &&
                    //					    !checkRepeatDict.ContainsKey(assetField.Name))
                    //					{
                    //						checkRepeatDict.Add(assetField.Name, asset);
                    codeType.Members.Add(assetField);
                    //					}
                }

                //				checkRepeatDict.Clear();
            }

            //TODO using Microsoft.CSharp;
            var provider = new Microsoft.CSharp.CSharpCodeProvider();
            var options  = new CodeGeneratorOptions
            {
                BlankLinesBetweenMembers = false,
                BracingStyle             = "C"
            };

            provider.GenerateCodeFromCompileUnit(compileUnit, writer, options);
        }
예제 #2
0
        void OnGUI()
        {
            GUIStyle text_style = new GUIStyle();

            text_style.fontSize  = 15;
            text_style.alignment = TextAnchor.MiddleCenter;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("默认使用源文件名", GUILayout.MinWidth(0));
            IsThisName = EditorGUILayout.Toggle(IsThisName);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("AssetBundleName:", GUILayout.MinWidth(0));
            if (IsThisName)
            {
                GUILayout.Label("文件相对Assets/Export的路径", GUILayout.MinWidth(0));
            }
            else
            {
                AssetBundleName = EditorGUILayout.TextField(AssetBundleName.ToLower());
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Variant:", GUILayout.MinWidth(0));
            Variant = EditorGUILayout.TextField(Variant.ToLower());
            EditorGUILayout.EndHorizontal();

            GUILayout.Label("\n");

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("文件夹路径", GUILayout.MinWidth(60));
            if (GUILayout.Button("浏览", GUILayout.MinWidth(60)))
            {
                OpenFolder();
            }

            PathRoot = EditorGUILayout.TextField(PathRoot);
            EditorGUILayout.EndHorizontal();
            if (GUILayout.Button("修改该文件夹下的AssetName及Variant"))
            {
                BuildAssetBundleTools.SetSettings();
            }

            if (GUILayout.Button("清除所有未被引用的AssetName及Variant"))
            {
                AssetDatabase.RemoveUnusedAssetBundleNames();
            }

            if (GUILayout.Button("清空所有AssetName及Variant"))
            {
                ClearAssetBundlesName();
            }
        }