备份CatanBuilding瘦身独立工程
This commit is contained in:
159
LocalPackages/asap.playfab.async/Editor/AsyncCodeGen.cs
Normal file
159
LocalPackages/asap.playfab.async/Editor/AsyncCodeGen.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
LocalPackages/asap.playfab.async/Editor/AsyncCodeGen.cs.meta
Normal file
11
LocalPackages/asap.playfab.async/Editor/AsyncCodeGen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38d3e0539df25f746bcce1eb53cf944f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "asap.playfab.async.editor",
|
||||
"rootNamespace": "asap.playfab.editor",
|
||||
"references": [
|
||||
"GUID:0da6d172d18a54e4389d0dce1e1ffdf2"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78dc71f7c2e31d44dae7ff07b8c305f9
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user