Playmaker Load Scenes Async Additive

Jinxter Games
26 Apr 201820:50

Summary

TLDRDG Dino 从 Jinx Games 带来了一个关于如何在 Unity 中使用 Playmaker 插件进行异步场景加载的教程。他首先感谢了购买他资产商店 Playmaker 样本的用户,并请求评价。接着,他展示了下一个教程的预览,并解释了在制作过程中遇到的一些问题,包括 Unity 的一些加载和激活场景的顺序问题。教程详细解释了如何设置断点进行调试,并通过实际操作演示了场景加载和激活的正确顺序,以及如何避免常见错误。最后,他提供了关于如何使用全局事件和监听器来改善游戏性能和用户体验的技巧。

Takeaways

  • 😀 DG Dino 是来自 Jinx Games 的开发者,本教程是关于如何使用 Playmaker 插件中的加载场景(Load Scene)功能。
  • 🙏 DG Dino 感谢所有在 Asset Store 上购买他 Playmaker 示例的用户,并请求用户对资产进行评分和评论。
  • 🔍 DG Dino 展示了他下一个教程的预览,这将是一个完整的游戏,并且会添加到他的 Playmaker 示例资产中。
  • 🛠️ 教程中提到,在制作教程时遇到了一些问题,最初以为是 Playmaker 动作的问题,但后来发现即使在 C# 脚本中也遇到了同样的问题。
  • 🔄 DG Dino 演示了如何使用 Playmaker 设置断点来调试游戏,当游戏运行到断点状态时会暂停,允许开发者检查当前状态。
  • 🎮 教程中展示了如何加载和激活不同的游戏级别,以及如何使用 Playmaker 来控制游戏级别的加载和激活顺序。
  • ⚠️ DG Dino 强调了在加载多个场景时,必须按照正确的顺序激活它们,否则可能会导致游戏卡住。
  • 🔄 教程中提到了卸载场景时需要注意的问题,如果场景未激活就尝试卸载,可能会导致游戏卡住。
  • 📝 DG Dino 演示了如何使用 Playmaker 的“Load Scene Async”动作来异步加载场景,并解释了如何使用变量来控制加载过程。
  • 🔧 教程中还介绍了如何使用“Activate GameObject”动作来激活或停用游戏对象,以及如何使用“Set String Value”动作来设置场景名称。
  • 🔄 DG Dino 通过比较当前级别和要加载的级别,演示了如何实现游戏级别的前进和后退功能。
  • 🎨 教程最后介绍了如何使用 Playmaker 来设置 UI 元素,例如更改背景颜色和更新文本显示。

Q & A

  • DG Dino 是哪个游戏公司的代表?

    -DG Dino 是 Jinx Games 的代表。

  • 在 Unity 中,如果加载多个场景对象,应该按照什么顺序激活它们?

    -在 Unity 中,如果加载多个场景对象,应该先加载所有对象,然后再按照加载的相同顺序激活它们。

  • 在 Unity 的 Playmaker 中设置断点有什么作用?

    -在 Unity 的 Playmaker 中设置断点可以在游戏运行到特定状态时暂停游戏,用于调试和检查游戏状态。

  • 在 DG Dino 的教程中,他提到了哪些可能导致游戏加载时出现问题的错误操作?

    -DG Dino 提到的错误操作包括先加载玩家对象再加载场景,然后尝试激活场景,这会导致游戏加载时出现问题。

  • 在 Playmaker 中,'Load Scene Async' 动作的 'Allow Scene Activation' 选项设置为 false 有什么作用?

    -在 Playmaker 中,'Load Scene Async' 动作的 'Allow Scene Activation' 选项设置为 false 可以防止场景在加载后立即激活,允许开发者在激活前进行其他操作。

  • DG Dino 在教程中提到了哪些调试技巧?

    -DG Dino 在教程中提到的调试技巧包括使用断点、触发事件以及检查游戏状态等。

  • 在 Unity 的场景加载中,为什么 DG Dino 推荐使用场景名称而不是场景索引?

    -DG Dino 推荐使用场景名称而不是场景索引,因为场景索引可能会因为构建设置中的不同位置而导致问题,而场景名称是唯一的,可以避免这种混淆。

  • 在 DG Dino 的教程中,他是如何实现场景之间的转换的?

    -在 DG Dino 的教程中,他通过 'Load Scene Async' 动作加载新场景,并在加载完成后激活新场景,同时设置 'Allow Scene Activation' 为 false 以控制激活时机。

  • DG Dino 在教程中提到了哪些关于场景激活和卸载的注意事项?

    -DG Dino 提到,在激活和卸载场景时,需要先激活所有加载的场景,然后再进行卸载,否则可能会导致游戏卡住。

  • 在 DG Dino 的教程中,他是如何使用全局事件来控制场景加载的?

    -DG Dino 在教程中使用了全局事件来控制场景加载,他通过设置全局事件监听器,使得在游戏的任何位置都可以触发场景加载。

  • DG Dino 在教程中提到了哪些关于 Playmaker 动作的优化技巧?

    -DG Dino 提到了使用名称而非索引来加载场景,以及使用全局事件和事件监听器来优化 Playmaker 动作的流程。

  • 在 DG Dino 的教程中,他是如何展示如何通过按钮来触发不同场景的加载的?

    -DG Dino 在教程中通过设置按钮事件,使用 Playmaker 的 FSM 发送事件来触发不同场景的加载。

