Unity 笔记记录(自用,不定时更新)UnityGameFramwork

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);
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用Unity的InvokeRepeating方法来实现定时执行某个方法。在该方法中,你可以通过AndroidJNI类调用Android原生的方法来获取设备内存信息,并将其保存在日志文件中。具体实现步骤如下: 1. 在Unity中创建一个脚本,例如MemoryLogger.cs。 2. 在该脚本中,定义一个方法来获取设备内存信息并保存在日志文件中。例如: ``` private void LogMemory() { // 获取Android的Activity对象 AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); // 获取ActivityManager对象 AndroidJavaObject activityManager = activity.Call<AndroidJavaObject>("getSystemService", "activity"); // 获取MemoryInfo对象 AndroidJavaObject memoryInfo = new AndroidJavaObject("android.app.ActivityManager$MemoryInfo"); activityManager.Call("getMemoryInfo", memoryInfo); // 获取可用内存大小 long availableMemory = memoryInfo.GetLong("availMem"); // 将可用内存大小保存在日志文件中 Debug.Log("Available memory: " + availableMemory); // TODO: 将可用内存大小保存在日志文件中 } ``` 3. 在Start方法中,使用InvokeRepeating方法来定时执行LogMemory方法。例如: ``` void Start() { // 每5秒执行一次LogMemory方法 InvokeRepeating("LogMemory", 0.0f, 5.0f); } ``` 4. 将该脚本挂载在场景中的任何一个GameObject上,运行游戏即可定时记录设备内存信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值