1. UnityGameFramwork打包流程
首先从官网下载插件直接导入项目中即可
网址:下载地址?
教程:教程地址
工程示例:GitHub - EllanJiang/StarForce: This is a demo made with Game Framework.?
项目导入之后首先进行打包准备:
在自己的工程下面建立目录Game Main,如图:
configs放置我们的配置文件,然后我们在Editor文件夹加载该配置文件
第一步:生成配置文件
?点击之后打开面板,点击右下脚保存,生成两个配置文件:
修改ResourceEditor配置文件信息:
<?xml version="1.0" encoding="UTF-8"?>
<UnityGameFramework>
<ResourceEditor>
<Settings>
<SourceAssetRootPath>Assets/GameMain</SourceAssetRootPath>
<SourceAssetSearchPaths>
<SourceAssetSearchPath RelativePath="" />
</SourceAssetSearchPaths>
<SourceAssetUnionTypeFilter>t:Scene t:Prefab t:Shader t:Model t:Material t:Texture t:AudioClip t:AnimationClip t:AnimatorController t:Font t:TextAsset t:ScriptableObject</SourceAssetUnionTypeFilter>
<SourceAssetUnionLabelFilter>l:ResourceInclusive</SourceAssetUnionLabelFilter>
<SourceAssetExceptTypeFilter>t:Script</SourceAssetExceptTypeFilter>
<SourceAssetExceptLabelFilter>l:ResourceExclusive</SourceAssetExceptLabelFilter>
<AssetSorter>Path</AssetSorter>
</Settings>
</ResourceEditor>
</UnityGameFramework>
再打开ResourcesBuilder面板,同样点击保存,生成第三个配置文件
将三个配置文件,保存到自己的configs文件夹下面,
Editor新建脚本
using GameFramework;
using System.IO;
using UnityEngine;
using UnityGameFramework.Editor;
using UnityGameFramework.Editor.ResourceTools;
public static class GameFrameworkConfigs
{
[ResourceBuilderConfigPath]
public static string ResourceBuilderConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/ResourceBuilder.xml"));
[ResourceEditorConfigPath]
public static string ResourceEditorConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/ResourceEditor.xml"));
[ResourceCollectionConfigPath]
public static string ResourceCollectionConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/ResourceCollection.xml"));
//[BuildSettingsConfigPath]
//public static string BuildSettingsConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/BuildSettings.xml"));
}
配置完成。
?最左边为自己新建的AB包,
最右边为你想要打包的资源,
Packed为是否随包发布。
Package文件夹为StreamingAssets测试文件夹?
打包后文件夹Fullpath为你上传到资源服务器的文件夹,BuidReporter文件夹为你配置信息。
至此基本操作完成
打包后事件:
//------------------------------------------------------------
// Game Framework
// Copyright ? 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityGameFramework.Editor.ResourceTools;
namespace StarForce.Editor
{
public sealed class StarForceBuildEventHandler : IBuildEventHandler
{
public bool ContinueOnFailure
{
get
{
return false;
}
}
public void OnPreprocessAllPlatforms(string productName, string companyName, string gameIdentifier, string gameFrameworkVersion, string unityVersion, string applicableGameVersion, int internalResourceVersion,
Platform platforms, AssetBundleCompressionType assetBundleCompression, string compressionHelperTypeName, bool additionalCompressionSelected, bool forceRebuildAssetBundleSelected, string buildEventHandlerTypeName, string outputDirectory, BuildAssetBundleOptions buildAssetBundleOptions,
string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, string buildReportPath)
{
string streamingAssetsPath = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "StreamingAssets"));
string[] fileNames = Directory.GetFiles(streamingAssetsPath, "*", SearchOption.AllDirectories);
foreach (string fileName in fileNames)
{
if (fileName.Contains(".gitkeep"))
{
continue;
}
File.Delete(fileName);
}
Utility.Path.RemoveEmptyDirectory(streamingAssetsPath);
}
public void OnPostprocessAllPlatforms(string productName, string companyName, string gameIdentifier, string gameFrameworkVersion, string unityVersion, string applicableGameVersion, int internalResourceVersion,
Platform platforms, AssetBundleCompressionType assetBundleCompression, string compressionHelperTypeName, bool additionalCompressionSelected, bool forceRebuildAssetBundleSelected, string buildEventHandlerTypeName, string outputDirectory, BuildAssetBundleOptions buildAssetBundleOptions,
string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, string buildReportPath)
{
}
public void OnPreprocessPlatform(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath)
{
}
public void OnBuildAssetBundlesComplete(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, AssetBundleManifest assetBundleManifest)
{
}
public void OnOutputUpdatableVersionListData(Platform platform, string versionListPath, int versionListLength, int versionListHashCode, int versionListCompressedLength, int versionListCompressedHashCode)
{
}
public void OnPostprocessPlatform(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, bool isSuccess)
{
if (!outputPackageSelected)
{
return;
}
if (platform != Platform.Windows)
{
return;
}
string streamingAssetsPath = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "StreamingAssets"));
string[] fileNames = Directory.GetFiles(outputPackagePath, "*", SearchOption.AllDirectories);
foreach (string fileName in fileNames)
{
string destFileName = Utility.Path.GetRegularPath(Path.Combine(streamingAssetsPath, fileName.Substring(outputPackagePath.Length)));
FileInfo destFileInfo = new FileInfo(destFileName);
if (!destFileInfo.Directory.Exists)
{
destFileInfo.Directory.Create();
}
File.Copy(fileName, destFileName);
}
}
}
}
|