Outlines

00:00

😀 Unity教程开场及感谢

DG Dino 来自 Jinx Games,感谢购买 Playmaker 资源包的用户,并请求评价。预告下一个游戏教程,将加入 Playmaker 资源包。教程制作因遇到问题而延迟,DG Dino 测试了 Playmaker 动作和 C# 脚本,发现问题并非动作本身所致,而是加载顺序错误。

05:01

🛠️ Unity调试技巧和加载顺序问题

介绍了如何在 Playmaker 中设置断点进行调试。演示了加载级别和玩家的顺序问题,正确的顺序是先加载级别再加载玩家,错误的顺序会导致游戏卡住。强调了加载和激活多个对象时,必须按照正确的顺序进行。

10:01

📚 Playmaker 异步加载场景教程

详细解释了如何使用 Playmaker 异步加载场景。包括设置场景名称、索引、加载模式为累加、禁止立即激活场景等。演示了如何通过设置变量和事件监听器来控制场景的加载和激活。

15:04

🔄 场景切换和事件监听器的使用

讨论了如何实现场景间的切换,包括设置文本窗口显示当前级别、比较当前级别与加载级别、使用事件监听器响应按钮点击等。强调了在进行场景切换时要考虑玩家的重力影响和激活顺序。

20:07

🎨 界面颜色设置和教程总结

介绍了如何根据场景加载状态设置界面颜色,以及如何使用全局事件和事件监听器简化 FSM 的触发。最后,DG Dino 总结了教程内容,并鼓励观众点赞、订阅频道、支持 Patreon、通过 PayPal 捐款或在 Asset Store 购买资产。

📢 教程结束和观众互动

DG Dino 预告了未来可能会有更多关于加载场景的教程,但在此之前他有其他事情要做。他感谢观众观看,并邀请他们点赞、订阅频道,并提供了 Patreon、PayPal 和 Asset Store 的链接,鼓励观众支持他的工作。

Mindmap

Keywords

💡PlayMaker

PlayMaker是一个Unity游戏引擎的插件,它允许开发者通过可视化的脚本系统来创建游戏逻辑,而无需编写代码。在视频中,DG Dino提到了使用PlayMaker来制作游戏,并且提到了他在Unity Asset Store上销售的PlayMaker样本。

💡Asset Store

Unity Asset Store是Unity官方提供的一个在线市场,开发者可以在这里购买或免费下载Unity插件、游戏资产、教程等资源。DG Dino在视频中感谢了购买他PlayMaker样本的用户,并请求他们对资产进行评分和评论。

💡Breakpoints

断点是编程和调试中使用的一种技术,它允许开发者暂停程序的执行,以便检查程序的状态或变量的值。在视频中,DG Dino介绍了如何在PlayMaker中设置断点,以便在特定状态暂停游戏,从而帮助调试。

💡Load Scene

