/// <summary>
    /// 编译模式
    /// </summary>
    /// <param name="outpath"></param>
    /// <param name="platform"></param>
    /// <param name="mode"></param>
    static public void RoslynBuild(string outpath, RuntimePlatform platform, ScriptBuildTools.BuildMode mode, bool isShowTips = true)
    {
        //触发bd环境周期
        BDEditorBehaviorHelper.OnBeginBuildDLL();

        var targetPath = "Assets/Code/BDFramework.Game/ILRuntime/Binding/Analysis";
        //1.分析之前先删除,然后生成临时文件防止报错
        // if (Directory.Exists(targetPath))
        // {
        //     Directory.Delete(targetPath, true);
        // }

        var fileContent = @"
        namespace ILRuntime.Runtime.Generated
        {
            class CLRBindings
            {
                internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Vector2> s_UnityEngine_Vector2_Binding_Binder = null;
                internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Vector3> s_UnityEngine_Vector3_Binding_Binder = null;
                internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Vector4> s_UnityEngine_Vector4_Binding_Binder = null;
                internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<UnityEngine.Quaternion> s_UnityEngine_Quaternion_Binding_Binder = null;
                public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
                {
                }
            } 
        }   ";

        FileHelper.WriteAllText(targetPath + "/CLRBindings.cs", fileContent);
        AssetDatabase.Refresh(); //这里必须要刷新

        //2.生成DLL
        ScriptBuildTools.BuildDll(outpath, platform, mode, isShowTips);

        //3.预绑定
        //GenPreCLRBinding();
        //4.生成自动分析绑定
        GenCLRBindingByAnalysis(platform, outpath);
        AssetDatabase.Refresh();
        //触发bd环境周期
        BDEditorBehaviorHelper.OnEndBuildDLL(outpath);
    }
