首页 > 其他分享 >搭建UnityGameFramework框架最低需求项目

搭建UnityGameFramework框架最低需求项目

时间:2022-08-17 15:12:21浏览次数:86  
标签:xml 框架 GameFramework UnityGameFramework Path using public 搭建

1、下载 Game Framework 包

进入官网的下载页面下载2021.05.31版本 https://gameframework.cn/download/

2、新建Unity项目,然后把包导入

3、新建Editor文件夹,并创建 GameFrameworkConfigs.cs 脚本

GameFrameworkConfigs.cs 这是指定xml配置文件的脚本,可以修改路径

using GameFramework;
using System.IO;
using UnityEngine;
using UnityGameFramework.Editor;
using UnityGameFramework.Editor.ResourceTools;

public static class GameFrameworkConfigs
{
    [BuildSettingsConfigPath]
    public static string BuildSettingsConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/BuildSettings.xml"));

    [ResourceCollectionConfigPath]
    public static string ResourceCollectionConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/ResourceCollection.xml"));

    [ResourceEditorConfigPath]
    public static string ResourceEditorConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/ResourceEditor.xml"));

    [ResourceBuilderConfigPath]
    public static string ResourceBuilderConfig = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "GameMain/Configs/ResourceBuilder.xml"));
}

4、创建 GameFrameworkConfigs.cs 脚本中提到的 4 个 xml 文件

BuildSettings.xml (DefaultScene 是启动创建根据需要修改)

<?xml version="1.0" encoding="UTF-8"?>
<UnityGameFramework>
  <BuildSettings>
    <DefaultScenes>
      <DefaultScene Name="Assets/Launcher.unity" />
    </DefaultScenes>
    <SearchScenePaths>
      <SearchScenePath Path="Assets" />
    </SearchScenePaths>
  </BuildSettings>
</UnityGameFramework>

ResourceCollection.xml 是配置AB包要打包的资源。 使用UGF自带的编辑器编辑可能会出现错误,可以将 Resources 和 Assets 中的内容全部删除重新编辑

<?xml version="1.0" encoding="UTF-8"?>
<UnityGameFramework>
  <ResourceCollection>
    <Resources>
      <Resource Name="Prefabs/Cube" LoadType="0" Packed="False" />
      <Resource Name="Prefabs/Panel" LoadType="0" Packed="False" />
      <Resource Name="Scenes/Menu" LoadType="0" Packed="False" />
    </Resources>
    <Assets>
      <Asset Guid="4001e38f08c97ba47a17ee5abcb6a388" ResourceName="Prefabs/Cube" />
      <Asset Guid="80381cb4a7962eb4089d41001ca2218c" ResourceName="Prefabs/Panel" />
      <Asset Guid="c56d6ccf379a228439a15bc3c45518b6" ResourceName="Scenes/Menu" />
    </Assets>
  </ResourceCollection>
</UnityGameFramework>

ResourceEditor.xml 配置资源文件的根目录和哪些文件会出现在 打包的资源编辑器中

<?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>

ResourceBuilder.xml 配置打包选项,如打包输出目录,一般不需要手动修改

<?xml version="1.0" encoding="UTF-8"?>
<UnityGameFramework>
  <ResourceBuilder>
    <Settings>
      <InternalResourceVersion>22</InternalResourceVersion>
      <Platforms>1</Platforms>
      <AssetBundleCompression>1</AssetBundleCompression>
      <CompressionHelperTypeName>UnityGameFramework.Runtime.DefaultCompressionHelper</CompressionHelperTypeName>
      <AdditionalCompressionSelected>True</AdditionalCompressionSelected>
      <ForceRebuildAssetBundleSelected>False</ForceRebuildAssetBundleSelected>
      <BuildEventHandlerTypeName>
      </BuildEventHandlerTypeName>
      <OutputDirectory>D:/ProjectUnity/UgfPackageTemplate/AB</OutputDirectory>
      <OutputPackageSelected>True</OutputPackageSelected>
      <OutputFullSelected>False</OutputFullSelected>
      <OutputPackedSelected>False</OutputPackedSelected>
    </Settings>
  </ResourceBuilder>
</UnityGameFramework>

5、创建启动场景 Launcher.unity ,将框架的预制体GameFramework拖入场景中,然后编写代码