在Unity中,加载场景(Load Scene)是指将一个新的游戏世界或环境加载到游戏中。DG Dino在视频中演示了如何使用PlayMaker来异步加载场景,这是Unity中一种不中断当前游戏流程的方式来加载新场景。

💡Async Additive

异步加载(Async Additive)是一种在Unity中加载场景的方式,它允许开发者在不中断游戏流程的情况下,后台加载新的场景。DG Dino在视频中详细讲解了如何使用PlayMaker来实现这一功能。

💡Scene Activation

场景激活(Scene Activation)是指在Unity中激活或使场景变为可交互状态的过程。视频中提到,如果加载了多个场景对象,需要按照正确的顺序激活它们,否则可能会导致程序卡住。

💡Event

在Unity和PlayMaker中,事件(Event)是一种消息,用于在游戏的不同部分之间传递信息或触发特定的行为。DG Dino在视频中提到了如何使用事件来控制游戏流程,例如加载和激活场景。

💡Global Transitions

全局转换(Global Transitions)是PlayMaker中的一个功能,允许开发者创建可以在任何时候触发的转换或事件。在视频中,DG Dino展示了如何使用全局转换来激活场景,无论玩家当前处于游戏的哪个部分。

💡Debugging

调试(Debugging)是软件开发过程中识别和修复错误的过程。DG Dino在视频中提到了在开发过程中遇到的一些问题,并展示了如何使用断点和事件监听来调试游戏。

💡Tutorial

教程(Tutorial)是一种教学材料或视频,旨在教授特定的技能或知识。DG Dino在视频中提供了一个关于如何使用PlayMaker和Unity进行场景加载的教程,并预告了下一个教程的内容。

Highlights

DG Dino 感谢购买 Playmaker 样本的用户,并请求评分和评论。

预告下一个教程将是完整的游戏,并将添加到 Playmaker 样本资产中。

教程中遇到了问题,最初以为是 Playmaker 动作的问题,后来发现 C# 脚本也有同样的问题。

介绍了如何设置和使用断点进行调试。

展示了如何加载和激活关卡以及玩家,以及如何通过断点调试。

解释了加载多个对象时激活顺序的重要性。

强调了在卸载场景前必须先激活所有加载的对象。

演示了如何使用 Playmaker 动作设置场景名称和索引。

讨论了使用场景名称而非索引加载场景的优势。

介绍了如何使用异步加载和激活场景。

展示了如何使用 Playmaker 动作激活和取消激活游戏对象。

讨论了在激活玩家场景时需要考虑的重力因素。

演示了如何使用事件监听器和按钮来改变关卡。

介绍了如何使用比较操作来判断当前关卡是否为最低级别。

展示了如何使用全局转换和事件监听器来激活关卡。

讨论了设置文本和背景颜色来反映当前关卡的方法。

讲解了如何使用字符串比较来检查和加载新关卡。

强调了在加载新场景前先激活当前场景的重要性。

介绍了如何使用发送事件来无需箭头连接地触发事件监听器。

教程最后,DG Dino 邀请观众点赞、订阅频道,并支持他的工作。

Transcripts

play00:00

hi I'm DG Dino from jinx games and this

play00:04

tutorial is about how to use loads seen

play00:07

async additive let's get started

play00:11

but first I would like to thank everyone

play00:13

who purchased my play maker samples on

play00:16

the asset store also I would like to ask

play00:19

if you could rate the asset and maybe

play00:21

give a review also I would like to show

play00:25

you a preview on my next tutorial and

play00:27

this is going to be a proper game and

play00:30

this will also be added to my play maker

play00:35

samples asset and now let's start with

play00:39

the tutorial it took a little bit longer

play00:44

than I expected to make this tutorial

play00:47

because I ran into some issues and at

play00:51

first I thought there were some issues

play00:52

with some of the actions I used so then

play00:55

I made the same sample in a c-sharp

play00:58

script and noticed that I had the same

play01:01

issues so then I decided to rebuild the

play01:05

sample and also show you what not to do

play01:08

now let's place some breakpoints and

play01:11

play this so you can see how this works

play01:13

you can right-click on a state and click

