先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
160 lines
5.6 KiB
C#
160 lines
5.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using PlayFab;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace asap.playfab.editor
|
|
{
|
|
public class AsyncCodeGen
|
|
{
|
|
private static string OutputDir = "LocalPackages/asap.playfab.async/Runtime/Gen";
|
|
private static string ClassTemp =
|
|
@"
|
|
#if {3}
|
|
using System.Threading.Tasks;
|
|
using PlayFab;
|
|
using UnityEngine;
|
|
{0}
|
|
|
|
namespace asap.playfab.async
|
|
{{
|
|
//generated file, do not modify
|
|
public static partial class {1}
|
|
{{
|
|
{2}
|
|
}}
|
|
}}
|
|
#endif
|
|
";
|
|
|
|
private static string MehtodTemp =
|
|
@"
|
|
public static Task<{3}> {1}Async({2} request)
|
|
{{
|
|
var task = new TaskCompletionSource<{3}>();
|
|
{0}.{1}(request,
|
|
result =>
|
|
{{
|
|
task.SetResult(result);
|
|
}},
|
|
error =>
|
|
{{
|
|
Debug.LogError(error.GenerateErrorReport());
|
|
task.SetResult(null);
|
|
}});
|
|
return task.Task;
|
|
}}
|
|
";
|
|
[MenuItem(@"asap/PlayFab/Generate Async Client API")]
|
|
static async void GenerateClientAsyncAPIs()
|
|
{
|
|
var apiType = typeof(PlayFabClientAPI);
|
|
var usings = "using PlayFab.ClientModels;";
|
|
var asyncAPIName = "PlayFabClientAsyncAPI";
|
|
var macro = "!DISABLE_PLAYFABCLIENT_API && !DISABLE_PLAYFAB_STATIC_API";
|
|
if (!Directory.Exists(OutputDir))
|
|
{
|
|
Directory.CreateDirectory(OutputDir);
|
|
}
|
|
await GenerateAsyncAPI(apiType, usings, asyncAPIName, macro);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
|
|
#if ENABLE_PLAYFABSERVER_API && !DISABLE_PLAYFAB_STATIC_API
|
|
[MenuItem(@"asap/PlayFab/Generate Async Server API")]
|
|
static async void GenerateServerAsyncAPIs()
|
|
{
|
|
var apiType = typeof(PlayFabServerAPI);
|
|
var usings = "using PlayFab.ServerModels;";
|
|
var asyncAPIName = "PlayFabServerAsyncAPI";
|
|
var macro = "ENABLE_PLAYFABSERVER_API && !DISABLE_PLAYFAB_STATIC_API";
|
|
await GenerateAsyncAPI(apiType, usings, asyncAPIName, macro);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
#endif
|
|
|
|
#if ENABLE_PLAYFABADMIN_API && !DISABLE_PLAYFAB_STATIC_API
|
|
[MenuItem(@"asap/PlayFab/Generate Async Admin API")]
|
|
static async void GenerateAdminAsyncAPIs()
|
|
{
|
|
var apiType = typeof(PlayFabAdminAPI);
|
|
var usings = "using PlayFab.AdminModels;";
|
|
var asyncAPIName = "PlayFabAdminAsyncAPI";
|
|
var macro = "ENABLE_PLAYFABADMIN_API && !DISABLE_PLAYFAB_STATIC_API";
|
|
await GenerateAsyncAPI(apiType, usings, asyncAPIName, macro);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
#endif
|
|
|
|
#if !DISABLE_PLAYFABENTITY_API && !DISABLE_PLAYFAB_STATIC_API
|
|
[MenuItem(@"asap/PlayFab/Generate Async Data API")]
|
|
static async void GenerateDataAsyncAPIs()
|
|
{
|
|
var apiType = typeof(PlayFabDataAPI);
|
|
var usings = "using PlayFab.DataModels;";
|
|
var asyncAPIName = "PlayFabDataAsyncAPI";
|
|
var macro = "!DISABLE_PLAYFABENTITY_API && !DISABLE_PLAYFAB_STATIC_API";
|
|
await GenerateAsyncAPI(apiType, usings, asyncAPIName, macro);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
#endif
|
|
#if !DISABLE_PLAYFABENTITY_API && !DISABLE_PLAYFAB_STATIC_API
|
|
[MenuItem(@"asap/PlayFab/Generate Async Profiles API")]
|
|
static async void GenerateProfilesAsyncAPIs()
|
|
{
|
|
var apiType = typeof(PlayFabProfilesAPI);
|
|
var usings = "using PlayFab.ProfilesModels;";
|
|
var asyncAPIName = "PlayFabProfilesAsyncAPI";
|
|
var macro = "!DISABLE_PLAYFABENTITY_API && !DISABLE_PLAYFAB_STATIC_API";
|
|
if (!Directory.Exists(OutputDir))
|
|
{
|
|
Directory.CreateDirectory(OutputDir);
|
|
}
|
|
await GenerateAsyncAPI(apiType, usings, asyncAPIName, macro);
|
|
AssetDatabase.Refresh();
|
|
}
|
|
#endif
|
|
|
|
private static async Task GenerateAsyncAPI(Type apiType, string usings, string asyncAPIName, string macro)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
var typeName = apiType.Name;
|
|
var methodInfos = apiType.GetMethods();
|
|
for (int i = 0; i < methodInfos.Length; i++)
|
|
{
|
|
var methodInfo = methodInfos[i];
|
|
var obsoleteAttributes = methodInfo.GetCustomAttributes(typeof(ObsoleteAttribute), false);
|
|
if (obsoleteAttributes != null && obsoleteAttributes.Length > 0)
|
|
continue;
|
|
if (methodInfo.IsGenericMethod)
|
|
continue;
|
|
var parameterInfos = methodInfo.GetParameters();
|
|
if (parameterInfos.Length != 5)
|
|
continue;
|
|
|
|
var inputType = parameterInfos[0].ParameterType;
|
|
var outputType = parameterInfos[1].ParameterType.GenericTypeArguments[0];
|
|
sb.AppendFormat(MehtodTemp, typeName, methodInfo.Name, inputType.Name, outputType.Name);
|
|
// sb.AppendLine();
|
|
}
|
|
|
|
StringBuilder classSB = new StringBuilder();
|
|
classSB.AppendFormat(ClassTemp, usings, asyncAPIName, sb.ToString(), macro);
|
|
|
|
var outputPath = Path.Combine(OutputDir, asyncAPIName + ".cs");
|
|
// var fs = new FileStream(outputPath, FileMode.OpenOrCreate);
|
|
var sw = new StreamWriter(outputPath);
|
|
await sw.WriteAsync(classSB.ToString());
|
|
await sw.FlushAsync();
|
|
sw.Close();
|
|
}
|
|
}
|
|
}
|