Ejemplo n.º 2
0
        /// <summary>
        /// json转sql
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="jsonContent"></param>
        static public void Json2Sqlite(string filePath, string jsonContent)
        {
            var table      = Path.GetFileName(filePath).Replace(Path.GetExtension(filePath), "");
            var jsonObj    = JsonMapper.ToObject(jsonContent);
            var dbname     = Path.GetFileNameWithoutExtension(SqliteHelper.DB.DBPath);
            var @namespace = "Game.Data." + dbname + ".";
            var type       = BDFrameEditorLife.Types.FirstOrDefault((t) => t.FullName.StartsWith(@namespace) && t.Name.ToLower() == table.ToLower());

            if (type == null)
            {
                type = BDFrameEditorLife.Types.FirstOrDefault((t) => t.FullName.StartsWith("Game.Data.") && t.Name.ToLower() == table.ToLower());
            }
            if (type == null)
            {
                Debug.LogError(table + "类不存在,请检查!");
                return;
            }
            //
            EditorUtility.DisplayProgressBar("Excel2Sqlite", string.Format("生成:{0} 记录条目:{1}", type.FullName, jsonObj.Count), 0);
            Debug.LogFormat("导出 [{0}]:{1}", dbname, filePath.Replace(Application.dataPath + "\\", "") + "=>【" + type.FullName + "】");
            //数据库创建表
            SqliteHelper.DB.CreateTable(type);
            for (int i = 0; i < jsonObj.Count; i++)
            {
                try
                {
                    var json = jsonObj[i].ToJson();
                    var jobj = JsonMapper.ToObject(type, json);
                    SqliteHelper.DB.Insert(jobj);
                }
                catch (Exception e)
                {
                    Debug.LogError("导出数据有错,跳过! 错误位置:" + type.Name + ":" + i + "/" + jsonObj.Count + "\n" + e);
                }
            }
            //回调通知
            BDEditorBehaviorHelper.OnExportExcel(type);
            //
            EditorUtility.DisplayProgressBar("Excel2Sqlite", string.Format("生成:{0} 记录条目:{1}", type.Name, jsonObj.Count), 1);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成sqlite
        /// 默认导出到当前平台目录下
        /// </summary>
        /// <param name="ouptputPath">自定义路径</param>
        public static void AllExcel2SQLite(string ouptputPath, RuntimePlatform platform, DBType dbType = DBType.Local)
        {
            //触发bd环境周期
            BDEditorBehaviorHelper.OnBeginBuildSqlite();
            var xlslFiles = GetAllConfigFiles();

            switch (dbType)
            {
            case DBType.Local:
                SqliteLoder.LoadLocalDBOnEditor(ouptputPath, platform);
                break;

            case DBType.Server:
                SqliteLoder.LoadServerDBOnEditor(ouptputPath, platform);
                break;
            }
            {
                foreach (var f in xlslFiles)
                {
                    try
                    {
                        Excel2SQLite(f, dbType);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("导表失败:" + f);
                        EditorUtility.ClearProgressBar();
                    }
                }
            }
            SqliteLoder.Close();
            //
            EditorUtility.ClearProgressBar();
            //触发bd环境周期
            BDEditorBehaviorHelper.OnEndBuildSqlite(ouptputPath);
            AssetHelper.AssetHelper.GenPackageBuildInfo(ouptputPath, platform);
            Debug.Log("导出Sqlite完成!");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 生成AssetBundle
        /// </summary>
        /// <param name="outputPath">导出目录</param>
        /// <param name="target">平台</param>
        /// <param name="options">打包参数</param>
        /// <param name="isHashName">是否为hash name</param>
        public static bool GenAssetBundle(string outputPath,
                                          RuntimePlatform platform,
                                          BuildTarget target,
                                          BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression,
                                          bool isHashName = false,
                                          string AES      = "")
        {
            var _outputPath = Path.Combine(outputPath, BDApplication.GetPlatformPath(platform));
            //
            var artOutputPath = IPath.Combine(_outputPath, "Art");
            var buildInfoPath = IPath.Combine(artOutputPath, "BuildInfo.json");

            //初始化
            allfileHashMap = new Dictionary <string, string>();
            var assetPaths = BDApplication.GetAllAssetsPath();

            for (int i = 0; i < assetPaths.Count; i++)
            {
                assetPaths[i] = assetPaths[i].ToLower();
            }

            /***********************新老资源依赖生成************************/
            //获取老的配置
            BuildInfo lastBuildInfo = new BuildInfo();

            if (File.Exists(buildInfoPath))
            {
                var content = File.ReadAllText(buildInfoPath);
                lastBuildInfo = JsonMapper.ToObject <BuildInfo>(content);
            }

            //获取当前配置
            var newbuildInfo = GetAssetsInfo(assetPaths);

            var buildinfoCahce = JsonMapper.ToJson(newbuildInfo);

            //BD生命周期触发
            BDEditorBehaviorHelper.OnBeginBuildAssetBundle(newbuildInfo);
            //获取改动的数据
            var changedBuildInfo = GetChangedAssets(lastBuildInfo, newbuildInfo);

            // newbuildInfo = null; //防止后面再用
            if (changedBuildInfo.AssetDataMaps.Count == 0)
            {
                Debug.Log("无资源改变,不需要打包!");
                return(false);
            }

            #region 整理依赖关系

            //1.把依赖资源替换成AB Name,
            foreach (var asset in newbuildInfo.AssetDataMaps.Values)
            {
                for (int i = 0; i < asset.DependList.Count; i++)
                {
                    var da = asset.DependList[i];
                    var dependAssetData = newbuildInfo.AssetDataMaps[da];
                    //替换成真正AB名
                    if (!string.IsNullOrEmpty(dependAssetData.ABName))
                    {
                        asset.DependList[i] = dependAssetData.ABName;
                    }
                }

                //去重
                asset.DependList = asset.DependList.Distinct().ToList();
                asset.DependList.Remove(asset.ABName);
            }

            var runtimeStr = "/runtime/";

            if (isHashName)
            {
                //使用guid 作为ab名

                foreach (var asset in newbuildInfo.AssetDataMaps)
                {
                    var abname = AssetDatabase.AssetPathToGUID(asset.Value.ABName);
                    if (!string.IsNullOrEmpty(abname)) //不存在的资源(如ab.shader之类),则用原名
                    {
                        asset.Value.ABName = abname;
                    }
                    else
                    {
                        Debug.LogError("获取GUID失败:" + asset.Value.ABName);
                    }

                    for (int i = 0; i < asset.Value.DependList.Count; i++)
                    {
                        var dependAssetName = asset.Value.DependList[i];

                        abname = AssetDatabase.AssetPathToGUID(dependAssetName);
                        if (!string.IsNullOrEmpty(abname)) //不存在的资源(如ab.shader之类),则用原名
                        {
                            asset.Value.DependList[i] = abname;
                        }
                        else
                        {
                            Debug.LogError("获取GUID失败:" + dependAssetName);
                        }
                    }
                }
            }
            else
            {
                //2.整理runtime路径 替换路径名为Resource规则的名字

                foreach (var asset in newbuildInfo.AssetDataMaps)
                {
                    if (asset.Key.Contains(runtimeStr))
                    {
                        var newName = asset.Value.ABName;
                        //移除runtime之前的路径、后缀
                        var index = newName.IndexOf(runtimeStr);
                        newName = newName.Substring(index + 1); //runtimeStr.Length);

                        var extension = Path.GetExtension(newName);
                        if (!string.IsNullOrEmpty(extension))
                        {
                            newName = newName.Replace(extension, "");
                        }

                        //刷新整个列表替换
                        foreach (var _asset in newbuildInfo.AssetDataMaps)
                        {
                            var oldName = asset.Key.ToLower();
                            //ab替换
                            if (_asset.Value.ABName == oldName)
                            {
                                _asset.Value.ABName = newName;
                            }

                            //依赖替换
                            for (int i = 0; i < _asset.Value.DependList.Count; i++)
                            {
                                if (_asset.Value.DependList[i] == oldName)
                                {
                                    _asset.Value.DependList[i] = newName;
                                }
                            }
                        }
                    }
                }
            }

            #endregion


            #region 生成Runtime使用的Config

            //根据buildinfo 生成加载用的 Config
            //1.只保留Runtime目录下的配置
            ManifestConfig config = new ManifestConfig();
            config.IsHashName = isHashName;
            //
            foreach (var item in newbuildInfo.AssetDataMaps)
            {
                //runtime路径下,
                //改成用Resources加载规则命名的key
                if (item.Key.Contains(runtimeStr))
                {
                    var key = item.Key;
                    //移除runtime之前的路径、后缀
                    var index = key.IndexOf(runtimeStr);
                    if (config.IsHashName)
                    {
                        key = key.Substring(index + runtimeStr.Length); //hash要去掉runtime
                    }
                    else
                    {
                        key = key.Substring(index + 1); // 保留runtime
                    }

                    var exten = Path.GetExtension(key);
                    if (!string.IsNullOrEmpty(exten))
                    {
                        key = key.Replace(exten, "");
                    }

                    //添加manifest
                    var mi = new ManifestItem(item.Value.ABName, (ManifestItem.AssetTypeEnum)item.Value.Type,
                                              new List <string>(item.Value.DependList));
                    config.ManifestMap[key] = mi;
                }
            }


            //写入
            FileHelper.WriteAllText(artOutputPath + "/Config.json", JsonMapper.ToJson(config));

            #endregion


            #region 设置ABname

            /***********************开始设置build ab************************/
            //设置AB name
            foreach (var changedAsset in changedBuildInfo.AssetDataMaps)
            {
                //根据改变的ChangedAssets,获取Asset的资源
                var key   = changedAsset.Key;
                var asset = newbuildInfo.AssetDataMaps[changedAsset.Key];
                //设置ABName 有ab的则用ab ,没有就用configpath
                string abname = asset.ABName;
                //
                var ai = GetAssetImporter(key);
                if (ai)
                {
                    ai.assetBundleName = abname;
                }
            }

            #endregion


            //3.生成AssetBundle
            try
            {
                BuildAssetBundle(target, _outputPath, options);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                throw;
            }

            //4.清除AB Name
            RemoveAllAssetbundleName();
            AssetImpoterCacheMap.Clear();
            //the end.删除无用文件
            var delFiles = Directory.GetFiles(artOutputPath, "*", SearchOption.AllDirectories);
            foreach (var df in delFiles)
            {
                var ext = Path.GetExtension(df);
                if (ext == ".meta" || ext == ".manifest")
                {
                    File.Delete(df);
                }
            }

            //the end. BuildInfo写入
            if (File.Exists(buildInfoPath))
            {
                string targetPath = artOutputPath + "/BuildInfo.old.json";
                File.Delete(targetPath);
                File.Move(buildInfoPath, targetPath);
            }

            FileHelper.WriteAllText(buildInfoPath, buildinfoCahce);

            //BD生命周期触发
            BDEditorBehaviorHelper.OnEndBuildAssetBundle(outputPath);
            AssetHelper.AssetHelper.GenPackageBuildInfo(outputPath, platform);

            return(true);
        }