GameFrameWork framework (Unity3D) use notes (1) Entry

Table of contents

Table of contents

Foreword: 

1. Create a project and introduce the framework

2. Game entrance


Foreword: 

        I have heard of this framework a long time ago ( Game Framework | Game Framework based on the Unity engine ), read the official documents and a little tutorial (just don’t change it), and watched a lot of video tutorials, blogs, etc. But most of them only stop at code analysis, and there are few detailed hands-on practical teaching. So it often happens that after reading it, I find that I seem to understand it when I read it, but I am at a loss when I start using it.

        So I decided to use practice to promote learning, and started to implement a simple and relatively complete project with the GameFrameWork framework, and recorded the process.

The main content of this practice is to apply the framework to a game "Ruying"         made by our team (Unity version: 2021.3.1f1c1). The main reference for the whole process is the official case "StarForce" ( GitHub - EllanJiang/StarForce: This is a demo made with Game Framework. ) I will solve the problems encountered in the middle by reading the source code, querying various documents and tutorials, etc. . Due to limited personal ability, please point out any mistakes.

So, the game begins!


1. Create a project and introduce the framework

        This part is very simple, and there are detailed plans on the official website and various tutorials. Simply record it here.

        First download the latest framework plugin on the official website: 

 Create a project, create a folder GameMain to install game content and then drag in the downloaded framework:

At this point, the game framework is installed just fine:

 Run the Example scenario test:

no problem:


2. Game entrance

After the framework is installed, it is to create the game entry GameEntry (learn from StarForce).

Its role is actually to store and manage the references of all framework modules (including built-in and custom) components, which are convenient for global calls. (In fact, there is a GameEntry and GameFrameworkEntry inside the framework . I personally feel that the GameEntry created here is a step of decoupling between the framework and the main body of the game).

Create the Scripts folder:

Create the Base folder in it :

Create three scripts , GameEntry, GameEntry.Builtin, and GameEntry.Custom , to manage the three parts of the GameEntry class (literally):

The codes of the three scripts are as follows:

//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()
        {

        }
    }
}

(The code of the builtin part can be copied because it is basically dead, and then the self in Custom can be compared to the extension)

Then create a scene folder and create a ShadowULauncher scene as a startup scene, add an empty object FrameWork and hang GameEntry on it, and set the GameFrameWork prefab as its child object:

At this point, the basic preparations have been completed, and the creation process will start below.

 

Guess you like

Origin blog.csdn.net/HowToPause/article/details/127183803