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

 آموزش یونیتی Unity 5 2D Extend Window System Generate window enum

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

در این آموزش یونیتی فوق العاده قدرتمند هستند. اما سیستم ما هنوز کمی شکننده است. اگر ما پیش برویم و سفارش پنجره ها را در پنجره مدیریت تغییر دهیم، enums های ما دیگر مطابق با جایی که در ابتدا قرار داشتند، نخواهد بود. برای حل این مشکل، ما قصد داریم یک دکمه اضافه کنیم که در واقع کد enum را برای ما تولید می کند. بیایید به ویرایشگرمان برویم و مدیر ویرایشگر پنجره را باز کنیم. در حال حاضر، این کمی پیچیده است، اما من دوست دارم از ابزارهایی مثل این برای استفاده از کد خود استفاده کنم، بنابراین من همیشه مجبور نیستم این کار را با دست انجام دهم. بنابراین هنگامی که ما از طریق تنظیم همه چیزهایی که ما نیاز به تولید کلاس enum C # داریم، ما نباید مجبور باشیم مجددا این کار را مجددا انجام دهیم و همه آنها براساس دستور فهرست از ویرایشگر ما خودکار می شوند. برای شروع، ما باید دو فضای نام را وارد کنیم. بیایید با استفاده از System.IO تایپ کنیم تا بتوانیم به سیستم فایل بنویسیم. و بیایید با استفاده از System.Text را به طوری که ما می توانیم با متن برای تولید از کد که در فایل ما می سازند کار می کنند. حالا در انتهای OnInspectorGUI، یک دکمه سفارشی ایجاد کنیم. ما این دکمه را در شرایطی قرار می دهیم تا تست آن را کلیک کنیم. بیایید به GUILayout برویم و با روش دکمه تماس برقرار کنیم. ما دکمه یک برچسب به نام Generate Window Enums می دهیم. در حال حاضر، در داخل این دکمه، ما میخواهیم تمام پنجرههای بر اساس آرایه را از مدیر پنجره بگیریم. بنابراین اجازه دهید یک متغیر جدید ایجاد کنیم که به نام windows است، و در اینجا ما قصد داریم یک اشاره به هدف، که یک ملک است که متعلق به ویرایشگر است. تنها مسئله این است که هدف هدف مشترک است. بنابراین ما باید آن را به عنوان مدیر پنجره خود مجددا اجرا کنیم. بنابراین اجازه دهید ریخته گری کنیم. 

 Inside of our double parentheses, we're going to add the WindowManager, and then, inside the last parenthesis, we're going to add the target property. Now, we can get a reference to the windows array. Sometimes this isn't a smart move to make, because you don't know what type the target is going to be. But since this editor is directly linked to a window manager, we can be sure that the target will always be a window manager. Next, we're going to want to get the total of the number of windows in the array. Let's just create a variable called total and set it to the window array's length. Now, we're going to want to create a new class called a string builder. A string builder is the easiest way to work with text inside of C# without causing a lot of memory leaks. We'll create a new variable called sb, and we'll set it to a new StringBuilder. Our first line of text is going to need to be the declaration for the enum. So let's do sb.Append and pass in the following string public_enum Windows{ All we're going to do is go piece by piece and reconstruct the class that we created by hand in the previous video, but instead we'll use the string builder to dynamically generate it. The next line is going to be sb.Append, and in here, we want to add the first item of the enum. Which is going to be None with a comma. Now we can create a four-loop to go through each of the windows and get their name. Here we'll make i = 0, we'll test that i is less than the total, and we'll increment i by 1 over each loop. Inside of the loop, we're going to append the name of each of the windows. We'll start by looking at the window array, getting the current index, then get the name of the element.

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

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