สร้างโลกของคุณเอง
เศรษฐกิจ
ค้นหาข้อมูลเกี่ยวกับสิ่งของที่ผู้ใช้เป็นเจ้าของ
8นาที
คุณสามารถใช้ zepeto module shop api เพื่อดึงข้อมูลรายการของผู้ใช้ที่เชื่อมต่ออยู่ในปัจจุบันตามหมวดหมู่ได้ ติดตั้ง window → package manager → กรุณาติดตั้ง zepeto world package เวอร์ชัน 1 21 14 หรือสูงกว่าก่อน จากนั้นติดตั้งแพ็คเกจ zepeto module เวอร์ชัน 1 0 7 หรือสูงกว่า zepeto module shop api หากคุณสนใจใน zepeto module shop api กรุณาอ้างอิงเอกสารประกอบ 📘 โปรดดูคู่มือต่อไปนี้ \[ zepeto module shop api https //developer zepeto me/docs/module/namespaces/zepeto module shop ] ตัวอย่างการแสดงข้อมูลสินค้า โครงการ > สร้าง > zepeto > typescript ถูกสร้างขึ้นและชื่อถูกเปลี่ยนเป็น myitemlist เขียนสคริปต์ตัวอย่างตามที่แสดงด้านล่าง import { zepetoscriptbehaviour } from 'zepeto script' import { shopservice, category, itemkeyword } from 'zepeto module shop' import { zepetopropertyflag } from 'zepeto' import { texture2d, waituntil } from 'unityengine' import { rawimage } from 'unityengine ui' import { item } from 'zepeto module content' export default class myitemlist extends zepetoscriptbehaviour { public thumbnailimage rawimage; start() { this startcoroutine(this cogetmycategory()); } cogetmycategory() { var requestcategory = shopservice getmycategoryasync(); yield new waituntil(() => requestcategory keepwaiting == false); if (requestcategory responsedata issuccess) { let categoryinfo = requestcategory responsedata category; console log(`\[category info] ${categoryinfo displayname} length ${categoryinfo categories length}`); let categories category\[] = categoryinfo categories; for (const category of categories) { console log(`\[category displayname] ${category displayname} `); //category keyword is used as an argument in the shopservice getmycontentitemlistasync function console log(`\[category keyword] ${category keyword} `); } } this startcoroutine(this cogetmyitem()); } cogetmyitem() { var requestitemlist = shopservice getmycontentitemlistasync(itemkeyword all, null); yield new waituntil(() => requestitemlist keepwaiting == false); if (requestitemlist responsedata issuccess) { let items item\[] = requestitemlist responsedata items; // จำนวนของรายการที่ได้รับเป็นผลลัพธ์จาก getmycontentitemlistasync() console log(items length); for (let i = 0; i < items length; ++i) { const property zepetopropertyflag = items\[i] property; // รหัสรายการและคุณสมบัติของรายการ console log(`\[content item] (id) ${items\[i] id} | (property) ${property}`); // ตั้งค่าภาพขนาดย่อของรายการเป็นพื้นผิวของ rawimage var texturereq = items\[i] getthumbnailasync(); yield new waituntil(() => texturereq keepwaiting == false); let thumbnailtexture texture2d = texturereq responsedata texture; this thumbnailimage texture = thumbnailtexture; } } } } คำอธิบายสคริปต์ ดึงข้อมูลแท็บรายการของฉัน เรียกใช้ shopservice getmycategoryasync() เพื่อทราบหมวดหมู่รายการในแท็บรายการของฉัน เมื่อคุณได้รับการตอบกลับสำเร็จ คุณสามารถเข้าถึงอ็อบเจ็กต์ categoryresponse ผ่านคุณสมบัติ responsedata ได้ categoryresponse category categories ถูกเรียกดูและรายการหมวดหมู่รายการในแท็บรายการของฉันถูกส่งออก ดึงรายการสินค้า เรียกใช้ shopservice getmycontentitemlistasync(itemkeyword all, null) เพื่อดึงรายการสินค้าสำหรับทุกหมวดหมู่ คุณสามารถเลือกที่จะดึงรายการจากหมวดหมู่เฉพาะได้ ตัวอย่างเช่น คุณสามารถใช้ itemkeyword hair แทน itemkeyword all เพื่อดึงเฉพาะรายการเกี่ยวกับผม พารามิเตอร์ที่สองจะถูกใช้เฉพาะเมื่อคุณทราบโทเค็นหน้าถัดไปที่จะขอ ตั้งค่าเป็น null ในครั้งแรกที่คุณเรียก api สำหรับตัวอย่างที่เกี่ยวข้องกับ nextpagetoken โปรดตรวจสอบข้อมูลด้านล่าง เมื่อคุณได้รับการตอบกลับที่สำเร็จ คุณสามารถเข้าถึงอ็อบเจ็กต์ contentitemlistresponse ผ่านคุณสมบัติ responsedata ได้ itemresponse items ถูกเรียกดูและ id และรหัส enum ส่วนสำหรับแต่ละรายการถูกส่งออก นอกจากนี้ รูปภาพขนาดย่อของรายการจะถูกตั้งค่าเป็น rawimage ที่กำหนดไว้ หลังจากที่คุณเขียนสคริปต์เสร็จแล้ว ให้เพิ่มสคริปต์ไปยังอ็อบเจ็กต์ในฉาก การกดปุ่มเล่นจะแสดงรายการหมวดหมู่ของแท็บรายการของฉันและข้อมูลรายการของทุกหมวดหมู่ หากคุณสร้างพรีแฟบของภาพขนาดย่อของรายการและมีภาพขนาดย่อที่สร้างขึ้นแบบไดนามิกตามรายการสินค้า คุณสามารถแสดงภาพขนาดย่อของรายการสินค้าใน ui ได้ ตัวอย่างเพื่อตรวจสอบสถานะการเป็นเจ้าของของรายการเฉพาะของผู้ใช้ คุณสามารถใช้ getmycontentitemlistasync() เพื่อตรวจสอบว่ามีใครในโลกที่สวมใส่เสื้อผ้าเฉพาะหรือไม่ ต่อไปนี้คือตัวอย่างง่ายๆ ในการแสดงข้อความใน ui ของผู้ใช้ที่เป็นเจ้าของรายการเฉพาะ โปรเจกต์ > สร้าง > zepeto > typescript ถูกสร้างขึ้นและชื่อถูกเปลี่ยนเป็น checkitem เขียนสคริปต์ตัวอย่างตามที่แสดงด้านล่าง import { zepetoscriptbehaviour } from 'zepeto script' import { shopservice, itemkeyword } from 'zepeto module shop' import { zepetopropertyflag } from 'zepeto' import { waituntil } from 'unityengine' import { text } from 'unityengine ui' import { item } from 'zepeto module content' export default class checkitem extends zepetoscriptbehaviour { public resulttext text; public checkitemid string; start() { this resulttext gameobject setactive(false); this startcoroutine(this cocheckitem()); } cocheckitem() { let nextpagetoken string | null = null; do { // request the list of the user's content items const requestitemlist = shopservice getmycontentitemlistasync(itemkeyword all, nextpagetoken); yield new waituntil(() => requestitemlist keepwaiting == false); if (requestitemlist responsedata issuccess) { // get the content items from the response const contentitems item\[] = requestitemlist responsedata items; nextpagetoken = requestitemlist responsedata nextpagetoken; // iterate through the content items for (let i = 0; i < contentitems length; ++i) { const property zepetopropertyflag = contentitems\[i] property; // check if the item id matches the specified id if (contentitems\[i] id == this checkitemid) { // activate the matched item message this activatematcheditem(); break; } } } else { break; } } while (nextpagetoken != null); } activatematcheditem() { // show the matched item message this resulttext gameobject setactive(true); this resulttext text = "ว้าว คุณมีไอเทมที่ฉันทำ!"; } } คำอธิบายสคริปต์ นี่คือสคริปต์ที่เรียกดูรายการ 'รายการของฉัน' (ทุกหมวดหมู่) ของผู้ใช้ที่เข้าสู่ระบบในโลกและค้นหา id รายการที่ตรงกันที่ป้อนใน inspector หากมีหลายรายการ ค่า nextpagetoken จะไม่เป็น null ดังนั้นกระบวนการจะทำซ้ำด้วยคำสั่ง do while จนกว่าค่าจะเป็น null สังเกตว่า nextpagetoken ถูกจัดเตรียมเป็นพารามิเตอร์ที่สองของ shopservice getmycontentitemlistasync(itemkeyword all, nextpagetoken) เมื่อคุณได้รับการตอบสนองที่สำเร็จ คุณสามารถเข้าถึงวัตถุ contentitemlistresponse ผ่านคุณสมบัติ responsedata itemresponse items ถูกเรียกดูเพื่อค้นหาความตรงกันสำหรับ id รายการที่ป้อน หากพบรายการที่ตรงกัน จะมีการเรียกใช้ activatematcheditem() เพื่อแสดงข้อความบนหน้าจอของผู้ใช้และสิ้นสุดลูป หลังจากที่คุณเขียนสคริปต์เสร็จแล้ว ให้เพิ่มสคริปต์ไปยังวัตถุในฉาก ป้อน id ของรายการที่คุณต้องการตรวจสอบว่าผู้ใช้ในโลกมีใน inspector หรือไม่ กดปุ่มเล่นเพื่อเริ่มกระบวนการ ข้อความจะปรากฏบนหน้าจอหากผู้ใช้ที่เข้าสู่ระบบในโลกมีรายการที่ตรงกับรหัสรายการที่ป้อนเข้าไป คุณสามารถใช้ตัวอย่างนี้เพื่อสร้างเนื้อหาที่น่าสนใจทุกประเภท