C# Unity playfab问题我需要导出到playfab,但是如果Unity因为有错误而没有加载脚本怎么办?

C# Unity playfab问题我需要导出到playfab,但是如果Unity因为有错误而没有加载脚本怎么办?,c#,visual-studio,unity3d,C#,Visual Studio,Unity3d,Unity playfab问题我需要导出到playfab,但是如果Unity因为有错误而没有加载脚本怎么办?有人能帮我吗?我是unity的新手,我遇到了上述问题。欢迎任何帮助 我试过很多种方法,事实上我已经试了两天了,但是没有任何成功,我总是以各种方式面对这个问题 PLayfabMonetizationExplorer代码 using System.Collections; using System.Collections.Generic; using UnityEngine; using S

Unity playfab问题我需要导出到playfab,但是如果Unity因为有错误而没有加载脚本怎么办?有人能帮我吗?我是unity的新手,我遇到了上述问题。欢迎任何帮助

我试过很多种方法,事实上我已经试了两天了,但是没有任何成功,我总是以各种方式面对这个问题

PLayfabMonetizationExplorer代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if UNITY_PURCHASING && UNITY_EDITOR
using UnityEngine.Purchasing;
#endif
using LitJson;

public class PlayfabMonetizationExporter : MonoBehaviour
{
    public GameInstance gameInstance;
    public MonetizationManager monetizationManager;

    [Header("Catalog")]
    public string exportingCatalogVersion = "Catalog-1";

#if UNITY_EDITOR
    [ContextMenu("Export Catalog")]
    public void ExportCatalog()
    {
        var allItems = gameInstance.GetAllItems();
        var allBundles = monetizationManager.products;
        var catalogItems = new Dictionary<string, CatalogItem>();
        foreach (var item in allItems)
        {
            var virtualCurrencyPrices = new Dictionary<string, int>();
            if (!string.IsNullOrEmpty(item.price.id))
                virtualCurrencyPrices[item.price.id] = item.price.amount;
            foreach (var price in item.prices)
            {
                if (!string.IsNullOrEmpty(price.id))
                    virtualCurrencyPrices[price.id] = price.amount;
            }
            catalogItems[item.GetId()] = new CatalogItem()
            {
                ItemId = item.GetId(),
                CatalogVersion = exportingCatalogVersion,
                DisplayName = item.GetTitle(),
                Description = item.GetDescription(),
                VirtualCurrencyPrices = virtualCurrencyPrices,
                Consumable = new CatalogConsumable(),
                Bundle = new CatalogBundle(),
            };
        }

        var iapCatalog = ProductCatalog.LoadDefaultCatalog();
        var iapCatalogDict = new Dictionary<string, ProductCatalogItem>();
        foreach (var product in iapCatalog.allProducts)
        {
            iapCatalogDict[product.id] = product;
        }

        ProductCatalogItem tempIAPItem;
        foreach (var bundle in allBundles)
        {
            var virtualCurrencyPrices = new Dictionary<string, int>();
            virtualCurrencyPrices.Add("RM", 0); // TODO: SET USD PRICE
            var itemIds = new List<string>();
            foreach (var item in bundle.items)
            {
                itemIds.Add(item.GetId());
            }
            var rewardCurrencies = new Dictionary<string, int>();
            foreach (var currency in bundle.currencies)
            {
                rewardCurrencies[currency.id] = currency.amount;
            }

            if (iapCatalogDict.TryGetValue(bundle.GetId(), out tempIAPItem))
            {
                // Google play
                catalogItems[tempIAPItem.GetStoreID(GooglePlay.Name)] = new CatalogItem()
                {
                    ItemId = tempIAPItem.GetStoreID(GooglePlay.Name),
                    CatalogVersion = exportingCatalogVersion,
                    DisplayName = bundle.GetTitle(),
                    Description = bundle.GetDescription(),
                    VirtualCurrencyPrices = virtualCurrencyPrices,
                    Consumable = new CatalogConsumable()
                    {
                        UsagePeriod = 3,
                    },
                    Bundle = new CatalogBundle()
                    {
                        BundledItems = itemIds,
                        BundledVirtualCurrencies = rewardCurrencies,
                    }
                };
                // Apple appstore
                catalogItems[tempIAPItem.GetStoreID(AppleAppStore.Name)] = new CatalogItem()
                {
                    ItemId = tempIAPItem.GetStoreID(AppleAppStore.Name),
                    CatalogVersion = exportingCatalogVersion,
                    DisplayName = bundle.GetTitle(),
                    Description = bundle.GetDescription(),
                    VirtualCurrencyPrices = virtualCurrencyPrices,
                    Consumable = new CatalogConsumable()
                    {
                        UsagePeriod = 3,
                    },
                    Bundle = new CatalogBundle()
                    {
                        BundledItems = itemIds,
                        BundledVirtualCurrencies = rewardCurrencies,
                    }
                };
            }
        }

        var dropTables = new List<DropTableItem>();

        var catalog = new PlayfabCatalog()
        {
            CatalogVersion = exportingCatalogVersion,
            Catalog = new List<CatalogItem>(catalogItems.Values),
            DropTables = dropTables,
        };
        var json = JsonMapper.ToJson(catalog);
        var path = EditorUtility.SaveFilePanel("Export Catalog", Application.dataPath, "CATALOG", "json");
        if (path.Length > 0)
            File.WriteAllText(path, json);
    }