play01:18

this toggle breakpoint to set a

play01:21

breakpoint here and if you click it

play01:23

again it will disable this breakpoint

play01:26

again and you can see on a state here

play01:31

when a breakpoint is active you have

play01:33

this red rectangle here and place

play01:38

another one and what this does is when

play01:40

you play the game and it reaches this

play01:44

state the game will be paused and

play01:47

anything inside the state is not yet

play01:50

activated so everything before has been

play01:53

done and it stops here and then you can

play01:56

unpause and then you can continue and

play01:59

that's very useful for debugging let's

play02:03

play this

play02:06

so first I'm loading my level then I'm

play02:09

loading my player and then

play02:13

activating my level and then I am

play02:16

activating my player and then I can

play02:21

choose a different level I have only

play02:23

four now and just activated and as you

play02:27

can see I have a different level here

play02:29

and also different camera position so

play02:33

level four or level two and back to

play02:38

level one

play02:40

okay so let's go to the states now and

play02:46

first I will explain you the issue I had

play02:51

so this works fine but this side won't

play02:56

work and let me go first in here in here

play03:01

I just have a sent event so it goes

play03:03

automatically here for working so I'm

play03:08

gonna turn this off now on both and now

play03:14

I need to click this myself I can all

play03:17

click this or command-click I think but

play03:20

I can also do this in the inspector and

play03:24

how to get this in inspector is very

play03:27

simple you just select an event and just

play03:31

turn on inspector and now you can click

play03:35

on this to trigger so let's play this

play03:42

and I now go to not working and as you

play03:49

can see it just get stuck here and the

play03:54

reason for this is because I loaded the

play03:57

player then I loaded to level and then I

play04:01

wanted to activate the level and after

play04:05

that I wanted to activate the player so

play04:08

I first loaded the player and then level

play04:11

and then I wanted to activate the level

play04:13

and that is an issue so the way you

play04:17

should do this if you load multiple

play04:20

things before activating them you need

play04:24

to activate them in this

play04:26

same sequence so here I loaded first the

play04:30

level and then the player and an

play04:33

activate level and then player here I

play04:37

did I swapped these two so I loaded the

play04:42

player and then loaded the level and

play04:44

this gives issues that it gets stuck

play04:48

here and also in a c-sharp script it

play04:51

just gets stuck it doesn't give errors

play04:54

it just doesn't do anything so it's

play04:57

unity issue and nothing to do with these

play05:00

actions I will try to find if there is a

play05:04

solution for this that it will at least

play05:06

give a failure event but for now just be

play05:12

careful that you always use the right

play05:16

sequence now for unloading because I'm

play05:21

also unloading this other level so if I

play05:24

load a level I'm gonna unload the other

play05:26

level so the current level I have the

play05:30

issue with the allow scene activation

play05:35

here so when I want to unload and I have

play05:41

something loaded that isn't activated

play05:44

yet

play05:46

then I it gets stuck also and if i do

play05:53

first activation and then unload then

play05:56

it's fine so also if you have more

play05:59

things loaded you need to activate them

play06:02

all and then unload so be careful with

play06:07

that let's look now two old states so

play06:13

this one is just the same event so it

play06:15

would go automatically that's just for

play06:18

debugging and for the tutorial here so

play06:21

you can choose to turn it on or you can

play06:23

just use these two for working and not

play06:26

working but let me set this back to

play06:30

automatic then when I go here I have my

play06:35

set string value and I'm gonna set my

play06:39

I first seen so that's gonna be level

play06:43

one and here you can see it's the same

play06:45

scene name and then I have this current

play06:50

level in an int so I use this for the

play06:53

index I'll show you later on and then I

play06:58

have my load level and this is actually

play07:01

to reset it so it's it's on zero and

play07:07

then I have my load seen asic and my

play07:13

scene reference is seen by name and not

play07:15

at index and I prefer to do this by name

play07:20

because if I have in the build setting a

play07:24

different position here are the index

play07:27

numbers and you see level 1 is index 3

play07:31

so you might get issues with that and

play07:34

that's why I prefer to use names then my

play07:39

load scene mode is additive because I

play07:44

