loading...
آموزش کامل نقشه کشی اتوکد مدلسازی سه بعدی به زبان فارسی
3d Rener بازدید : 119 چهارشنبه 15 آذر 1396 نظرات (0)

آموزش تصویری یونیتی Unity 5 2D Window Add navigation to the keyboard

دانلود آموزش تصویری یونیتی به زبان فارسی Unity

 

 

دانلود آموزش تصویری یونیتی بنابراین اکنون آماده هستیم تا هر یک از دکمه های موجود در صفحه کلید ما را خاموش کنیم. قبل از اینکه ما این کار را انجام دهیم، باید کد دیگری را به KeyboardWindow اضافه کنیم. بیایید به پوشه ویندوز ما برویم و کلاس KeyboardWindow را انتخاب کنیم. بعد، اجازه دهید یک روش جدید اضافه کنیم که عمومی OnKeyPress نامعتبر است و برای این منظور رشته ای به نام key را خواهیم پذیرفت. هر بار که ما یک کلید را فشار می دهیم، ما آزمایش می کنیم تا اطمینان حاصل کنیم که طول متن کمتر از حداکثر کاراکتر است. در صورتی که هستیم، رشته کلیدی را که به روش OnKeyPress منتقل شده به قسمت متن ما اضافه می کنیم. ما این را با گفتن _text + = key انجام خواهیم داد. اکنون ما روش اضافه کردن متن به KeyboardWindow ما را داریم. بیایید دوباره به Unity برویم و تمام دکمه های ما را به هم وصل کنیم. برای اینکه این روند را کمی آسانتر کنیم، تمام دکمههای ردیفی که قبلا باز شدهاند، وجود دارد. بیایید هر کدام از این دکمه ها را انتخاب کنیم، به پایین به عمل دکمه برویم و بر روی + کلیک کنید، آن را به KeyboardWindow تنظیم کنید، و حالا ما را به کلاس KeyboardWindow بروید و OnKeyPress را انتخاب کنید. در حال حاضر، من فقط میخواهم q را به ارزش اضافه کنم. متوجه خواهید شد که Handler رویداد On Click به طور خودکار تشخیص می دهد که OnKeyPress ما یک رشته را می پذیرد و به ما یک فیلد ورودی می دهد. هر کدام از این دکمهها اکنون برای q ارزش دارند. بنابراین من قصد دارم به سرعت واقعی بروید و آنها را به مقادیر درست تنظیم کنید. هنگامی که شما برای یک ردیف انجام داده اید، پیش بروید و برای ردیف های دو و سه همین کار را انجام دهید. اکنون که کلیه کلیدهای ما مرتبط هستند، اجازه دهید بازی را اجرا کنیم و نگاهی به صفحهکلید ما ببریم. باز هم، ما این را به مدیر پنجره متصل نکنیم، بنابراین، KeyboardWindow را از سلسله مراتب انتخاب کنید و آن را قابل مشاهده کنید. اگر ما وارد می کنیم، باید بتوانیم مقادیر صفحه کلید را ببینیم. هنگامی که به حداکثر تعداد کاراکترها رسیدید، خواهید دید که مکان نما ناپدید شده است و شما دیگر نمیتوانید در هر متن دیگری اضافه کنید. بیایید این را متوقف کنیم و شروع به افزودن در منطق کنیم تا هرکدام از کلیدهای ما را با هم مرتبط کنیم اگر از یک کنترلر استفاده می کنید. بگذارید ردیف اول را باز کنید و نگاهی به دکمه q بیاندازید.

As you can see the navigation is set to Explicit. Let's check the Visualize button in order for us to see this as we connect it up. One thing you'll notice is that you'll still be able to see the visualization for the other windows that are behind the KeyboardWindow. So let's just ignore them for now. With q selected, let's set the w to the right value, and if we open up row two, let's set a to the down value. If we go to w, we're gonna set q to the left, e to the right, and s to the down. I'm gonna go ahead and do this up until t and then we'll talk about how we start moving up and down based on the fact that each row has a different number of buttons. So now that I've set up the left and right values for t, let's take a look at our keyboard and figure out where we want it to move down. As you can see, the t and the y both sit on top of the g, so we're gonna make both of them go to the g if you hit down from either key. As we continue through y, u, i, o, and p we'll move them to the closest key below. If we were to set this navigation to auto, we wouldn't guarantee that Unity would know which key to go to based on the direction you're pressing. While this is a lot of work to set up now, it'll ensure that we have the user go to the right key that they're expecting as they move around with a controller or the keyboard. Let's continue to set up the rest of the keys on the first row. Now we've finished the first row and as you can see each of our keys will move across to each other, q to w, and p will move to o, this way there's no wrapping, you can easily set up wrapping if you want by putting q in the right position of p, and p in the left position of q, if you want the keyboard to wrap around. Now we need to wire up the second row. The one place to note is that since g sits directly below t and y, there's gonna be no easy way for us to actually make it move up to the right key, so we'll simply pick t as a basis. The same thing about a and l, as we move down there's no key below them so we'll move them to the nearest key below, so for a we'll connect it to z, and for l we'll connect it to m. I'm gonna go ahead and wire up all the keys so you can see how they'll work. Here for s, I'm also gonna make it connect to z when you move down. So now our a and our s key will automatically go to z as you move the keyboard down. Since d sits directly above x, we'll set x to the down position and e to the up position. Here at g, we'll set t to the up position. and at h, we'll set u to the up position. This means that y is only accessible by moving up from g to t, and then over to the right to y, or from h to u and moving over to the left from u. Now depending on the type of keyboard or how much time you want to put into it, a lot of virtual keyboards will remember where you come from, so if you came from a t or a y down to a g and then went back up, it would check the previous key that it came from and go back to that key. For this course, we're gonna try to keep it simple and just know there's one limitation is that since g sits between both of these keys, we just had to choose which one to go to arbitrarily. And again for l, let's make this key go down to m. So now we've completed connecting up our second row of keys, all that's left is our final row. This one should be pretty straightforward, we'll simply connect all of the bottom row to each other, and then go directly up to the keys that are above them. In this case, z will only go to s and if you want to get to a, you'll have to go the left, and for m you can go up to k and go over to l. Now we have our entire keyboard wired up. Let's give it a quick test to see that it works. We'll run our game, make our KeyboardWindow visible, and simply click within one of the buttons to give it focus. At this point, you should be able to now go through and navigate your keyboard. Make sure that everything is connected as you expect it. Once you're done testing, your keyboard is ready to use.

تعداد صفحات : 136

اطلاعات کاربری