    [ContextMenu("Export Currencies")]
    public void ExportCurrencies()
    {
        var currencies = new List<PlayfabCurrency>();
        foreach (var currency in monetizationManager.currencies)
        {
            var code = currency.id;
            var name = currency.name;
            var startAmount = currency.startAmount;
            currencies.Add(new PlayfabCurrency()
            {
                CurrencyCode = code,
                DisplayName = name,
                InitialDeposit = startAmount,
                RechargeRate = 0,
                RechargeMax = 0,
                CurrencyCodeFull = code + " (" + name + ")",
            });
        }
        var json = JsonMapper.ToJson(currencies);
        var path = EditorUtility.SaveFilePanel("Export Currencies", Application.dataPath, "CURRENCIES", "json");
        if (path.Length > 0)
            File.WriteAllText(path, json);
    }
#endif

    [System.Serializable]
    public class PlayfabCurrency
    {
        public string CurrencyCode;     // GE
        public string DisplayName;      // Gem
        public int InitialDeposit;      // 0
        public int RechargeRate;        // 0
        public int RechargeMax;         // 0
        public string CurrencyCodeFull; // GE (Gem)
        public string GameManagerClassMetadata;
    }

    [System.Serializable]
    public class PlayfabCatalog
    {
        public string CatalogVersion;
        public List<CatalogItem> Catalog;
        public List<DropTableItem> DropTables;
    }

    [System.Serializable]
    public class CatalogItem
    {
        public string ItemId;
        public string ItemClass;
        public string CatalogVersion;
        public string DisplayName;
        public string Description;
        public Dictionary<string, int> VirtualCurrencyPrices;
        public Dictionary<string, int> RealCurrencyPrices;
        public List<string> Tags;
        public object CustomData;
        public CatalogConsumable Consumable;
        public CatalogContainer Container;
        public CatalogBundle Bundle;
        public bool CanBecomeCharacter;
        public bool IsStackable;
        public bool IsTradable;
        public string ItemImageUrl;
        public bool IsLimitedEdition;
        public int InitialLimitedEditionCount;
        public object ActivatedMembership;
    }

    [System.Serializable]
    public class CatalogConsumable
    {
        public int? UsageCount;
        public int? UsagePeriod;
        public string UsagePeriodGroup;
    }

    [System.Serializable]
    public class CatalogContainer
    {
        public string KeyItemId;
        public List<string> ItemContents;
        public List<string> ResultTableContents; // Drop tables
        public Dictionary<string, int> VirtualCurrencyContents;
    }

    [System.Serializable]
    public class CatalogBundle
    {
        public List<string> BundledItems;
        public List<string> BundledResultTables; // Drop tables
        public Dictionary<string, int> BundledVirtualCurrencies;
    }

    [System.Serializable]
    public class DropTableItem
    {
        public string TableId;
        public List<DropTableItemNode> Nodes;
    }

