目次
序文:
私はずっと前にこのフレームワークについて聞いたことがあり (ゲーム フレームワーク | Unity エンジンに基づくゲーム フレームワーク)、公式ドキュメントと小さなチュートリアル (変更しないでください) を読み、多くのビデオ チュートリアル、ブログ、などなど。しかし、それらのほとんどはコード分析にとどまるだけであり、詳細な実践的な教育はほとんどありません。そのため、読んでみるとなんとなくわかったような気もするが、いざ使ってみると途方に暮れるということがよくある。
そこで、学習を促進するために練習 を使用することに決め、GameFrameWork フレームワークを使用して単純で比較的完全なプロジェクトの実装を開始し、そのプロセスを記録しました。
この演習の主な内容は、私たちのチームが作成したゲーム「Ruying」 (Unity バージョン: 2021.3.1f1c1) にフレームワークを適用することです。全体のプロセスの主なリファレンスは、公式のケース「StarForce」 ( GitHub - EllanJiang/StarForce: これは Game Framework で作成されたデモです。 ) ソース コードを読み取り、さまざまなドキュメントをクエリして、途中で遭遇する問題を解決します。チュートリアルなど。個人の能力に限りがあるため、誤りがあればご指摘ください。
というわけで、ゲーム開始!
1. プロジェクトを作成し、フレームワークを導入する
この部分は非常にシンプルで、公式サイトや各種チュートリアルに詳細なプランが掲載されています。ここに記録するだけです。
まず、公式 Web サイトで最新のフレームワーク プラグインをダウンロードします。
プロジェクトを作成し、フォルダー GameMain を作成してゲーム コンテンツをインストールし、ダウンロードしたフレームワークにドラッグします。
この時点で、ゲーム フレームワークは問題なくインストールされています。
サンプル シナリオ テストを実行します。
問題ない:
2. ゲーム入場
フレームワークをインストールしたら、ゲーム エントリGameEntry (StarForce から学ぶ) を作成します。
その役割は、実際には、グローバル呼び出しに便利なすべてのフレームワーク モジュール (組み込みおよびカスタムを含む) コンポーネントの参照を格納および管理することです。(実際、フレームワークの中にGameEntryとGameFrameworkEntryがあります。個人的には、ここで作成されたGameEntry は、フレームワークとゲーム本体との間のデカップリングのステップであると感じています)。
Scriptsフォルダーを作成します。
その中にBaseフォルダーを作成します。
GameEntryクラスの 3 つの部分を (文字通り)管理するために、3 つのスクリプト、GameEntry、GameEntry.Builtin、および GameEntry.Customを作成します。
3 つのスクリプトのコードは次のとおりです。
//GameEntry.cs
using UnityEngine;
using UnityGameFramework.Runtime;
namespace ShadowU
{
public partial class GameEntry : MonoBehaviour
{
private void Start()
{
InitBuiltinComponents();
InitCustomComponents();
}
}
}
//GameEntry.Builtin.cs
using UnityEngine;
using UnityGameFramework.Runtime;
namespace ShadowU
{
/// <summary>
/// 内置模块
/// </summary>
public partial class GameEntry : MonoBehaviour
{
/// <summary>
/// 获取游戏基础组件。
/// </summary>
public static BaseComponent Base
{
get;
private set;
}
/// <summary>
/// 获取配置组件。
/// </summary>
public static ConfigComponent Config
{
get;
private set;
}
/// <summary>
/// 获取数据结点组件。
/// </summary>
public static DataNodeComponent DataNode
{
get;
private set;
}
/// <summary>
/// 获取数据表组件。
/// </summary>
public static DataTableComponent DataTable
{
get;
private set;
}
/// <summary>
/// 获取调试组件。
/// </summary>
public static DebuggerComponent Debugger
{
get;
private set;
}
/// <summary>
/// 获取下载组件。
/// </summary>
public static DownloadComponent Download
{
get;
private set;
}
/// <summary>
/// 获取实体组件。
/// </summary>
public static EntityComponent Entity
{
get;
private set;
}
/// <summary>
/// 获取事件组件。
/// </summary>
public static EventComponent Event
{
get;
private set;
}
/// <summary>
/// 获取文件系统组件。
/// </summary>
public static FileSystemComponent FileSystem
{
get;
private set;
}
/// <summary>
/// 获取有限状态机组件。
/// </summary>
public static FsmComponent Fsm
{
get;
private set;
}
/// <summary>
/// 获取本地化组件。
/// </summary>
public static LocalizationComponent Localization
{
get;
private set;
}
/// <summary>
/// 获取网络组件。
/// </summary>
public static NetworkComponent Network
{
get;
private set;
}
/// <summary>
/// 获取对象池组件。
/// </summary>
public static ObjectPoolComponent ObjectPool
{
get;
private set;
}
/// <summary>
/// 获取流程组件。
/// </summary>
public static ProcedureComponent Procedure
{
get;
private set;
}
/// <summary>
/// 获取资源组件。
/// </summary>
public static ResourceComponent Resource
{
get;
private set;
}
/// <summary>
/// 获取场景组件。
/// </summary>
public static SceneComponent Scene
{
get;
private set;
}
/// <summary>
/// 获取配置组件。
/// </summary>
public static SettingComponent Setting
{
get;
private set;
}
/// <summary>
/// 获取声音组件。
/// </summary>
public static SoundComponent Sound
{
get;
private set;
}
/// <summary>
/// 获取界面组件。
/// </summary>
public static UIComponent UI
{
get;
private set;
}
/// <summary>
/// 获取网络组件。
/// </summary>
public static WebRequestComponent WebRequest
{
get;
private set;
}
private static void InitBuiltinComponents()
{
Base = UnityGameFramework.Runtime.GameEntry.GetComponent<BaseComponent>();
Config = UnityGameFramework.Runtime.GameEntry.GetComponent<ConfigComponent>();
DataNode = UnityGameFramework.Runtime.GameEntry.GetComponent<DataNodeComponent>();
DataTable = UnityGameFramework.Runtime.GameEntry.GetComponent<DataTableComponent>();
Debugger = UnityGameFramework.Runtime.GameEntry.GetComponent<DebuggerComponent>();
Download = UnityGameFramework.Runtime.GameEntry.GetComponent<DownloadComponent>();
Entity = UnityGameFramework.Runtime.GameEntry.GetComponent<EntityComponent>();
Event = UnityGameFramework.Runtime.GameEntry.GetComponent<EventComponent>();
FileSystem = UnityGameFramework.Runtime.GameEntry.GetComponent<FileSystemComponent>();
Fsm = UnityGameFramework.Runtime.GameEntry.GetComponent<FsmComponent>();
Localization = UnityGameFramework.Runtime.GameEntry.GetComponent<LocalizationComponent>();
Network = UnityGameFramework.Runtime.GameEntry.GetComponent<NetworkComponent>();
ObjectPool = UnityGameFramework.Runtime.GameEntry.GetComponent<ObjectPoolComponent>();
Procedure = UnityGameFramework.Runtime.GameEntry.GetComponent<ProcedureComponent>();
Resource = UnityGameFramework.Runtime.GameEntry.GetComponent<ResourceComponent>();
Scene = UnityGameFramework.Runtime.GameEntry.GetComponent<SceneComponent>();
Setting = UnityGameFramework.Runtime.GameEntry.GetComponent<SettingComponent>();
Sound = UnityGameFramework.Runtime.GameEntry.GetComponent<SoundComponent>();
UI = UnityGameFramework.Runtime.GameEntry.GetComponent<UIComponent>();
WebRequest = UnityGameFramework.Runtime.GameEntry.GetComponent<WebRequestComponent>();
}
}
}
//GameEntry.Custom.cs
using UnityEngine;
using UnityGameFramework.Runtime;
namespace ShadowU
{
/// <summary>
/// 用户自定义模块
/// </summary>
public partial class GameEntry : MonoBehaviour
{
private void InitCustomComponents()
{
}
}
}
(組み込み部分のコードは基本的に死んでいるのでコピペして、カスタム中の自分と拡張部分を比較してみます)
次に、シーン フォルダーを作成し、スタートアップ シーンとしてShadowULauncherシーンを作成し、空のオブジェクトFrameWork を追加してそれにGameEntryを掛け、GameFrameWorkプレハブをその子オブジェクトとして設定します。
ここまでで基本的な準備は完了ですので、以下から作成に入ります。