参考 https://gameframework.cn/tutorial/tutorial-003/ 搭建可以快速访问UGF组件的工具和自定义组件

6、注意

单机模式需要调用 GameEntry.Resource.InitResources(); 并成功后才能使用加载资源的方法(如显示UI、实体等)

using UnityEngine;
using GameFramework;
using GameFramework.Event;
using GameFramework.Resource;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;

public class ProcedureStart : GameFramework.Procedure.ProcedureBase
{
    bool m_InitResourcesComplete = false;
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);
        if (GameEntry.Base.EditorResourceMode)
        {
            // 编辑器模式
            m_InitResourcesComplete = true;
        }
        else if (GameEntry.Resource.ResourceMode == ResourceMode.Package)
        {
            // 单机模式 调用InitResources方法
            GameEntry.Resource.InitResources(OnInitResourcesComplete);
        }
    }
    private void OnInitResourcesComplete()
    {
        m_InitResourcesComplete = true;
    }
    protected override void OnUpdate(ProcedureOwner procedureOwner,float elapseSeconds,float realElapseSeconds)
    {
        base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
        if (m_InitResourcesComplete)
        {
            ChangeState<ProcedureMenu>(procedureOwner);// 资源加载成功后切换流程
        }
    }
}

标签:xml,框架,GameFramework,UnityGameFramework,Path,using,public,搭建
From: https://www.cnblogs.com/lvhc/p/16595275.html

相关文章

  • spring 源码搭建
    这是不坚持写博客写的第7篇博客,搭建spring5源码运行环境idea版本:   第一步:拉取5.1.x版本代码到本地,官方的,中文注释的都可以 第二步:因为spring源码使用gradle......
  • Taurus.MVC 微服务框架 入门开发教程:项目部署:3、微服务应用程序版本升级:全站升级和局
    系列目录:本系列分为项目集成、项目部署、架构演进三个方向,后续会根据情况调整文章目录。本系列第一篇:Taurus.MVCV3.0.3微服务开源框架发布:让.NET架构在大并发的演进......
  • Pytest框架 — 09、Pytest的conftest.py文件
    目录1、conftest.py介绍2、conftest.py的特点3、conftest.py文件的使用4、conftest.py的作用域1、conftest.py介绍conftest.py是pytest框架的一种固定写法,把fixture或者......
  • SSM环境搭建
    一、下载安装Spring下载Spring地址:https://repo.spring.io/libs-release-local/沿着org-springframework-spring,可以看到各版本的压缩包下载链接  解压后有如下几个......
  • 集合框架4-----Set集合
    Set集合参考视频:13.23Set集合概述哔哩哔哩bilibili  Set实现类  HashSet的使用存储结构:哈希表(数组+链表+红黑树)存储过程:1.根据hashcode计算保存的......
  • Windows下ESP32 环境搭建(基于esp-idf FreeRTOS)
    1.之前的尝试(失败的尝试)咸鱼买了3块ESP32开发板。背面写了NODEMCUv1.1,好像这玩意可以直接写lua,也可以刷Micropython写python,还可以用ArduinoIDE写c。我想直接用官方库......
  • 迁移与备份,Dockerfile,Docker私有仓库,Docker-compose,Mysql主从搭建,django读写分离
    1迁移与备份#一个容器内,尽量只有一个软件,不要把mysql,redis,。。。方到一个容器中,而要放到多个容器#镜像---》容器---》装了软件(vim,mysql)---》打包成镜像#打包后的镜......
  • MySQL篇:MySQL主从搭建、django读写分离
    目录一、MySQL主从搭建1.1什么是主从同步?1.2原理1.3搭建步骤1.3.1拉取mysql5.7镜像1.3.2创建一些文件夹,用来做目录映射1.3.3启动两个docker容器1.3.4链接主库1.3.5......
  • 【菜鸟学会】nacos服务及集群搭建
    官网地址https://nacos.io/zh-cn/docs/quick-start.html快速开始单应用https://nacos.io/zh-cn/docs/quick-start.html应用数据源配置nacos服务默认启动会创建内部......
  • Spring框架认识
    Spring框架1、入职必备篇:Spring框架Spring属于开源框架,Spring是于2003年流行起来的一个轻量级的Java开发基础框架,它是为了解决企业应用开发的复杂性而提供的解决方案......