当前位置:网站首页>GameFramework制作游戏(一)
GameFramework制作游戏(一)
2022-07-25 14:24:00 【AT巡礼】
前言:关于去如何去下载安装框架,这里我就不教了,网上太多了
这是下载地址:https://gameframework.cn/download/
1.创建第一个脚本
当我们开始做的时候,创建一个Sence,然后把GameFramework预制体拖进来,如下图

创建一个脚本Demo11_ProcedureLaunch,继承自procedureBase
using GameFramework.Procedure;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
public class Demo11_ProcedureLaunch : ProcedureBase
{
protected override void OnEnter(ProcedureOwner procedureOwner)
{
base.OnEnter(procedureOwner);
Debug.LogError("1111");//在这里可以打印出你想要的东西,例如sayHelloWorld
}
}
把你写的脚本放到流程里
2.然后做切换场景
using GameFramework.Procedure;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
public class Demo11_ProcedureLaunch : ProcedureBase
{
protected override void OnEnter(ProcedureOwner procedureOwner) //你可以理解成Start() 生命周期
{
base.OnEnter(procedureOwner);
Debug.LogError("1111");//在这里可以打印出你想要的东西,例如sayHelloWorld
SceneComponent Scene
= UnityGameFramework.Runtime.GameEntry.GetComponent<SceneComponent>(); //是专门用于处理场景逻辑的框架组件,看下图
// 切换场景
Scene.LoadScene("Assets/Demo11/Demo11_Meun.unity", this);//场景路径
// 切换流程
ChangeState<Demo11_Meun>(procedureOwner);
Debug.LogError("??/");
}
}

这个时候我们需要创建一个新的空场景Demo11_Meun场景,和一个Demo11_Meun脚本,用于跳转
脚本很简单
using GameFramework.Procedure;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
public class Demo11_Meun : ProcedureBase//继承是为了把该脚本写进流程
{
protected override void OnEnter(ProcedureOwner procedureOwner)
{
base.OnEnter(procedureOwner);
}
}
继承ProcedureBase,进入流程后,记得勾选流程
勾上你要显示的菜单脚本
然后打开Build Settings 把场景放进来
运行
场景就加载出来了。
3.场景第二次加载,卸载第一次加载的场景,原场景是不会卸载的
创建Demo11_Game场景,创建Demo11_Game脚本
脚本继续继承,记得勾选流程
using GameFramework.Procedure;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
public class Demo11_Game : ProcedureBase
{
protected override void OnEnter(ProcedureOwner procedureOwner)
{
base.OnEnter(procedureOwner);
Debug.Log("进入游戏流程,可以在这里处理游戏逻辑,这条日志不会打印,因为没有切换到Game流程");
}
}
写个控制脚本Demo11_Controller继承Monobehaviour,创建一个Button,在Demo11_Meun场景
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
public class Demo11_Controller : MonoBehaviour
{
public void NextMethod()
{
// 获取框架场景组件
SceneComponent Scene
= UnityGameFramework.Runtime.GameEntry.GetComponent<SceneComponent>();
// 卸载所有场景
string[] loadedSceneAssetNames = Scene.GetLoadedSceneAssetNames();
for (int i = 0; i < loadedSceneAssetNames.Length; i++)
{
Scene.UnloadScene(loadedSceneAssetNames[i]);
}
// 加载游戏场景
Scene.LoadScene("Assets/Demo11/Demo11_Game.unity", this);
}
}

记得吧Demo11_Game场景放到BuildSettings里面,
运行
点击按钮,进入Game场景,卸载Menu场景,我们初始的第一个场景是不会被卸载的。
边栏推荐
- A small part is exposed on one or both sides of the swiper
- 金鱼哥RHCA回忆录:CL210管理存储--对象存储
- Mongodb source code deployment and configuration
- Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
- Paddlenlp's UIE relationship extraction model [executive relationship extraction as an example]
- Summary of some problems about left value and right value [easy to understand]
- Wangeditor rich text editor
- ~5 new solution of CCF 2021-12-2 sequence query
- Gateway 网关报错 SERVICE_UNAVAILABLE
- Teach you how to apply for SSL certificate
猜你喜欢

实现一个家庭安防与环境监测系统(二)

MySQL table operation

Okaleido ecological core equity Oka, all in fusion mining mode
![[eloquence] negotiation persuasion skills and Strategies](/img/01/0fcbbfcf35a6d166c14ba4215eacac.jpg)
[eloquence] negotiation persuasion skills and Strategies

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part 2) -- use of openmmlab framework

Mysql表的操作

How to design a high concurrency system?

Keys and scan based on redis delete keys with TTL -1

51单片机学习笔记(1)

~4.2 CCF 2021-12-1 sequence query
随机推荐
Paddlenlp之UIE关系抽取模型【高管关系抽取为例】
That day, I installed a database for my sister... Just help her sort out another shortcut
科隆新能源IPO被终止:拟募资6亿 先进制造与战新基金是股东
Problems and extensions of the monocular depth estimation model featdepth in practice
Realize a family security and environmental monitoring system (I)
Typora无法打开提示安装新版本解决办法
NUC980 设置SSH Xshell连接
[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster
Reverse Integer
Mongodb source code deployment and configuration
Sqli labs installation environment: ubuntu18 php7
手把手教你申请SSL证书
Bond0 script
Filters get the data in data; Filters use data in data
sudo rosdep init Error ROS安装问题解决方案
依迅总经理孙峰:公司已完成股改,准备IPO
结构体大小
Apple failed to synchronize on its mobile terminal, and logged out. As a result, it could not log in again
~4.1 sword finger offer 05. replace spaces
Throwing OutOfMemoryError “Could not allocate JNI Env“