want to add this to this scene then I

play07:47

have allow scene activation set to false

play07:50

as I don't want it to activate

play07:53

immediately I want to load it first and

play07:57

do something and then I want to activate

play08:00

it later on okay so in the result I have

play08:06

this async operation hash and I cannot

play08:10

see what's the complete word here but

play08:14

anyway this is to save the index for

play08:18

this load scene so I can use this on

play08:22

activate action to know which scene that

play08:27

is so it's like an index number then I

play08:34

have done event and the done event is if

play08:37

you have your allow scene activation on

play08:40

else it will not finish so it will not

play08:44

be done so then you can use the pending

play08:49

activation event and I'm

play08:52

using this level loaded you can also use

play08:57

an error for the scene not found or

play08:59

something so but I'm sure it's there

play09:03

so I didn't use this now then let's go

play09:09

to the next state and we have the same

play09:12

load scene async and also seen by name

play09:16

load scene acing player that's my player

play09:20

here additive and everything is the same

play09:23

except I use different variable here for

play09:27

hash player and here I had a progress

play09:31

but it just worked so fast so doesn't

play09:35

really matter but you can use it if you

play09:37

want then I have began this pending and

play09:43

I'm going to the next one and here I

play09:48

have activate game object and I'm

play09:55

deactivating my camera my main camera

play09:58

because I have a camera here on my main

play10:01

and on all the scenes I also have

play10:03

cameras so I deactivate this first and

play10:07

then I activate the scene so this is my

play10:13

level scene that I'm activating as this

play10:16

is the index from the level that is

play10:19

stored on the hash level like it it see

play10:24

here somewhere yeah

play10:27

here the progress is also not needed and

play10:38

then I have this is done bull but I

play10:43

don't need it also here actually but I

play10:45

do have this done event and a failure

play10:47

event and when it's done it goes to the

play10:51

next one and then I'm just setting the

play10:56

color for this background and then I

play10:59

have to allow scene activation for the

play11:01

player and at this moment

play11:05

I have to do my scene first and then my

play11:08

player because my player has gravity and

play11:11

if my player would be placed first it

play11:16

might fall down so that are things that

play11:18

you have to think of when you use this

play11:20

and here I just have a listener and

play11:25

that's listening to my buttons here solo

play11:29

previous and alone next next scene is a

play11:45

button and you can connect this with

play11:49

dropping this in and then playmaker fsm

play11:54

send event and then put the name here

play11:59

for the event and as you can see here

play12:07

load previous and next then if I would

play12:14

press the previous I'm doing this in

play12:17

compare for the current level so here's

play12:20

my current level now and I'm gonna check

play12:23

if it's level one so if it's equal it

play12:27

say it is lowest level already and less

play12:32

than also just for a fail-safe so if

play12:35

it's equal or less then it should go

play12:38

back to the listener and do nothing

play12:40

because there is no lower level and if

play12:46

it's greater than I'm gonna load the

play12:48

lower level and I'm just doing in ad

play12:51

minus one on my current level and then I

play12:58

do this in two operator minus one here

play13:01

so actually I'm doing this ad minus one

play13:06

so actually deducting one and I'm gonna

play13:09

store this result in this load level

play13:12

variable and why I do this because of

play13:16

the array because an array starts with

play13:19

I mean zero and not with one and that's

play13:22

why I just deduct one for this level and

play13:27

it's easier like this so my level one is

play13:31

gonna be one and my level four is gonna

play13:34

be for and to get it from the array I

play13:37

just have this minus one so level four

play13:42

will be on element 3 so that's why I use

play13:51

this so I'm getting the string here for

play13:56

my load level scenes and show it here

play14:02

again here just text for the load level

play14:05

async level 1 2 3 4 and as you can see

play14:08

they are the same as here and then I'm

play14:14

gonna set this text here on this text

play14:18

window and then I'm gonna compare if my

play14:24

string so if my current level string is

play14:27

the same as the load level string so

play14:31

here I am saving this load level string

play14:34

here and here I've set this current

play14:38

level string and so so if it's the same

play14:46

if it's equal it's gonna send this same

play14:49

event and gonna go here if it's not

play14:52

