เคลีย Grid อัตโนมัติ ก่อนหรือหลัง Grid ถูก Enable หรือ Disable by

28
Feb
0

บางครั้งเราก็จำเป็นที่จะต้อง ล้าง Grid ใหม่ทุกครั้งที่ Show หน้าที่มี Grid นี้ หรือ ล้างทุกครั้งที่เราละจาก Grid นี้ไป ไม่ว่าจะเหตุผลเรื่องของ Memory หรืออื่นๆก็ตาม วันนี้เรามีวีธีง่ายๆที่จะทำให้ชีวิตดีขึ้นมากก มาฝากครั้บบ

1. เราต้องแก้ไขไฟล์ UIGrid ของ NGUI ก่อนครับให้เราเพิ่ม code นี้ไปใน UIGrid ครับ
public bool clearGridOnEnable = false;
public bool clearGridOnDisable = false;

void OnEnable() {
if (clearGridOnEnable)
{
Utils.ClearGrid(this, false);
}
}

void OnDisable() {
if (clearGridOnDisable)
{
Utils.ClearGrid(this, false);
}
}

2. ถ้าทำแค่นี้ ก็ยังไม่ทำให้ชีวิตเราง่ายขึ้นเท่าไหร่ครับ เพราะว่ามันจะไม่มี clearGridOnEnable หรือ clearGridOnDisable ขึ้นมาใน Inspector ให้เราตั้งค่าครับ ก็ให้เราเพิ่ม code นี้ในไฟล์ UIGridEditor ครับ
NGUIEditorTools.DrawProperty(“Clear on Enable”, serializedObject, “clearGridOnEnable”);
NGUIEditorTools.DrawProperty(“Clear on Disable”, serializedObject, “clearGridOnDisable”);

ให้เราเพิ่ม code ไปก่อนบรรทัดนี้นะครับ
serializedObject.ApplyModifiedProperties();

3. ต่อไปจากนี้ เราก็จะมี การตั้งค่าใน Inspector เพิ่มมาให้เราตั้งค่าครับ หน้าตาแบบนี้ครับ

Enjoy this article?

Consider subscribing to our RSS feed!

Filed under: Uncategorized

No Comments

No comments yet.

Leave a comment

RSS feed for comments on this post

 เราชนะรอบ 4 | ยืมเงิน 3000 ด่วน | แอพกู้เงิน | แอพเงินด่วน | สินเชื่อออนไลน์อนุมัติทันที | Site Map | กู้เงินก้อน | กระเป๋าตัง | thisshop และ ยืมเงินฉุกเฉิน 5000 ด่วน