All language subtitles for 012 The Model-View-Controller Family_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian Download
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:04,670 --> 00:00:11,930 So I have updated the UI here so that we still have a health drain going on here, but now to gain our 2 00:00:11,930 --> 00:00:13,580 experience, we have to hit this button. 3 00:00:13,580 --> 00:00:18,710 We gain experience points until we get to the point where we level up, still get our particle effect 4 00:00:18,710 --> 00:00:21,340 like before and the health bar still replenishes. 5 00:00:21,350 --> 00:00:26,240 But the difference is now we have to do this by the UI and instead of having a display happen in the 6 00:00:26,240 --> 00:00:29,420 console, we've got it happening via our nice UI here. 7 00:00:29,960 --> 00:00:34,520 So let's just have a look at what's changed in the code in order for this to happen. 8 00:00:34,820 --> 00:00:39,770 So if we go and have a look, first of all at the health component, this is the simplest. 9 00:00:40,070 --> 00:00:45,950 What we've done here is we've simply added a serialized field reference to an image component. 10 00:00:46,310 --> 00:00:47,690 That image component is over here. 11 00:00:47,690 --> 00:00:50,510 In the canvas view, you can see there's the bar. 12 00:00:50,510 --> 00:00:51,490 That's what it points to. 13 00:00:51,530 --> 00:00:55,730 So if I have a look at the observer example, you can see it points to this bar image. 14 00:00:56,060 --> 00:00:59,350 And what it does is on the change. 15 00:00:59,360 --> 00:01:05,540 A resetting of the health or the updating of the health that caused the update UI and Update UI simply 16 00:01:05,540 --> 00:01:08,240 enters the fill amount of this image. 17 00:01:08,240 --> 00:01:14,360 So the fill amount being this little slider here that allows us to fill that image from the left and 18 00:01:14,360 --> 00:01:15,470 gives us health bar. 19 00:01:15,890 --> 00:01:20,150 So the same principle is in operation over on the level. 20 00:01:20,150 --> 00:01:25,640 We've got ourselves to theorize fields here, the display text for the level, the experience, text 21 00:01:25,640 --> 00:01:29,810 for the level, and we have also got a reference to a button. 22 00:01:30,230 --> 00:01:36,080 So what happens is we again have this update UI called on starts and called Omega an experience which 23 00:01:36,080 --> 00:01:41,990 sets the text for these two pieces of UI, getting the level and getting the experience. 24 00:01:42,680 --> 00:01:48,500 And we have an increase exp button, which when you click it essentially just calls gain experience 25 00:01:48,500 --> 00:01:49,760 with 10 experience points. 26 00:01:50,060 --> 00:01:52,550 So every time you click it, we gain 10 experience points. 27 00:01:53,120 --> 00:01:56,810 Now, hopefully you can see that as a bit of a problem arising here. 28 00:01:56,810 --> 00:02:05,000 They all this UI logic added to our level mono behavior is adding complexity, and it's also making 29 00:02:05,000 --> 00:02:07,430 it a little bit harder for linking things up. 30 00:02:07,430 --> 00:02:08,960 There's more stuff that could go wrong. 31 00:02:08,960 --> 00:02:14,270 The Observe, for example, you can see we've got links that go from somewhere, some sort of gameplay 32 00:02:14,270 --> 00:02:15,980 object all the way into the UI. 33 00:02:15,980 --> 00:02:22,130 And that link you might forget to put in some places and stuff would break, and then there's more reasons 34 00:02:22,400 --> 00:02:24,380 to need to change these classes. 35 00:02:24,380 --> 00:02:31,130 So it's basically in violation of the one class deals with one thing rule. 36 00:02:31,280 --> 00:02:38,600 Because here we're dealing with the game rules of the level we are dealing with handling inputs and 37 00:02:38,600 --> 00:02:40,280 converting that into game rules. 38 00:02:40,280 --> 00:02:47,270 We are dealing with formatting of text for the UI and linking it to the UI in general. 39 00:02:47,270 --> 00:02:49,820 And then unity is dealing with the rendering. 40 00:02:49,820 --> 00:02:54,970 So we're kind of triggering all the rendering and calling into the event system that E.A. is using. 41 00:02:54,980 --> 00:02:59,000 So how do we typically solve this kind of UI conundrum? 42 00:02:59,270 --> 00:03:05,720 Well, MVC is the traditional solution here, so you can see that we break this up into a model view 43 00:03:05,720 --> 00:03:06,470 and controller. 44 00:03:06,470 --> 00:03:10,370 And the fundamental idea is that the model would deal with game rules. 45 00:03:10,610 --> 00:03:14,000 The view deal with rendering and the controller deals with input. 46 00:03:14,240 --> 00:03:16,160 So how does this look in principle? 47 00:03:16,460 --> 00:03:20,540 The View would initially get its data from the model. 48 00:03:20,870 --> 00:03:27,710 It would render that data using probably the Unity UI system in our case, and the user or the player 49 00:03:27,710 --> 00:03:30,530 will see that data in the uniform. 50 00:03:30,950 --> 00:03:33,530 Then the user interacts with the UI. 51 00:03:33,560 --> 00:03:40,310 The controller processes that interaction, and it will update the model on the basis of that interaction. 52 00:03:40,730 --> 00:03:47,450 Now we use the observer pattern between the view and model for the view to observe changes on the model. 53 00:03:47,450 --> 00:03:52,700 And so any on change event will get broadcast to the View without the model having to know that the 54 00:03:52,700 --> 00:03:53,720 view even exists. 55 00:03:54,260 --> 00:03:59,540 So any own change will trigger the view to update itself and render the new information so that instantaneously 56 00:03:59,810 --> 00:04:04,970 the user provides input and sees the results all filtered through the game logic. 57 00:04:05,000 --> 00:04:07,700 So how do the responsibilities break down here? 58 00:04:08,030 --> 00:04:12,020 The model only handles game logic, often called business logic. 59 00:04:12,020 --> 00:04:15,530 When you're dealing with business systems here, it's more game logic related. 60 00:04:15,530 --> 00:04:19,790 So things like how many experience points does it take to level up? 61 00:04:19,790 --> 00:04:21,320 That is the game logic. 62 00:04:21,980 --> 00:04:27,950 The View deals with formatting, which we've seen with those text formatting pieces of code in there, 63 00:04:27,950 --> 00:04:34,040 or perhaps translating a numerical value to a value on a slider that is formatting logic. 64 00:04:34,490 --> 00:04:37,520 It also handles traditionally handles rendering. 65 00:04:37,520 --> 00:04:39,530 Now we didn't see that in our code. 66 00:04:39,560 --> 00:04:42,800 Rendering is mostly handled by unity directly. 67 00:04:43,130 --> 00:04:47,660 And we just trigger that by manipulating stuff in the hierarchy. 68 00:04:48,350 --> 00:04:50,540 Now, the controller deals with processing the input. 69 00:04:50,540 --> 00:04:55,790 We saw that with our input binding, it also deals with events and handling those events. 70 00:04:55,790 --> 00:04:57,290 Again, that's handled by unity. 71 00:04:57,530 --> 00:05:01,820 But we just listen in on the hierarchy to get our input. 72 00:05:02,300 --> 00:05:03,710 So this is traditional MVC. 73 00:05:03,890 --> 00:05:08,960 Already, you can see that I was saying some things on here are handled by unity and some things are 74 00:05:08,960 --> 00:05:18,020 handled by our own classes, and typically we can't really have this view do anything clever if it is 75 00:05:18,020 --> 00:05:20,420 just that unity side of things. 76 00:05:20,750 --> 00:05:25,150 So what we often see is an evolution of the traditional embassy. 77 00:05:25,430 --> 00:05:29,150 We see this also for web development, where the view is basically HTML. 78 00:05:29,420 --> 00:05:32,510 And so we don't can't do very much to manipulate the view. 79 00:05:32,810 --> 00:05:37,250 You see a different sort of breakdown called the model view presenter. 80 00:05:37,280 --> 00:05:38,360 And the idea is the same. 81 00:05:38,360 --> 00:05:42,530 Let's try and break up that logic a little bit between the model, the model we don't want. 82 00:05:42,620 --> 00:05:45,230 We don't want the model to depend on anything and just as game logic. 83 00:05:45,590 --> 00:05:48,110 So in this situation, what happens? 84 00:05:48,440 --> 00:05:55,700 The presenter will go and grab the data it needs from the model and it will update the view. 85 00:05:55,700 --> 00:05:59,930 So the view becomes passive in this model, it doesn't go and listen to the model directly. 86 00:06:00,200 --> 00:06:02,750 The presenter is responsible for updating it. 87 00:06:02,900 --> 00:06:06,050 Then the view will be seen by the user. 88 00:06:06,080 --> 00:06:08,220 The user gives some input. 89 00:06:08,240 --> 00:06:09,770 Often again to the view. 90 00:06:09,770 --> 00:06:14,120 So the view is now handling input as well as what we see. 91 00:06:14,120 --> 00:06:19,880 And that seems to match a little bit better with how things work in unity, because the view in this 92 00:06:19,880 --> 00:06:23,050 case could be literally this canvas view. 93 00:06:23,150 --> 00:06:28,430 We can see that there's buttons here that would take the input from the user, but also simultaneously, 94 00:06:28,430 --> 00:06:31,650 we're able to render the stuff in the view as well. 95 00:06:31,670 --> 00:06:35,120 So, OK, this seems like a better match already than what happens. 96 00:06:35,120 --> 00:06:39,170 We've got input come into the view now via bindings in the presenter. 97 00:06:39,260 --> 00:06:44,450 We would get events coming through and then the presenter would update the model. 98 00:06:44,900 --> 00:06:51,110 So the nice thing about a model view presenter is that now we've still got a oh yeah. 99 00:06:51,140 --> 00:06:56,300 Also, we register for changes on the model just like we did before, so that the model doesn't need 100 00:06:56,300 --> 00:07:01,280 to know anything about the presenters, and you could have multiple presenters hanging off of the same 101 00:07:01,280 --> 00:07:01,760 model. 102 00:07:02,390 --> 00:07:08,450 So the model still just responsible for game logic, it doesn't need to know anything about your UI. 103 00:07:08,750 --> 00:07:11,930 It just needs to expose the data that it knows about. 104 00:07:12,590 --> 00:07:16,940 The presenter now becomes responsible for input processing and formatting. 105 00:07:16,940 --> 00:07:23,150 The two things that in unity we are doing in our shop code and the view layer now becomes responsible 106 00:07:23,150 --> 00:07:29,780 for rendering an events, which is what unity is already doing for us in its UI canvas. 107 00:07:30,170 --> 00:07:36,530 So this is a much better breakdown that fits with the unity way of things, and that's what we're going 108 00:07:36,530 --> 00:07:39,140 to be trying to implement in the next lecture. 109 00:07:39,560 --> 00:07:47,990 But before we go on to actually put this into practice, I wanted to talk about another variation of 110 00:07:48,020 --> 00:07:55,340 model view controller called the Model View View model, often abbreviated to M.V. Am and you may have 111 00:07:55,340 --> 00:07:56,930 heard of this one will come across in. 112 00:07:56,930 --> 00:08:00,430 Pascal just wanted to clarify what that is here. 113 00:08:00,440 --> 00:08:07,490 What we get is the model view model is acting very much like the presenter in our MVP model. 114 00:08:07,730 --> 00:08:15,200 So here, the view model will get data from the model and then via a process of external data. 115 00:08:15,200 --> 00:08:23,240 Binding properties on the view model will be bound to properties in the view and automatically when 116 00:08:23,270 --> 00:08:24,860 a property changes in the View model. 117 00:08:24,860 --> 00:08:28,610 It will get updated in the view and this is the fundamental difference. 118 00:08:28,820 --> 00:08:30,470 Everything else is mostly the same. 119 00:08:30,470 --> 00:08:37,010 The View model still updates the model based on an on change events and so on and so forth, or vice 120 00:08:37,010 --> 00:08:38,000 versa as well. 121 00:08:38,000 --> 00:08:43,190 Actually mean, but the crucial bit about the difference between the presenter and the View model is 122 00:08:43,190 --> 00:08:49,790 this little magic binding layer, which if you have to use certain frameworks in order for this to happen. 123 00:08:49,820 --> 00:08:54,740 But this essentially means that the View model knows nothing about the View, and The View knows nothing 124 00:08:54,740 --> 00:08:56,690 about the View model, which is kind of nice. 125 00:08:56,870 --> 00:09:04,130 So to summarise, what we have seen is MVC, where we have the model game logic separated out from the 126 00:09:04,220 --> 00:09:07,970 view logic and the inputs logic handling in the controller. 127 00:09:08,510 --> 00:09:15,860 Then we see the evolution of that, where the presenter does handle both the view logic and the input 128 00:09:15,860 --> 00:09:16,250 logic. 129 00:09:16,610 --> 00:09:21,800 But the view becomes more passive and only deals with rendering and event management. 130 00:09:22,310 --> 00:09:26,930 And then we have the NVMe model, which is very similar to the MVP model. 131 00:09:26,930 --> 00:09:32,900 With this extra magic of binding between the View and the View model, which allows us to have neither 132 00:09:32,900 --> 00:09:35,240 of them depend on each other directly. 133 00:09:35,480 --> 00:09:36,080 Great stuff. 134 00:09:36,080 --> 00:09:44,120 I will see you in the next video where we will be putting this into practice to make this UI work a 135 00:09:44,120 --> 00:09:44,780 lot nicer. 14312

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.