So i want to make players upload 3d models in playfab from their device, and upload it to the catalog store but i don't know how to do that and there is no tutorials on this please help.
I am using Unity and the target platform is android
So i want to make players upload 3d models in playfab from their device, and upload it to the catalog store but i don't know how to do that and there is no tutorials on this please help.
I am using Unity and the target platform is android
You can refer to the following sample.
using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using PlayFab.ClientModels; using PlayFab.EconomyModels; using System.Text; using UnityEngine.Networking; public class UGCTest : MonoBehaviour { void Start() { PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest { CustomId = " " }, (result) => { Debug.Log("login success"); }, (error) => { Debug.LogError(error.GenerateErrorReport()); }); } string uploadUrl; string uploadId; string itemId; string payloadStr; byte[] payload; /// <summary> /// 1.CreateUploadUrls /// </summary> public void CreateUrl() { PlayFabEconomyAPI.CreateUploadUrls(new CreateUploadUrlsRequest { Files = new List<UploadInfo> { new UploadInfo { FileName="test.txt" } } }, CreateUrlsSuccess, OnError); } public void CreateUrlsSuccess(CreateUploadUrlsResponse result) { uploadUrl = result.UploadUrls[0].Url; uploadId = result.UploadUrls[0].Id; Debug.Log(result.UploadUrls[0].FileName + ":" + result.UploadUrls[0].Id + ":" + result.UploadUrls[0].Url); } /// <summary> /// 2.upload /// </summary> public void Upload() { ResourcesFile(); StartCoroutine(Upload_Put()); } IEnumerator Upload_Put() { UnityWebRequest request = UnityWebRequest.Put(uploadUrl, payload); request.SetRequestHeader("Content-Type", "text/plain"); request.SetRequestHeader("comp", "blob"); request.SetRequestHeader("x-ms-blob-type", "blockblob"); yield return request.SendWebRequest(); if(request.result==UnityWebRequest.Result.ProtocolError||request.result==UnityWebRequest.Result.ConnectionError) { Debug.LogError(request.error); } else { Debug.Log("put success"); } } /// <summary> /// 3.CreateDraftItem /// </summary> public void CreateDraft() { PlayFabEconomyAPI.CreateDraftItem(new CreateDraftItemRequest { Publish = false, Item = new PlayFab.EconomyModels.CatalogItem { Type = "ugc", Title = new Dictionary<string, string> { { "neutral","UGCTest" } }, Description = new Dictionary<string, string> { { "neutral","A ugc item" } }, ContentType = "example item", IsHidden = false, Contents = new List<Content> { new Content { Id=uploadId, Url=uploadUrl } } } }, (result) => { itemId = result.Item.Id; Debug.Log(result.Item.Id + ":" + result.Item.Contents[0].Id + ":" + result.Item.Contents[0].Url); }, OnError); } /// <summary> /// 4.Publish /// </summary> public void Publish() { PlayFabEconomyAPI.PublishDraftItem(new PublishDraftItemRequest { Id = itemId }, (result) => { Debug.Log("Publish Success"); }, OnError); } /// <summary> /// 5.GetStatus /// </summary> public void GetPublishStatus() { PlayFabEconomyAPI.GetItemPublishStatus(new GetItemPublishStatusRequest { Id = itemId }, (result) => { Debug.Log(result.StatusMessage + ":" + result.Result); }, OnError); } public void OnError(PlayFabError error) { Debug.LogError(error.GenerateErrorReport()); } public void ResourcesFile() { TextAsset txt = Resources.Load("test") as TextAsset; payloadStr = txt.text; payload = Encoding.UTF8.GetBytes(payloadStr); } }
Ok thanks, but it uses unity Web url i want to make the user directly select file from his device and upload it.
Uploading files to urls is by design, but UnityWebRequest is not necessary, you can upload files using whatever method you are good at. As for how to use Unity to read files in the user's device, please go to the Unity community for professional support.
What could go wrong if we call playfab's cloudscript getTime method?
Can you give me a link that shows how to read files from user's device
Can you explain what it means to upload to catalog store? PlayFab doesn't provide such a feature. Did you mean UGC? If so, please refer to Publish your first user generated content - PlayFab | Microsoft Docs to implement it.
For storing files you can also use Entity File, please refer to Entity files - PlayFab | Microsoft Docs.
If you just store string/json, you can also use Player Data, refer to Quickstart Player Data - PlayFab | Microsoft Docs.
Can you please send the script to do that? I don't understand the tutorial
3 People are following this question.