ویرگول
ورودثبت نام
soheil moonesi
soheil moonesi
خواندن ۳ دقیقه·۶ ماه پیش

Unity Engine Objects

UnityEngine.Object

خوب بالاترین قسمت سلسله مراتب آبجکت ها در یونیتی میرسه به؟ به unityEngine.Object

name string

int GetInstanceID() method

bunch of equality comparers

The class also provides a static void Destroy(Object obj) method (and some overloads) that destroys a UnityEngine.Object and any of its subclasses.

زمانی که object رو از بین میبریم. قسمت native اون از مموری آزاد میشه و قسمت مدیریتیش هم بعد از یه مدتی توسط garbage collector جمع آوری میشه و حذف میشه و دیگه هیچ رفرنسی دیگه به اون آبجکت باقی نمیماند.

میگه که اگر رفرنسی موجود باشه ما میتونیم با استفاده از unityEngine.Object به native object که از بین رفته دسترسی پیدا کنیم ولی unityEngine.Object میاد عملگرهای == و =! رو override میکنه و آبجکت حذف شده رو به صورت null نشون میده. اگر بخوایم از متد ها برای دسترسی به این آبجکت ها استفاده کنیم بهمون nullReferenceException رو میده.

GameObject

خوب میگه که GameObject مشتق شده از Object هستش که نشون دهنده ی هر المانی در صفحه هستش.

خوب GameObject میان name و instance ID از پدرشون به ارث میبرن.

has a list of Components on it,

has a tag string for organizational purposes, and

belongs to a layer.

A GameObject’s state

  • is the product of all of its Components’ state, and
  • whether an object is active or not.

حالا میخوایم عمیق تر موضوع رو بررسی کنیم، خوب همونطوری که میدونید gameObject ها حداقل یک component دارن که transform هستش که نمایانگر مختصات اون GameObject هستش

object absolute world position and rotation

و همچنین موقعیت اون به نسبت پدرش رو هم داره .

خوب توی editor چون این قضیه خیلی مورد استفاده است transform رو به صورت یه پراپرتی public گذاشتن.

حالا برای دسترسی به component هایی دیگه میتونیم از

T GetComponent<T>()

T[ ]GetComponents<T>()

استفاده کنیم. خوب حالا وقتی که این ها رو نوشتیم میاد و میره توی کل component ها سرچ میکنه و اونی که ما میخوایم رو برامون میاره به همین دلیل میگن که این فرآیند lookup کردنه رو بهتره که برای سرعت بیشتر cache اش کنیم.

اگر خودمون بخوایم build/extend کنیم یه gameObject رو میتونیم از

AddComponent<T>()

استفاده کنیم.

Individual Objects (a Component or ScriptableObject) might refer to other GameObjects in a few ways:

آبجکت ها میتونن به gameObject ها به طریق های مختلفی وصل بشن یا اشاره کنن.

By reference. By exposing a GameObject serialized field that you then set from the inspector.

Using tags. Every Game Object can have a tag string. You can find objects in the scene using that tag through the static functions GameObject.FindGameObjectsWithTag. A GameObject also exposes a public bool CompareTag(string tag) method.

اولی با رفرنسه - که میشه همون با استفاده کردن از serialized filed ها میشه

راه دوم میشه استفاده کردن از Tag ها هستش

This is a quick-and-dirty way to get the job done, but is still a popular way. A common use of this in the wild is to have a "Player" tag to find the Player. Ideally, these methods should not be called every frame, so if you have to use them, consider caching the result.

Using layers. A layer is an int between 0 and 31. Every Game Object is in exactly one layer.

استفاده کردن از Layer ها : یک لایه میشه یک int از 0 تا 31 . هر game object یک لایه است

خوب از این جا به بعد مقاله رو بعدا ترجمه میکنم و میزارم و تا اون موقع همین رو میزارم ویرگول

لینک مطلب


game objectlt gtevery gameobject بین
C# enthusiast
شاید از این پست‌ها خوشتان بیاید