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

 بازی سازی یونیتی Add Difficulty Window Unity Save difficulty selection

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

 

 بنابراین اکنون که ما قادر به گرفتن ورودی صفحه کلید هستیم، می توانیم این ورودی را به داخل گروه تغییر دهیم تا کار UI را انجام دهیم. برای انجام این کار، ما نیاز به بازگشایی کلاس DifficultyWindow خود داریم. در بالای کلاس ما، ما میخواهیم یک فضای نام جدید را وارد کنیم. با استفاده از System.Linq تایپ کنید. Linq یک کتابخانه قدرتمند است که به ما امکان می دهد که در لیست ها به پرسش ها پاسخ دهیم. همچنین استفاده از آن خطرناک است زیرا همیشه 100٪ در تلفن همراه کار نمی کند. ما قصد داریم از یک تماس خاص استفاده کنیم که باید در هر پلتفرم کار کند. یکی از مسائلی که ما داریم این است که گروه جابجایی یک راه ساده برای دیدن مواردی که در حال حاضر انتخاب شده نیستند. بنابراین ما قصد داریم از Linq برای کمک به ما استفاده کنیم. در پایین که در آن مقدار را در setter ما قرار می دهیم، بیایید پیش برویم و یک متغیر جدید برای انتخاب فعلی ایجاد کنیم. ما قصد داریم این روش را به روش ActiveToggles GroupGroup تنظیم کنیم. این همه مواردی را که به طور فعال تعویض شده اند را باز می گرداند. از اینجا، ما قصد داریم از Linq برای پیدا کردن اولین و یا مورد پیش فرض استفاده کنیم. حالا که ما یک مورد داریم، از آنجایی که ما قصد داریم اطمینان حاصل کنیم که گروه جابجایی ما فقط می تواند یک مورد را در هر زمان خاص انتخاب کند، ما قصد داریم پیش برویم و مطمئن شویم که این انتخاب صفر نیست. اگر CurrentSelection برابر صفر نباشد، اکنون گزینه فعلی را مشخص می کنیم که isOn آن را به false تنظیم می کند. این گزینه انتخاب شده در حال حاضر انتخاب شده را غیرفعال کرده و به ما اجازه می دهد که یکی را انتخاب کنیم که ما می خواهیم. بعد، ما قصد داریم گزینه فعلی را به ID فرزند داخل تبدیل دشوار گروه بازنشانی کنیم. ما با دسترسی به gameObject.transform difficultyGroup و تماس GetChild شروع خواهیم کرد. ما در ارزش گذر می کنیم و سپس ما می خواهیم جزء آن را بدست آوریم و ما می خواهیم یک جزء تعویض را جستجو کنیم. هنگامی که ما این را بدست آورده اید، خواهیم تماس CurrentSelection را انجام دهیم و این را به درستی تنظیم کنیم. در مرحله بعد، ما قصد داریم چند مورد را انجام دهیم تا مطمئن شویم که همیشه ارزش درستی را به دست می آوریم. در بالا، جایی که ما صفر را بازگردانیم، اجازه دهید یک متغیر جدید برای کل ایجاد کنیم که تعداد کودکان داخل گروه دشواری را نشان می دهد. بعد، ما از طریق هر یک از بچه ها به حلقه می رویم و یکی از آن ها را تغییر می دهیم. ما حلقه ای برای ما ایجاد می کنیم که برابر صفر است. من کمتر از کل خواهد بود و ما به وسیله ی یک افزایش می دهیم.

Now let's create a variable for each toggle inside of the difficultyGroup. Here, we'll go to the difficultyGroup, select its transform, get the child at i, and then get the toggle component on it. Here we'll search for the toggle component. Now we'll test for the first toggle that we find that has isOn set to true. We'll return i and exit out of the loop. If we don't find any, we'll simply return zero. Now this is a convoluted way of doing it, but what I wanted to show you is that toggle groups and the toggles inside of them are just game objects, and that you can go through and manipulate them outside of the toggle group itself just like you would any other game object looking for a component. Now that we've set this up, let's go ahead and tell the window that it needs to set the difficulty when we open it up. We'll create a method right below this getter that overrides our open method. Before we call base.Open, let's set the difficulty to a value. Now you may want to save this difficulty from screen to screen. So in this case, we're going to save this in the PlayerPrefs. Here, we'll get an int. Our int will be called difficulty. And our default value will be zero. So the first time we open the window, if we don't have a difficulty, we're going to set it to zero. Next, when we call OnSelect and we go to the next window, we're going to save this back to the PlayerPrefs. Here, we'll call the PlayerPrefs, SetInt, and we'll pass in the key, Difficulty, and the property, difficulty itself. Now as the player goes through and picks their difficulty, it will save it for the next time they come back to the window. Let's save our script and go back into Unity. Now if we run the game and go to our new game, we can now move left and right across each of the items. If we select one and go to the next screen, go Next, hit Accept, go all the way back, you'll see that medium has been saved as my last selection. You can continue to add player prefs to save parts of your UI if you want them to have persistent across different gameplays. And now that we've finished the difficulty window, you now have several key windows that you can use in your own future games.

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

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