    [System.Serializable]
    public class DropTableItemNode
    {
        public string ResultItemType = "ItemId";
        public string ResultItem;
        public int Weight;
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用System.IO;
#如果统一编辑器
使用UnityEditor;
#恩迪夫
#如果UNITY\u采购和UNITY\u编辑器
使用UnityEngine。采购;
#恩迪夫
使用LitJson;
公共类PlayFab货币化出口商:单一行为
{
公共游戏实例游戏实例;
公共货币化经理货币化经理;
[标题(“目录”)]
公共字符串exportingCatalogVersion=“Catalog-1”;
#如果统一编辑器
[上下文菜单(“导出目录”)]
public void ExportCatalog()
{
var allItems=gameInstance.GetAllItems();
var allBundles=货币化管理器.products;
var catalogItems=newdictionary();
foreach(所有项目中的var项目)
{
var virtualCurrencyPrices=新字典();
如果(!string.IsNullOrEmpty(item.price.id))
virtualCurrencyPrices[item.price.id]=item.price.amount;
foreach(项目价格中的var价格)
{
如果(!string.IsNullOrEmpty(price.id))
virtualCurrencyPrices[price.id]=price.amount;
}
catalogItems[item.GetId()]=新CatalogItem()
{
ItemId=item.GetId(),
CatalogVersion=导出CatalogVersion,
DisplayName=item.GetTitle(),
Description=item.GetDescription(),
VirtualCurrencyPrices=VirtualCurrencyPrices,
消耗品=新目录消耗品(),
Bundle=新目录Bundle(),
};
}
var iapCatalog=ProductCatalog.LoadDefaultCatalog();
var iapCatalogDict=新字典();
foreach(iapCatalog.allProducts中的var乘积)
{
iapCatalogDict[product.id]=产品;
}
产品目录项tempIAPItem;
foreach(所有bundles中的var bundle)
{
var virtualCurrencyPrices=新字典();
virtualCurrencyPrices.Add(“RM”,0);//TODO:设置美元价格
var itemIds=新列表();
foreach(bundle.items中的变量项)
{
Add(item.GetId());
}
var rewardCurrencies=新字典();
foreach(捆绑中的var货币。货币)
{
报酬货币[currency.id]=currency.amount;
}
if(iapCatalogDict.TryGetValue(bundle.GetId(),out tempIAPItem))
{
//谷歌游戏
catalogItems[tempIAPItem.GetStoreID(GooglePlay.Name)]=新CatalogItem()
{
ItemId=tempIAPItem.GetStoreID(GooglePlay.Name),
CatalogVersion=导出CatalogVersion,
DisplayName=bundle.GetTitle(),
Description=bundle.GetDescription(),
VirtualCurrencyPrices=VirtualCurrencyPrices,
消耗品=新目录消耗品()
{
UsagePeriod=3,
},
Bundle=新目录Bundle()
{
BundledItems=itemIds,
捆绑虚拟货币=兑换货币,
}
};
//苹果应用商店
catalogItems[tempIAPItem.GetStoreID(AppleAppStore.Name)]=新CatalogItem()
{
ItemId=tempIAPItem.GetStoreID(AppleAppStore.Name),
CatalogVersion=导出CatalogVersion,
DisplayName=bundle.GetTitle(),
Description=bundle.GetDescription(),
VirtualCurrencyPrices=VirtualCurrencyPrices,
消耗品=新目录消耗品()
{
UsagePeriod=3,
},
Bundle=新目录Bundle()
{
BundledItems=itemIds,
捆绑虚拟货币=兑换货币,
}
};
}
}
var dropTables=新列表();
var catalog=new PlayfabCatalog()
{
CatalogVersion=导出CatalogVersion,
Catalog=新列表(catalogItems.Values),
DropTables=DropTables,
};
var json=JsonMapper.ToJson(目录);
var path=EditorUtility.SaveFilePanel(“导出目录”,Application.dataPath,“目录”,“json”);
如果(路径长度>0)
WriteAllText(路径,json);
}
[上下文菜单(“出口货币”)]
公共货币()
{
var货币=新列表();
foreach(货币化管理器中的var货币)
{
var代码=currency.id;
var name=currency.name;
var startAmount=currency.startAmount;
货币。添加(新货币()
{
CurrencyCode=代码,
DisplayName=name,
初始存款=startAmount,
再充电率=0,
最大值为0,
CurrencyCodeFull=code+“(“+name+”)”,
});
}
var json=JsonMapper.ToJson(货币);
var path=EditorUtility.SaveFilePanel(“导出货币”