equal then it's gonna set the background

play14:55

color to white and continue so let me

play15:00

show you here the same level and I'm

play15:03

just changing the color and going back

play15:07

to the listener and here I just have

play15:11

white and also back to the listener and

play15:15

that's just it to change the level in

play15:18

the check highest so I'm gonna look if

play15:21

the highest level is 4 if it's higher is

play15:24

equal or greater then it goes back to

play15:28

the listener and if it's lower it's

play15:30

gonna in add

play15:32

so that's just for the levels then if I

play15:37

press activate so you can see I have

play15:41

this set as a global so anytime I can

play15:44

press this activate and that's why I use

play15:48

Global's and you can just right click at

play15:50

global transitions and place them so

play15:57

that's a big advantage of Global's that

play16:00

you can send or trigger them anytime

play16:04

inside this episode so also I have this

play16:10

on a button here the same as I showed

play16:13

you before so I'm not gonna show it

play16:16

again now and here again this was just

play16:20

for debugging so for the working or not

play16:23

working I'm gonna set this on also again

play16:25

and then I have my string compare and

play16:30

I'm gonna compare the current level

play16:34

string to the load level string and if

play16:37

it's equal I have this event listener

play16:40

but I don't have it here

play16:42

but I do have it here as a global and

play16:47

this is again a nice thing here so if we

play16:50

have some global things here you can

play16:52

just set this listener or set this event

play16:57

and you don't need to wire it so like

play17:01

like this part

play17:03

I wanted to group it separately so it

play17:07

just looks nicer also like this then I

play17:10

have here another wire and here another

play17:13

wire so in performance it's the same so

play17:18

I like to do this especially if I'm

play17:23

grouping things together so but that's

play17:28

all up to you of course now so if it's

play17:32

equal it goes back to the listener here

play17:34

and then I can change levels again and

play17:36

if it's not equal I will have this done

play17:41

event and I'm gonna go here and

play17:45

gonna load this scene so the scene that

play17:49

I selected and I'm gonna store this hash

play17:53

level so that index again also additive

play17:58

progress we can't really see the next is

play18:02

my pending activation so the pool is

play18:04

also not really needed now and it's done

play18:07

also not it's just to show you that you

play18:10

can set these then done event is also

play18:15

empty because I have my allow scene

play18:18

activation turn off so I need to use

play18:21

this one to continue and then after I've

play18:28

loaded this and I did some stuff then I

play18:32

can activate that scene and then unload

play18:37

the currency so important is first to

play18:42

activate everything and then unload else

play18:44

you will get stuck once it's loaded I

play18:49

have my set string value here and I'm

play18:52

just gonna set this current level with

play18:56

this load level so load level is the new

play18:59

level that was loaded and it's gonna be

play19:01

set to the current level because that's

play19:04

the current active now and then I have

play19:08

just this current level string for the

play19:11

text to change this one here and then

play19:15

I'm setting this color to red as it

play19:20

would be the same as the current and a

play19:24

load so that's why I turned this back to

play19:28

red here and then I have a send event

play19:31

here because I didn't want to put this

play19:34

connection I could just do like this

play19:36

finished and in connect this but I

play19:40

wanted just to use use it without wire

play19:45

without an arrow and so I use the send

play19:50

event and the target itself so to this

play19:54

FSM here and then I'm just sending an

play19:57

event listener

play19:59

and I'm just sending this to this

play20:01

listener again so it will go back here

play20:06

and well that is about all for this

play20:13

tutorial and I'm probably gonna do some

play20:18

more load scene tutorials but first I

play20:26

have some other things to do so anyway

play20:28

thank you for watching if you liked the

play20:31

tutorial please like the video and don't

play20:33

forget to subscribe to my channel you

play20:36

can support my work by becoming a patron

play20:38

at patreon or donate me with PayPal or

play20:42

purchase my assets on the asset store

play20:45

you can find the links in the

play20:47

descriptions below

Rate This

5.0 / 5 (0 votes)

Related Tags
Unity开发Playmaker插件场景加载游戏教程DG DinoJinx Games调试技巧序列激活游戏制作资产商店
Do you need a summary in English?