feat:update upm
commit
51d1037052
|
@ -0,0 +1,110 @@
|
|||
# ChangeLog
|
||||
|
||||
## 3.11.1
|
||||
|
||||
### Fixed bugs
|
||||
- iOS: 修复授权模块对系统 URL 回调的使用方式
|
||||
|
||||
## 3.11.0
|
||||
|
||||
## 3.10.0
|
||||
|
||||
## 3.9.0
|
||||
|
||||
## 3.8.0
|
||||
|
||||
## 3.7.1
|
||||
|
||||
## 3.7.0
|
||||
|
||||
## 3.6.3
|
||||
|
||||
### Optimization and fixed bugs
|
||||
- Android 修复特定机型上繁体中文的识别
|
||||
- Android 修复初始化时未配置 TapDBConfig 会初始化失败的问题
|
||||
|
||||
## 3.6.1
|
||||
|
||||
## 3.6.0
|
||||
|
||||
## 3.5.2
|
||||
|
||||
### New Feature
|
||||
- 新增多语言配置
|
||||
|
||||
## 3.5.0
|
||||
|
||||
### Optimization and fixed bugs
|
||||
- 支持性更新
|
||||
|
||||
## 3.4.0
|
||||
|
||||
## 3.3.0
|
||||
|
||||
- Native Update
|
||||
|
||||
## 3.2.0
|
||||
|
||||
- Native Update
|
||||
|
||||
## 3.1.0
|
||||
|
||||
- Native Update
|
||||
|
||||
## 3.0.0
|
||||
|
||||
### Optimization
|
||||
|
||||
- Bridge 新增 Task 桥接
|
||||
|
||||
## 2.1.7
|
||||
|
||||
### None
|
||||
|
||||
## 2.1.6
|
||||
|
||||
### BreakingChanges
|
||||
|
||||
- 修改 **TapCommon.OpenReviewInTapGlobal()** 方法命名
|
||||
|
||||
## 2.1.5
|
||||
|
||||
### Optimization and fixed bugs
|
||||
|
||||
- 内部优化
|
||||
|
||||
## 2.1.4
|
||||
|
||||
### Optimization and fixed bugs
|
||||
|
||||
- 优化多语言相关
|
||||
- 修复 JSON 解析错误
|
||||
|
||||
## 2.1.3
|
||||
|
||||
### New Feature
|
||||
|
||||
* iOS 新增 TapTap 以及 Tap.IO 客户端安装判断
|
||||
|
||||
## 2.1.2
|
||||
|
||||
### Optimization and fixed bugs
|
||||
|
||||
* 修复 iOS ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 设置问题可能导致的 AppStore 审核无法通过
|
||||
|
||||
## 2.1.1
|
||||
|
||||
### Feature
|
||||
|
||||
* Android 新增 TapTap App 相关支持功能
|
||||
|
||||
## 2.1.0
|
||||
|
||||
* 新增长链接支持 TapTap.Friends
|
||||
* 海内外域名切换
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Feature
|
||||
|
||||
* TapTap Common
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89a2f2ba3f4d4cf0b55f2f992c6b6afb
|
||||
timeCreated: 1616744142
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e5655844e77cd49d8a69c4a299e31419
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,178 @@
|
|||
# TapCommon 用于支持 TapSDK 其他模块中 Android、iOS 与 Unity 的通信
|
||||
|
||||
> 目前 TapSDK 业务中,Unity 业务层实现的功能不多,主要作为桥接来调用 Android、iOS SDK 中的方法。
|
||||
|
||||
## 一、实现 Unity 调用 Android、iOS 方法
|
||||
|
||||
> 为了方便 Unity 一套代码可以调用双端方法,所以定义原生接口时,需要考虑 Android、iOS 语言之间的差异。
|
||||
|
||||
### Android 接口定义
|
||||
|
||||
- 使用 `@BridgeService` 、`@BridgeMethod` 、`@BridgeParam` 注解修饰 `类`、`方法`、`参数`。
|
||||
- `Activity`、`BridgeCallback` 这两个类型参数不需要 `@BridgeParam` 注解。
|
||||
- `@BridgeParam` 仅支持基本数据类型(包含 `String`)。
|
||||
|
||||
```java
|
||||
@BridgeService("TestService")
|
||||
public class TestService implementation IBridgeService {
|
||||
|
||||
@BridgeMethod("testMethodWithCallback")
|
||||
void testMethodWithCallback(BridgeCallback callback);
|
||||
|
||||
@BridgeMethod("testMethodWithArgsAndCallback")
|
||||
void testMethodWithArgsAndCallback(Activity activity, @BridgeParam("args1") String appId, @BridgeParam("args2") int args2, BridgeCallback callback);
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Android 接口实现
|
||||
|
||||
```java
|
||||
public class TestService implementation TestService {
|
||||
|
||||
@Override
|
||||
public void testMethodWithCallback(BridgeCallback callback){
|
||||
callback.onResult("testMethodWithCallback 回调给 Unity 的参数");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testMethodWithArgsAndCallback(Activity activity, String appId,int args2, BridgeCallback callback){
|
||||
callback.onResult("testMethodWithArgsAndCallback 回调给 Unity 的参数");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### iOS 接口定义
|
||||
|
||||
> iOS 方法名通过反射获取到的为 `args1:args2:bridgeCallback` ,所以 iOS 的方法定义与 Android 略有不同。
|
||||
|
||||
- 类名必须同 Android `@BridgeService` 所修饰的类名一致。
|
||||
- 参数名例如 `args1`、`args2` 必须同 Android `@BridgeParam` 修饰的一致,用于回调的 `iOS` 闭包的参数名必须为 `bridgeCallback`。
|
||||
- 当参数个数仅为 0 或者 仅为 闭包时,方法名必须同 Android `@BridgeMethod` 修饰的方法一致。
|
||||
|
||||
```objectivec
|
||||
@interface TestService
|
||||
|
||||
// 匹配的是 Android 中 testMethodWithCallback 方法
|
||||
+(void) testMethodWithCallback:(void (^)(NSString *result))callback;
|
||||
|
||||
// 匹配的是 Android 中 testMethodWithArgsAndCallback 方法
|
||||
+(void) args1:(NSString*)args1 args2:(NSNumber*)args2 bridgeCallback:(void (^)(NSString *result))callback;
|
||||
|
||||
@end
|
||||
```
|
||||
|
||||
### iOS 接口实现
|
||||
|
||||
```objectivec
|
||||
@implementation TestService
|
||||
|
||||
+(void) testMethodWithCallback:(void (^)(NSString *result)) callback{
|
||||
callback(@"testMethodWithCallback 回调给 Unity 的参数");
|
||||
}
|
||||
|
||||
+(void) args1:(NSString*)args1 args2:(NSNumber*)args2 bridgeCallback:(void (^)(NSString *result))callback{
|
||||
callback(@"testMethodWithArgsAndCallback 回调给 Unity 的参数");
|
||||
}
|
||||
|
||||
@end
|
||||
```
|
||||
|
||||
### Unity 调用上文中定义的 Android、iOS 接口
|
||||
|
||||
#### 1.初始化
|
||||
|
||||
```c#
|
||||
// Android 初始化
|
||||
//CLZ_NAME 和IMP_NAME为 接口以及实现类的全路径包名 例如:com.tds.bridge.TestService,com.tds.bridge.TestServiceImpl
|
||||
EngineBridge.GetInstance().Register(CLZ_NAME, IMP_NAME);
|
||||
|
||||
// iOS 无需初始化
|
||||
```
|
||||
#### 2.调用方法
|
||||
|
||||
`Bridge.CallHandler` 为异步方法,执行线程的流程为:
|
||||
|
||||
Unity Thread -> Native MainThread -> Execute Function -> Unity Thread
|
||||
|
||||
所以执行 `CallHandler` 的 Thread 和 `Action<Result>` 的 Thread 都为 Unity 当前 Thread。
|
||||
|
||||
```c#
|
||||
var command = new Command.Builder()
|
||||
.Service("TestService") // @BridgeService 值以及 iOS 类名
|
||||
.Method("testMethodWithArgsAndCallback") // @BridgeMethod 值 以及 iOS 方法名
|
||||
.Args("args1","value") // @BridgeParam 值 以及 iOS 参数名
|
||||
.Args("args2",1) // 同上
|
||||
.Callback(true) // 是否需要添加 BridgeCallback
|
||||
.OnceTime(true) // 当前 BridgeCallback 是否常驻内存
|
||||
.CommandBuilder();
|
||||
|
||||
// 需要回调
|
||||
EngineBridge.GetInstance().CallHandler(command,result=>{
|
||||
if(EngineBridge.CheckResult(result)){
|
||||
// 桥接调用成功
|
||||
// 当前 Content 则为 Android、iOS 通过 BridgeCallback 传给 Unity 的值
|
||||
var content = result.content;
|
||||
}
|
||||
});
|
||||
|
||||
// 不需要回调
|
||||
EngineBridge.GetInstance().CallHandler(command);
|
||||
```
|
||||
|
||||
## 二、Android 、iOS 调用 Unity
|
||||
|
||||
鉴于 TapSDK 3.1.+ 之后,Android 与 iOS 需要同步 `TapBootstrap` 中 `TDSUser` 的部分参数,所以 `TapCommon` 在当前版本支持了原生简单的调用 Unity 接口。
|
||||
|
||||
以下以 Android、iOS 需要 Unity 提供 `sessionToken` 以及 `objectId` 为例
|
||||
|
||||
### Unity 实现 ITapPropertiesProxy 接口并注册
|
||||
|
||||
```c#
|
||||
public class SessionTokenProxy:ITapPropertiesProxy{
|
||||
|
||||
public string GetProperties(){
|
||||
return "sessionToken-kafjaskldfjasjdhfajkdfajdfas";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ObjectIdProxy:ITapPropertiesProxy {
|
||||
|
||||
public string GetProperties(){
|
||||
return "objectId-dafasdfad";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 通过 TapCommon 注册 Native 需要调用的接口
|
||||
TapCommon.RegisterProperties("sessionToken",new SessionTokenProxy());
|
||||
|
||||
TapCommon.RegisterProperties("objectid",new ObjectIdProxy());
|
||||
```
|
||||
|
||||
### Android、iOS 调用 Unity 实现的 ITapPropertiesProxy 来获取所需要的值
|
||||
|
||||
Android 获取 `sessionToken` 以及 `objectId`
|
||||
|
||||
```java
|
||||
String sessionToken = TapPropertiesHolder.INSTANCE.getProperty("sessionToken");
|
||||
String objectId = TapPropertiesHolder.INSTANCE.getProperty("objectId");
|
||||
```
|
||||
|
||||
iOS 获取 `sessionToken` 以及 `objectId`
|
||||
|
||||
```objectivec
|
||||
NSString* sessionToken = [[TapPropertiesHolder shareInstance] getProperty:@"sessionToken"];
|
||||
NSString* objectId = [[TapPropertiesHolder shareInstance] getProperty:@"objectId"];
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c2be0874429944a43820d92aa06185f4
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,89 @@
|
|||
## TapTap.Common
|
||||
|
||||
### 接口描述
|
||||
|
||||
#### 1.获取地区
|
||||
|
||||
```c#
|
||||
TapCommon.GetRegionCode(isMainland =>
|
||||
{
|
||||
// true 中国大陆 false 非中国大陆
|
||||
});
|
||||
```
|
||||
|
||||
#### 2. TapTap 是否安装
|
||||
|
||||
```c#
|
||||
TapCommon.IsTapTapInstalled(installed =>
|
||||
{
|
||||
// true 安装 false 未安装
|
||||
});
|
||||
```
|
||||
|
||||
#### 3. TapTap IO 是否安装
|
||||
|
||||
```c#
|
||||
TapCommon.IsTapTapGlobalInstalled(installed =>
|
||||
{
|
||||
// true 安装 false 未安装
|
||||
});
|
||||
```
|
||||
|
||||
### Android 独占方法
|
||||
|
||||
#### 4. 在 TapTap 更新游戏
|
||||
|
||||
```c#
|
||||
TapCommon.UpdateGameInTapTap(appId,updateSuccess =>
|
||||
{
|
||||
// true 更新成功 false 更新失败
|
||||
});
|
||||
```
|
||||
|
||||
#### 5. 在 TapTap IO 更新游戏
|
||||
|
||||
```c#
|
||||
TapCommon.UpdateGameInTapGlobal(appId,updateSuccess =>
|
||||
{
|
||||
// true 更新成功 false 更新失败
|
||||
});
|
||||
```
|
||||
|
||||
#### 6. 在 TapTap 打开当前游戏的评论区
|
||||
|
||||
```c#
|
||||
TapCommon.OpenReviewInTapTap(appId,openSuccess =>
|
||||
{
|
||||
// true 打开评论区 false 打开失败
|
||||
});
|
||||
```
|
||||
|
||||
#### 6. 在 TapTap IO 打开当前游戏的评论区
|
||||
|
||||
```c#
|
||||
TapCommon.OpenReviewInTapGlobal(appId,openSuccess =>
|
||||
{
|
||||
// true 打开评论区 false 打开失败
|
||||
});
|
||||
```
|
||||
|
||||
#### 7. 唤起 TapTap 客户端更新游戏
|
||||
|
||||
appId: 游戏在 TapTap 商店的唯一身份标识
|
||||
|
||||
例如:https://www.taptap.com/app/187168 ,其中 187168 是 appid.
|
||||
|
||||
```c#
|
||||
// 在 TapTap 客户端更新游戏,失败时通过浏览器打开 Tap 网站对应的游戏页面
|
||||
// 当你在国内区上架时使用
|
||||
bool isSuccess = await TapCommon.UpdateGameAndFailToWebInTapTap(string appId);
|
||||
// 当你在海外区上架时使用
|
||||
bool isSuccess = await TapCommon.UpdateGameAndFailToWebInTapGlobal(string appId):
|
||||
```
|
||||
|
||||
如果你需要在唤起 Tap 客户端失败时跳转到自己的网页
|
||||
|
||||
```c#
|
||||
bool isSuccess = await TapCommon.UpdateGameAndFailToWebInTapTap(string appId, string webUrl)
|
||||
bool isSuccess = await TapCommon.UpdateGameAndFailToWebInTapGlobal(string appId, string webUrl)
|
||||
```
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1d7008a3a22e45a4bfe9605e6d050a29
|
||||
timeCreated: 1616744132
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 28e2e71fed1414ad3978a4e5575065f6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace TapTap.Common.Editor {
|
||||
public static class BuildTargetUtils {
|
||||
public static bool IsSupportMobile(BuildTarget platform) {
|
||||
return platform == BuildTarget.iOS || platform == BuildTarget.Android;
|
||||
}
|
||||
|
||||
public static bool IsSupportStandalone(BuildTarget platform) {
|
||||
return platform == BuildTarget.StandaloneOSX ||
|
||||
platform == BuildTarget.StandaloneWindows || platform == BuildTarget.StandaloneWindows64;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: da005b5e251334d388fe38e6978890cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,70 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TapTap.Common.Editor {
|
||||
public class LinkedAssembly {
|
||||
public string Fullname { get; set; }
|
||||
public string[] Types { get; set; }
|
||||
}
|
||||
|
||||
public class LinkXMLGenerator {
|
||||
public static void Generate(string path, IEnumerable<LinkedAssembly> assemblies) {
|
||||
DirectoryInfo parent = Directory.GetParent(path);
|
||||
if (!parent.Exists) {
|
||||
Directory.CreateDirectory(parent.FullName);
|
||||
}
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
|
||||
XmlNode rootNode = doc.CreateElement("linker");
|
||||
doc.AppendChild(rootNode);
|
||||
|
||||
foreach (LinkedAssembly assembly in assemblies) {
|
||||
XmlNode assemblyNode = doc.CreateElement("assembly");
|
||||
|
||||
XmlAttribute fullnameAttr = doc.CreateAttribute("fullname");
|
||||
fullnameAttr.Value = assembly.Fullname;
|
||||
assemblyNode.Attributes.Append(fullnameAttr);
|
||||
|
||||
if (assembly.Types?.Length > 0) {
|
||||
foreach (string type in assembly.Types) {
|
||||
XmlNode typeNode = doc.CreateElement("type");
|
||||
XmlAttribute typeFullnameAttr = doc.CreateAttribute("fullname");
|
||||
typeFullnameAttr.Value = type;
|
||||
typeNode.Attributes.Append(typeFullnameAttr);
|
||||
|
||||
XmlAttribute typePreserveAttr = doc.CreateAttribute("preserve");
|
||||
typePreserveAttr.Value = "all";
|
||||
typeNode.Attributes.Append(typePreserveAttr);
|
||||
|
||||
assemblyNode.AppendChild(typeNode);
|
||||
}
|
||||
} else {
|
||||
XmlAttribute preserveAttr = doc.CreateAttribute("preserve");
|
||||
preserveAttr.Value = "all";
|
||||
assemblyNode.Attributes.Append(preserveAttr);
|
||||
}
|
||||
|
||||
rootNode.AppendChild(assemblyNode);
|
||||
}
|
||||
|
||||
doc.Save(path);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"Generate {path} done.");
|
||||
Debug.Log(doc.OuterXml);
|
||||
}
|
||||
|
||||
public static void Delete(string path) {
|
||||
if (File.Exists(path)) {
|
||||
File.Delete(path);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
Debug.Log($"Delete {path} done.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c63ed7a6afba54761aca6c388df097e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,954 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace TapTap.Common.Editor
|
||||
{
|
||||
public static class Plist
|
||||
{
|
||||
private static List<int> offsetTable = new List<int>();
|
||||
private static List<byte> objectTable = new List<byte>();
|
||||
private static int refCount;
|
||||
private static int objRefSize;
|
||||
private static int offsetByteSize;
|
||||
private static long offsetTableOffset;
|
||||
|
||||
#region Public Functions
|
||||
|
||||
public static object readPlist(string path)
|
||||
{
|
||||
using (FileStream f = new FileStream(path, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
return readPlist(f, plistType.Auto);
|
||||
}
|
||||
}
|
||||
|
||||
public static object readPlistSource(string source)
|
||||
{
|
||||
return readPlist(System.Text.Encoding.UTF8.GetBytes(source));
|
||||
}
|
||||
|
||||
public static object readPlist(byte[] data)
|
||||
{
|
||||
return readPlist(new MemoryStream(data), plistType.Auto);
|
||||
}
|
||||
|
||||
public static plistType getPlistType(Stream stream)
|
||||
{
|
||||
byte[] magicHeader = new byte[8];
|
||||
stream.Read(magicHeader, 0, 8);
|
||||
|
||||
if (BitConverter.ToInt64(magicHeader, 0) == 3472403351741427810)
|
||||
{
|
||||
return plistType.Binary;
|
||||
}
|
||||
else
|
||||
{
|
||||
return plistType.Xml;
|
||||
}
|
||||
}
|
||||
|
||||
public static object readPlist(Stream stream, plistType type)
|
||||
{
|
||||
if (type == plistType.Auto)
|
||||
{
|
||||
type = getPlistType(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
if (type == plistType.Binary)
|
||||
{
|
||||
using (BinaryReader reader = new BinaryReader(stream))
|
||||
{
|
||||
byte[] data = reader.ReadBytes((int) reader.BaseStream.Length);
|
||||
return readBinary(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.XmlResolver = null;
|
||||
xml.Load(stream);
|
||||
return readXml(xml);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeXml(object value, string path)
|
||||
{
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(writeXml(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeXml(object value, Stream stream)
|
||||
{
|
||||
using (StreamWriter writer = new StreamWriter(stream))
|
||||
{
|
||||
writer.Write(writeXml(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static string writeXml(object value)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
|
||||
xmlWriterSettings.Encoding = new System.Text.UTF8Encoding(false);
|
||||
xmlWriterSettings.ConformanceLevel = ConformanceLevel.Document;
|
||||
xmlWriterSettings.Indent = true;
|
||||
|
||||
using (XmlWriter xmlWriter = XmlWriter.Create(ms, xmlWriterSettings))
|
||||
{
|
||||
xmlWriter.WriteStartDocument();
|
||||
//xmlWriter.WriteComment("DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
|
||||
xmlWriter.WriteDocType("plist", "-//Apple Computer//DTD PLIST 1.0//EN",
|
||||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
|
||||
xmlWriter.WriteStartElement("plist");
|
||||
xmlWriter.WriteAttributeString("version", "1.0");
|
||||
compose(value, xmlWriter);
|
||||
xmlWriter.WriteEndElement();
|
||||
xmlWriter.WriteEndDocument();
|
||||
xmlWriter.Flush();
|
||||
xmlWriter.Close();
|
||||
return System.Text.Encoding.UTF8.GetString(ms.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeBinary(object value, string path)
|
||||
{
|
||||
using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create)))
|
||||
{
|
||||
writer.Write(writeBinary(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeBinary(object value, Stream stream)
|
||||
{
|
||||
using (BinaryWriter writer = new BinaryWriter(stream))
|
||||
{
|
||||
writer.Write(writeBinary(value));
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] writeBinary(object value)
|
||||
{
|
||||
offsetTable.Clear();
|
||||
objectTable.Clear();
|
||||
refCount = 0;
|
||||
objRefSize = 0;
|
||||
offsetByteSize = 0;
|
||||
offsetTableOffset = 0;
|
||||
|
||||
//Do not count the root node, subtract by 1
|
||||
int totalRefs = countObject(value) - 1;
|
||||
|
||||
refCount = totalRefs;
|
||||
|
||||
objRefSize = RegulateNullBytes(BitConverter.GetBytes(refCount)).Length;
|
||||
|
||||
composeBinary(value);
|
||||
|
||||
writeBinaryString("bplist00", false);
|
||||
|
||||
offsetTableOffset = (long) objectTable.Count;
|
||||
|
||||
offsetTable.Add(objectTable.Count - 8);
|
||||
|
||||
offsetByteSize = RegulateNullBytes(BitConverter.GetBytes(offsetTable[offsetTable.Count - 1])).Length;
|
||||
|
||||
List<byte> offsetBytes = new List<byte>();
|
||||
|
||||
offsetTable.Reverse();
|
||||
|
||||
for (int i = 0; i < offsetTable.Count; i++)
|
||||
{
|
||||
offsetTable[i] = objectTable.Count - offsetTable[i];
|
||||
byte[] buffer = RegulateNullBytes(BitConverter.GetBytes(offsetTable[i]), offsetByteSize);
|
||||
Array.Reverse(buffer);
|
||||
offsetBytes.AddRange(buffer);
|
||||
}
|
||||
|
||||
objectTable.AddRange(offsetBytes);
|
||||
|
||||
objectTable.AddRange(new byte[6]);
|
||||
objectTable.Add(Convert.ToByte(offsetByteSize));
|
||||
objectTable.Add(Convert.ToByte(objRefSize));
|
||||
|
||||
var a = BitConverter.GetBytes((long) totalRefs + 1);
|
||||
Array.Reverse(a);
|
||||
objectTable.AddRange(a);
|
||||
|
||||
objectTable.AddRange(BitConverter.GetBytes((long) 0));
|
||||
a = BitConverter.GetBytes(offsetTableOffset);
|
||||
Array.Reverse(a);
|
||||
objectTable.AddRange(a);
|
||||
|
||||
return objectTable.ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
|
||||
private static object readXml(XmlDocument xml)
|
||||
{
|
||||
XmlNode rootNode = xml.DocumentElement.ChildNodes[0];
|
||||
return parse(rootNode);
|
||||
}
|
||||
|
||||
private static object readBinary(byte[] data)
|
||||
{
|
||||
offsetTable.Clear();
|
||||
List<byte> offsetTableBytes = new List<byte>();
|
||||
objectTable.Clear();
|
||||
refCount = 0;
|
||||
objRefSize = 0;
|
||||
offsetByteSize = 0;
|
||||
offsetTableOffset = 0;
|
||||
|
||||
List<byte> bList = new List<byte>(data);
|
||||
|
||||
List<byte> trailer = bList.GetRange(bList.Count - 32, 32);
|
||||
|
||||
parseTrailer(trailer);
|
||||
|
||||
objectTable = bList.GetRange(0, (int) offsetTableOffset);
|
||||
|
||||
offsetTableBytes = bList.GetRange((int) offsetTableOffset, bList.Count - (int) offsetTableOffset - 32);
|
||||
|
||||
parseOffsetTable(offsetTableBytes);
|
||||
|
||||
return parseBinary(0);
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> parseDictionary(XmlNode node)
|
||||
{
|
||||
XmlNodeList children = node.ChildNodes;
|
||||
if (children.Count % 2 != 0)
|
||||
{
|
||||
throw new DataMisalignedException("Dictionary elements must have an even number of child nodes");
|
||||
}
|
||||
|
||||
Dictionary<string, object> dict = new Dictionary<string, object>();
|
||||
|
||||
for (int i = 0; i < children.Count; i += 2)
|
||||
{
|
||||
XmlNode keynode = children[i];
|
||||
XmlNode valnode = children[i + 1];
|
||||
|
||||
if (keynode.Name != "key")
|
||||
{
|
||||
throw new ApplicationException("expected a key node");
|
||||
}
|
||||
|
||||
object result = parse(valnode);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
dict.Add(keynode.InnerText, result);
|
||||
}
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private static List<object> parseArray(XmlNode node)
|
||||
{
|
||||
List<object> array = new List<object>();
|
||||
|
||||
foreach (XmlNode child in node.ChildNodes)
|
||||
{
|
||||
object result = parse(child);
|
||||
if (result != null)
|
||||
{
|
||||
array.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
private static void composeArray(List<object> value, XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("array");
|
||||
foreach (object obj in value)
|
||||
{
|
||||
compose(obj, writer);
|
||||
}
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
private static object parse(XmlNode node)
|
||||
{
|
||||
switch (node.Name)
|
||||
{
|
||||
case "dict":
|
||||
return parseDictionary(node);
|
||||
case "array":
|
||||
return parseArray(node);
|
||||
case "string":
|
||||
return node.InnerText;
|
||||
case "integer":
|
||||
// int result;
|
||||
//int.TryParse(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo, out result);
|
||||
return Convert.ToInt32(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
case "real":
|
||||
return Convert.ToDouble(node.InnerText, System.Globalization.NumberFormatInfo.InvariantInfo);
|
||||
case "false":
|
||||
return false;
|
||||
case "true":
|
||||
return true;
|
||||
case "null":
|
||||
return null;
|
||||
case "date":
|
||||
return XmlConvert.ToDateTime(node.InnerText, XmlDateTimeSerializationMode.Utc);
|
||||
case "data":
|
||||
return Convert.FromBase64String(node.InnerText);
|
||||
}
|
||||
|
||||
throw new ApplicationException(String.Format("Plist Node `{0}' is not supported", node.Name));
|
||||
}
|
||||
|
||||
private static void compose(object value, XmlWriter writer)
|
||||
{
|
||||
if (value == null || value is string)
|
||||
{
|
||||
writer.WriteElementString("string", value as string);
|
||||
}
|
||||
else if (value is int || value is long)
|
||||
{
|
||||
writer.WriteElementString("integer",
|
||||
((int) value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
else if (value is System.Collections.Generic.Dictionary<string, object> ||
|
||||
value.GetType().ToString().StartsWith("System.Collections.Generic.Dictionary`2[System.String"))
|
||||
{
|
||||
//Convert to Dictionary<string, object>
|
||||
Dictionary<string, object> dic = value as Dictionary<string, object>;
|
||||
if (dic == null)
|
||||
{
|
||||
dic = new Dictionary<string, object>();
|
||||
IDictionary idic = (IDictionary) value;
|
||||
foreach (var key in idic.Keys)
|
||||
{
|
||||
dic.Add(key.ToString(), idic[key]);
|
||||
}
|
||||
}
|
||||
|
||||
writeDictionaryValues(dic, writer);
|
||||
}
|
||||
else if (value is List<object>)
|
||||
{
|
||||
composeArray((List<object>) value, writer);
|
||||
}
|
||||
else if (value is byte[])
|
||||
{
|
||||
writer.WriteElementString("data", Convert.ToBase64String((Byte[]) value));
|
||||
}
|
||||
else if (value is float || value is double)
|
||||
{
|
||||
writer.WriteElementString("real",
|
||||
((double) value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
else if (value is DateTime)
|
||||
{
|
||||
DateTime time = (DateTime) value;
|
||||
string theString = XmlConvert.ToString(time, XmlDateTimeSerializationMode.Utc);
|
||||
writer.WriteElementString("date", theString); //, "yyyy-MM-ddTHH:mm:ssZ"));
|
||||
}
|
||||
else if (value is bool)
|
||||
{
|
||||
writer.WriteElementString(value.ToString().ToLower(), "");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(String.Format("Value type '{0}' is unhandled", value.GetType().ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeDictionaryValues(Dictionary<string, object> dictionary, XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("dict");
|
||||
foreach (string key in dictionary.Keys)
|
||||
{
|
||||
object value = dictionary[key];
|
||||
writer.WriteElementString("key", key);
|
||||
compose(value, writer);
|
||||
}
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
private static int countObject(object value)
|
||||
{
|
||||
int count = 0;
|
||||
switch (value.GetType().ToString())
|
||||
{
|
||||
case "System.Collections.Generic.Dictionary`2[System.String,System.Object]":
|
||||
Dictionary<string, object> dict = (Dictionary<string, object>) value;
|
||||
foreach (string key in dict.Keys)
|
||||
{
|
||||
count += countObject(dict[key]);
|
||||
}
|
||||
|
||||
count += dict.Keys.Count;
|
||||
count++;
|
||||
break;
|
||||
case "System.Collections.Generic.List`1[System.Object]":
|
||||
List<object> list = (List<object>) value;
|
||||
foreach (object obj in list)
|
||||
{
|
||||
count += countObject(obj);
|
||||
}
|
||||
|
||||
count++;
|
||||
break;
|
||||
default:
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryDictionary(Dictionary<string, object> dictionary)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
List<byte> header = new List<byte>();
|
||||
List<int> refs = new List<int>();
|
||||
for (int i = dictionary.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var o = new object[dictionary.Count];
|
||||
dictionary.Values.CopyTo(o, 0);
|
||||
composeBinary(o[i]);
|
||||
offsetTable.Add(objectTable.Count);
|
||||
refs.Add(refCount);
|
||||
refCount--;
|
||||
}
|
||||
|
||||
for (int i = dictionary.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var o = new string[dictionary.Count];
|
||||
dictionary.Keys.CopyTo(o, 0);
|
||||
composeBinary(o[i]); //);
|
||||
offsetTable.Add(objectTable.Count);
|
||||
refs.Add(refCount);
|
||||
refCount--;
|
||||
}
|
||||
|
||||
if (dictionary.Count < 15)
|
||||
{
|
||||
header.Add(Convert.ToByte(0xD0 | Convert.ToByte(dictionary.Count)));
|
||||
}
|
||||
else
|
||||
{
|
||||
header.Add(0xD0 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(dictionary.Count, false));
|
||||
}
|
||||
|
||||
|
||||
foreach (int val in refs)
|
||||
{
|
||||
byte[] refBuffer = RegulateNullBytes(BitConverter.GetBytes(val), objRefSize);
|
||||
Array.Reverse(refBuffer);
|
||||
buffer.InsertRange(0, refBuffer);
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] composeBinaryArray(List<object> objects)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
List<byte> header = new List<byte>();
|
||||
List<int> refs = new List<int>();
|
||||
|
||||
for (int i = objects.Count - 1; i >= 0; i--)
|
||||
{
|
||||
composeBinary(objects[i]);
|
||||
offsetTable.Add(objectTable.Count);
|
||||
refs.Add(refCount);
|
||||
refCount--;
|
||||
}
|
||||
|
||||
if (objects.Count < 15)
|
||||
{
|
||||
header.Add(Convert.ToByte(0xA0 | Convert.ToByte(objects.Count)));
|
||||
}
|
||||
else
|
||||
{
|
||||
header.Add(0xA0 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(objects.Count, false));
|
||||
}
|
||||
|
||||
foreach (int val in refs)
|
||||
{
|
||||
byte[] refBuffer = RegulateNullBytes(BitConverter.GetBytes(val), objRefSize);
|
||||
Array.Reverse(refBuffer);
|
||||
buffer.InsertRange(0, refBuffer);
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] composeBinary(object obj)
|
||||
{
|
||||
byte[] value;
|
||||
switch (obj.GetType().ToString())
|
||||
{
|
||||
case "System.Collections.Generic.Dictionary`2[System.String,System.Object]":
|
||||
value = writeBinaryDictionary((Dictionary<string, object>) obj);
|
||||
return value;
|
||||
|
||||
case "System.Collections.Generic.List`1[System.Object]":
|
||||
value = composeBinaryArray((List<object>) obj);
|
||||
return value;
|
||||
|
||||
case "System.Byte[]":
|
||||
value = writeBinaryByteArray((byte[]) obj);
|
||||
return value;
|
||||
|
||||
case "System.Double":
|
||||
value = writeBinaryDouble((double) obj);
|
||||
return value;
|
||||
|
||||
case "System.Int32":
|
||||
value = writeBinaryInteger((int) obj, true);
|
||||
return value;
|
||||
|
||||
case "System.String":
|
||||
value = writeBinaryString((string) obj, true);
|
||||
return value;
|
||||
|
||||
case "System.DateTime":
|
||||
value = writeBinaryDate((DateTime) obj);
|
||||
return value;
|
||||
|
||||
case "System.Boolean":
|
||||
value = writeBinaryBool((bool) obj);
|
||||
return value;
|
||||
|
||||
default:
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] writeBinaryDate(DateTime obj)
|
||||
{
|
||||
List<byte> buffer =
|
||||
new List<byte>(RegulateNullBytes(BitConverter.GetBytes(PlistDateConverter.ConvertToAppleTimeStamp(obj)),
|
||||
8));
|
||||
buffer.Reverse();
|
||||
buffer.Insert(0, 0x33);
|
||||
objectTable.InsertRange(0, buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] writeBinaryBool(bool obj)
|
||||
{
|
||||
List<byte> buffer = new List<byte>(new byte[1] {(bool) obj ? (byte) 9 : (byte) 8});
|
||||
objectTable.InsertRange(0, buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryInteger(int value, bool write)
|
||||
{
|
||||
List<byte> buffer = new List<byte>(BitConverter.GetBytes((long) value));
|
||||
buffer = new List<byte>(RegulateNullBytes(buffer.ToArray()));
|
||||
while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
|
||||
buffer.Add(0);
|
||||
int header = 0x10 | (int) (Math.Log(buffer.Count) / Math.Log(2));
|
||||
|
||||
buffer.Reverse();
|
||||
|
||||
buffer.Insert(0, Convert.ToByte(header));
|
||||
|
||||
if (write)
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryDouble(double value)
|
||||
{
|
||||
List<byte> buffer = new List<byte>(RegulateNullBytes(BitConverter.GetBytes(value), 4));
|
||||
while (buffer.Count != Math.Pow(2, Math.Log(buffer.Count) / Math.Log(2)))
|
||||
buffer.Add(0);
|
||||
int header = 0x20 | (int) (Math.Log(buffer.Count) / Math.Log(2));
|
||||
|
||||
buffer.Reverse();
|
||||
|
||||
buffer.Insert(0, Convert.ToByte(header));
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryByteArray(byte[] value)
|
||||
{
|
||||
List<byte> buffer = new List<byte>(value);
|
||||
List<byte> header = new List<byte>();
|
||||
if (value.Length < 15)
|
||||
{
|
||||
header.Add(Convert.ToByte(0x40 | Convert.ToByte(value.Length)));
|
||||
}
|
||||
else
|
||||
{
|
||||
header.Add(0x40 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(buffer.Count, false));
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] writeBinaryString(string value, bool head)
|
||||
{
|
||||
List<byte> buffer = new List<byte>();
|
||||
List<byte> header = new List<byte>();
|
||||
foreach (char chr in value.ToCharArray())
|
||||
buffer.Add(Convert.ToByte(chr));
|
||||
|
||||
if (head)
|
||||
{
|
||||
if (value.Length < 15)
|
||||
{
|
||||
header.Add(Convert.ToByte(0x50 | Convert.ToByte(value.Length)));
|
||||
}
|
||||
else
|
||||
{
|
||||
header.Add(0x50 | 0xf);
|
||||
header.AddRange(writeBinaryInteger(buffer.Count, false));
|
||||
}
|
||||
}
|
||||
|
||||
buffer.InsertRange(0, header);
|
||||
|
||||
objectTable.InsertRange(0, buffer);
|
||||
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] RegulateNullBytes(byte[] value)
|
||||
{
|
||||
return RegulateNullBytes(value, 1);
|
||||
}
|
||||
|
||||
private static byte[] RegulateNullBytes(byte[] value, int minBytes)
|
||||
{
|
||||
Array.Reverse(value);
|
||||
List<byte> bytes = new List<byte>(value);
|
||||
for (int i = 0; i < bytes.Count; i++)
|
||||
{
|
||||
if (bytes[i] == 0 && bytes.Count > minBytes)
|
||||
{
|
||||
bytes.Remove(bytes[i]);
|
||||
i--;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytes.Count < minBytes)
|
||||
{
|
||||
int dist = minBytes - bytes.Count;
|
||||
for (int i = 0; i < dist; i++)
|
||||
bytes.Insert(0, 0);
|
||||
}
|
||||
|
||||
value = bytes.ToArray();
|
||||
Array.Reverse(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private static void parseTrailer(List<byte> trailer)
|
||||
{
|
||||
offsetByteSize = BitConverter.ToInt32(RegulateNullBytes(trailer.GetRange(6, 1).ToArray(), 4), 0);
|
||||
objRefSize = BitConverter.ToInt32(RegulateNullBytes(trailer.GetRange(7, 1).ToArray(), 4), 0);
|
||||
byte[] refCountBytes = trailer.GetRange(12, 4).ToArray();
|
||||
Array.Reverse(refCountBytes);
|
||||
refCount = BitConverter.ToInt32(refCountBytes, 0);
|
||||
byte[] offsetTableOffsetBytes = trailer.GetRange(24, 8).ToArray();
|
||||
Array.Reverse(offsetTableOffsetBytes);
|
||||
offsetTableOffset = BitConverter.ToInt64(offsetTableOffsetBytes, 0);
|
||||
}
|
||||
|
||||
private static void parseOffsetTable(List<byte> offsetTableBytes)
|
||||
{
|
||||
for (int i = 0; i < offsetTableBytes.Count; i += offsetByteSize)
|
||||
{
|
||||
byte[] buffer = offsetTableBytes.GetRange(i, offsetByteSize).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
offsetTable.Add(BitConverter.ToInt32(RegulateNullBytes(buffer, 4), 0));
|
||||
}
|
||||
}
|
||||
|
||||
private static object parseBinaryDictionary(int objRef)
|
||||
{
|
||||
Dictionary<string, object> buffer = new Dictionary<string, object>();
|
||||
List<int> refs = new List<int>();
|
||||
int refCount = 0;
|
||||
|
||||
int refStartPosition;
|
||||
refCount = getCount(offsetTable[objRef], out refStartPosition);
|
||||
|
||||
|
||||
if (refCount < 15)
|
||||
refStartPosition = offsetTable[objRef] + 1;
|
||||
else
|
||||
refStartPosition = offsetTable[objRef] + 2 +
|
||||
RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length;
|
||||
|
||||
for (int i = refStartPosition; i < refStartPosition + refCount * 2 * objRefSize; i += objRefSize)
|
||||
{
|
||||
byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray();
|
||||
Array.Reverse(refBuffer);
|
||||
refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0));
|
||||
}
|
||||
|
||||
for (int i = 0; i < refCount; i++)
|
||||
{
|
||||
buffer.Add((string) parseBinary(refs[i]), parseBinary(refs[i + refCount]));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static object parseBinaryArray(int objRef)
|
||||
{
|
||||
List<object> buffer = new List<object>();
|
||||
List<int> refs = new List<int>();
|
||||
int refCount = 0;
|
||||
|
||||
int refStartPosition;
|
||||
refCount = getCount(offsetTable[objRef], out refStartPosition);
|
||||
|
||||
|
||||
if (refCount < 15)
|
||||
refStartPosition = offsetTable[objRef] + 1;
|
||||
else
|
||||
//The following integer has a header aswell so we increase the refStartPosition by two to account for that.
|
||||
refStartPosition = offsetTable[objRef] + 2 +
|
||||
RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length;
|
||||
|
||||
for (int i = refStartPosition; i < refStartPosition + refCount * objRefSize; i += objRefSize)
|
||||
{
|
||||
byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray();
|
||||
Array.Reverse(refBuffer);
|
||||
refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0));
|
||||
}
|
||||
|
||||
for (int i = 0; i < refCount; i++)
|
||||
{
|
||||
buffer.Add(parseBinary(refs[i]));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static int getCount(int bytePosition, out int newBytePosition)
|
||||
{
|
||||
byte headerByte = objectTable[bytePosition];
|
||||
byte headerByteTrail = Convert.ToByte(headerByte & 0xf);
|
||||
int count;
|
||||
if (headerByteTrail < 15)
|
||||
{
|
||||
count = headerByteTrail;
|
||||
newBytePosition = bytePosition + 1;
|
||||
}
|
||||
else
|
||||
count = (int) parseBinaryInt(bytePosition + 1, out newBytePosition);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private static object parseBinary(int objRef)
|
||||
{
|
||||
byte header = objectTable[offsetTable[objRef]];
|
||||
switch (header & 0xF0)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
//If the byte is
|
||||
//0 return null
|
||||
//9 return true
|
||||
//8 return false
|
||||
return (objectTable[offsetTable[objRef]] == 0)
|
||||
? (object) null
|
||||
: ((objectTable[offsetTable[objRef]] == 9) ? true : false);
|
||||
}
|
||||
case 0x10:
|
||||
{
|
||||
return parseBinaryInt(offsetTable[objRef]);
|
||||
}
|
||||
case 0x20:
|
||||
{
|
||||
return parseBinaryReal(offsetTable[objRef]);
|
||||
}
|
||||
case 0x30:
|
||||
{
|
||||
return parseBinaryDate(offsetTable[objRef]);
|
||||
}
|
||||
case 0x40:
|
||||
{
|
||||
return parseBinaryByteArray(offsetTable[objRef]);
|
||||
}
|
||||
case 0x50: //String ASCII
|
||||
{
|
||||
return parseBinaryAsciiString(offsetTable[objRef]);
|
||||
}
|
||||
case 0x60: //String Unicode
|
||||
{
|
||||
return parseBinaryUnicodeString(offsetTable[objRef]);
|
||||
}
|
||||
case 0xD0:
|
||||
{
|
||||
return parseBinaryDictionary(objRef);
|
||||
}
|
||||
case 0xA0:
|
||||
{
|
||||
return parseBinaryArray(objRef);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("This type is not supported");
|
||||
}
|
||||
|
||||
public static object parseBinaryDate(int headerPosition)
|
||||
{
|
||||
byte[] buffer = objectTable.GetRange(headerPosition + 1, 8).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
double appleTime = BitConverter.ToDouble(buffer, 0);
|
||||
DateTime result = PlistDateConverter.ConvertFromAppleTimeStamp(appleTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static object parseBinaryInt(int headerPosition)
|
||||
{
|
||||
int output;
|
||||
return parseBinaryInt(headerPosition, out output);
|
||||
}
|
||||
|
||||
private static object parseBinaryInt(int headerPosition, out int newHeaderPosition)
|
||||
{
|
||||
byte header = objectTable[headerPosition];
|
||||
int byteCount = (int) Math.Pow(2, header & 0xf);
|
||||
byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
//Add one to account for the header byte
|
||||
newHeaderPosition = headerPosition + byteCount + 1;
|
||||
return BitConverter.ToInt32(RegulateNullBytes(buffer, 4), 0);
|
||||
}
|
||||
|
||||
private static object parseBinaryReal(int headerPosition)
|
||||
{
|
||||
byte header = objectTable[headerPosition];
|
||||
int byteCount = (int) Math.Pow(2, header & 0xf);
|
||||
byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
|
||||
Array.Reverse(buffer);
|
||||
|
||||
return BitConverter.ToDouble(RegulateNullBytes(buffer, 8), 0);
|
||||
}
|
||||
|
||||
private static object parseBinaryAsciiString(int headerPosition)
|
||||
{
|
||||
int charStartPosition;
|
||||
int charCount = getCount(headerPosition, out charStartPosition);
|
||||
|
||||
var buffer = objectTable.GetRange(charStartPosition, charCount);
|
||||
return buffer.Count > 0 ? Encoding.ASCII.GetString(buffer.ToArray()) : string.Empty;
|
||||
}
|
||||
|
||||
private static object parseBinaryUnicodeString(int headerPosition)
|
||||
{
|
||||
int charStartPosition;
|
||||
int charCount = getCount(headerPosition, out charStartPosition);
|
||||
charCount = charCount * 2;
|
||||
|
||||
byte[] buffer = new byte[charCount];
|
||||
byte one, two;
|
||||
|
||||
for (int i = 0; i < charCount; i += 2)
|
||||
{
|
||||
one = objectTable.GetRange(charStartPosition + i, 1)[0];
|
||||
two = objectTable.GetRange(charStartPosition + i + 1, 1)[0];
|
||||
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
buffer[i] = two;
|
||||
buffer[i + 1] = one;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[i] = one;
|
||||
buffer[i + 1] = two;
|
||||
}
|
||||
}
|
||||
|
||||
return Encoding.Unicode.GetString(buffer);
|
||||
}
|
||||
|
||||
private static object parseBinaryByteArray(int headerPosition)
|
||||
{
|
||||
int byteStartPosition;
|
||||
int byteCount = getCount(headerPosition, out byteStartPosition);
|
||||
return objectTable.GetRange(byteStartPosition, byteCount).ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum plistType
|
||||
{
|
||||
Auto,
|
||||
Binary,
|
||||
Xml
|
||||
}
|
||||
|
||||
public static class PlistDateConverter
|
||||
{
|
||||
public static long timeDifference = 978307200;
|
||||
|
||||
public static long GetAppleTime(long unixTime)
|
||||
{
|
||||
return unixTime - timeDifference;
|
||||
}
|
||||
|
||||
public static long GetUnixTime(long appleTime)
|
||||
{
|
||||
return appleTime + timeDifference;
|
||||
}
|
||||
|
||||
public static DateTime ConvertFromAppleTimeStamp(double timestamp)
|
||||
{
|
||||
DateTime origin = new DateTime(2001, 1, 1, 0, 0, 0, 0);
|
||||
return origin.AddSeconds(timestamp);
|
||||
}
|
||||
|
||||
public static double ConvertToAppleTimeStamp(DateTime date)
|
||||
{
|
||||
DateTime begin = new DateTime(2001, 1, 1, 0, 0, 0, 0);
|
||||
TimeSpan diff = date - begin;
|
||||
return Math.Floor(diff.TotalSeconds);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 66eefeda055244c784769597b08e679e
|
||||
timeCreated: 1617120740
|
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
|
||||
namespace TapTap.Common.Editor {
|
||||
/// <summary>
|
||||
/// 模块 SDK 生成 link.xml 构建过程
|
||||
/// </summary>
|
||||
public abstract class SDKLinkProcessBuild : IPreprocessBuildWithReport, IPostprocessBuildWithReport {
|
||||
/// <summary>
|
||||
/// 执行顺序
|
||||
/// </summary>
|
||||
public abstract int callbackOrder { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 生成 link.xml 路径
|
||||
/// </summary>
|
||||
public abstract string LinkPath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 防止被裁剪的 Assembly
|
||||
/// </summary>
|
||||
public abstract LinkedAssembly[] LinkedAssemblies { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行平台委托
|
||||
/// </summary>
|
||||
public abstract Func<BuildReport, bool> IsTargetPlatform { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 构建时忽略目录,目前主要是 PC 内置浏览器 Vuplex
|
||||
/// </summary>
|
||||
public virtual string[] BuildingIgnorePaths => null;
|
||||
|
||||
/// <summary>
|
||||
/// 构建前处理
|
||||
/// </summary>
|
||||
/// <param name="report"></param>
|
||||
public void OnPreprocessBuild(BuildReport report) {
|
||||
if (!IsTargetPlatform.Invoke(report)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Application.logMessageReceived += OnBuildError;
|
||||
IgnorePaths();
|
||||
|
||||
string linkPath = Path.Combine(Application.dataPath, LinkPath);
|
||||
LinkXMLGenerator.Generate(linkPath, LinkedAssemblies);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建后处理
|
||||
/// </summary>
|
||||
/// <param name="report"></param>
|
||||
public void OnPostprocessBuild(BuildReport report) {
|
||||
if (!IsTargetPlatform.Invoke(report)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Application.logMessageReceived -= OnBuildError;
|
||||
RecoverIgnoredPaths();
|
||||
|
||||
string linkPath = Path.Combine(Application.dataPath, LinkPath);
|
||||
LinkXMLGenerator.Delete(linkPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 错误日志回调
|
||||
/// </summary>
|
||||
/// <param name="condition"></param>
|
||||
/// <param name="stacktrace"></param>
|
||||
/// <param name="logType"></param>
|
||||
private void OnBuildError(string condition, string stacktrace, LogType logType) {
|
||||
// TRICK: 通过捕获错误日志来监听打包错误事件
|
||||
if (logType == LogType.Error) {
|
||||
Application.logMessageReceived -= OnBuildError;
|
||||
RecoverIgnoredPaths();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 忽略目录
|
||||
/// </summary>
|
||||
private void IgnorePaths() {
|
||||
if (BuildingIgnorePaths == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string ignorePath in BuildingIgnorePaths) {
|
||||
if (!Directory.Exists(Path.Combine(Application.dataPath, ignorePath))) {
|
||||
continue;
|
||||
}
|
||||
string ignoreName = Path.GetFileName(ignorePath);
|
||||
AssetDatabase.RenameAsset(Path.Combine("Assets", ignorePath), $"{ignoreName}~");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复目录
|
||||
/// </summary>
|
||||
private void RecoverIgnoredPaths() {
|
||||
if (BuildingIgnorePaths == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string ignorePath in BuildingIgnorePaths) {
|
||||
if (!Directory.Exists(Path.Combine(Application.dataPath, $"{ignorePath}~"))) {
|
||||
continue;
|
||||
}
|
||||
Directory.Move(Path.Combine(Application.dataPath, $"{ignorePath}~"),
|
||||
Path.Combine(Application.dataPath, $"{ignorePath}"));
|
||||
AssetDatabase.ImportAsset(Path.Combine("Assets", ignorePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8566d22eb15da4629a4ae0deae37b0fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,264 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEngine;
|
||||
#if UNITY_IOS
|
||||
using System;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
|
||||
#endif
|
||||
|
||||
namespace TapTap.Common.Editor
|
||||
{
|
||||
public static class TapCommonCompile
|
||||
{
|
||||
#if UNITY_IOS
|
||||
public static string GetProjPath(string path)
|
||||
{
|
||||
return PBXProject.GetPBXProjectPath(path);
|
||||
}
|
||||
|
||||
public static PBXProject ParseProjPath(string path)
|
||||
{
|
||||
var proj = new PBXProject();
|
||||
proj.ReadFromString(File.ReadAllText(path));
|
||||
return proj;
|
||||
}
|
||||
|
||||
public static string GetUnityFrameworkTarget(PBXProject proj)
|
||||
{
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
string target = proj.GetUnityFrameworkTargetGuid();
|
||||
return target;
|
||||
#endif
|
||||
var unityPhoneTarget = proj.TargetGuidByName("Unity-iPhone");
|
||||
return unityPhoneTarget;
|
||||
}
|
||||
|
||||
public static string GetUnityTarget(PBXProject proj)
|
||||
{
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
string target = proj.GetUnityMainTargetGuid();
|
||||
return target;
|
||||
#endif
|
||||
var unityPhoneTarget = proj.TargetGuidByName("Unity-iPhone");
|
||||
return unityPhoneTarget;
|
||||
}
|
||||
|
||||
|
||||
public static bool CheckTarget(string target)
|
||||
{
|
||||
return string.IsNullOrEmpty(target);
|
||||
}
|
||||
|
||||
public static string GetUnityPackagePath(string parentFolder, string unityPackageName) {
|
||||
var request = Client.List(true);
|
||||
while(request.IsCompleted == false) {
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
var pkgs = request.Result;
|
||||
if (pkgs == null)
|
||||
return "";
|
||||
foreach (var pkg in pkgs) {
|
||||
if (pkg.name == unityPackageName) {
|
||||
if (pkg.source == PackageSource.Local)
|
||||
return pkg.resolvedPath;
|
||||
else if (pkg.source == PackageSource.Embedded)
|
||||
return pkg.resolvedPath;
|
||||
else {
|
||||
return pkg.resolvedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static bool HandlerIOSSetting(string path, string appDataPath, string resourceName,
|
||||
string modulePackageName,
|
||||
string moduleName, string[] bundleNames, string target, string projPath, PBXProject proj)
|
||||
{
|
||||
|
||||
var resourcePath = Path.Combine(path, resourceName);
|
||||
|
||||
var parentFolder = Directory.GetParent(appDataPath).FullName;
|
||||
|
||||
Debug.Log($"ProjectFolder path:{parentFolder}");
|
||||
|
||||
if (Directory.Exists(resourcePath))
|
||||
{
|
||||
Directory.Delete(resourcePath, true);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(resourcePath);
|
||||
|
||||
var remotePackagePath = GetUnityPackagePath(parentFolder, modulePackageName);
|
||||
|
||||
var assetLocalPackagePath = TapFileHelper.FilterFileByPrefix(parentFolder + "/Assets/TapTap/", moduleName);
|
||||
|
||||
var localPackagePath = TapFileHelper.FilterFileByPrefix(parentFolder, moduleName);
|
||||
|
||||
var tdsResourcePath = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(remotePackagePath))
|
||||
{
|
||||
tdsResourcePath = remotePackagePath;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(assetLocalPackagePath))
|
||||
{
|
||||
tdsResourcePath = assetLocalPackagePath;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(localPackagePath))
|
||||
{
|
||||
tdsResourcePath = localPackagePath;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(tdsResourcePath)) {
|
||||
throw new Exception(string.Format("Can't find tdsResourcePath with module of : {0}", modulePackageName));
|
||||
}
|
||||
|
||||
tdsResourcePath = $"{tdsResourcePath}/Plugins/iOS/Resource";
|
||||
|
||||
Debug.Log($"Find {moduleName} path:{tdsResourcePath}");
|
||||
|
||||
if (!Directory.Exists(tdsResourcePath)) {
|
||||
throw new Exception(string.Format("Can't Find {0}", tdsResourcePath));
|
||||
}
|
||||
|
||||
TapFileHelper.CopyAndReplaceDirectory(tdsResourcePath, resourcePath);
|
||||
foreach (var name in bundleNames) {
|
||||
var relativePath = GetRelativePath(Path.Combine(resourcePath, name), path);
|
||||
var fileGuid = proj.AddFile(relativePath, relativePath, PBXSourceTree.Source);
|
||||
proj.AddFileToBuild(target, fileGuid);
|
||||
}
|
||||
|
||||
File.WriteAllText(projPath, proj.WriteToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string GetRelativePath(string absolutePath, string rootPath) {
|
||||
if (Directory.Exists(rootPath) && !rootPath.EndsWith(Path.AltDirectorySeparatorChar.ToString())) {
|
||||
rootPath += Path.AltDirectorySeparatorChar;
|
||||
}
|
||||
Uri aboslutePathUri = new Uri(absolutePath);
|
||||
Uri rootPathUri = new Uri(rootPath);
|
||||
var relateivePath = rootPathUri.MakeRelativeUri(aboslutePathUri).ToString();
|
||||
Debug.LogFormat($"[TapCommonCompile] GetRelativePath absolutePath:{absolutePath} rootPath:{rootPath} relateivePath:{relateivePath} ");
|
||||
return relateivePath;
|
||||
}
|
||||
|
||||
public static bool HandlerPlist(string pathToBuildProject, string infoPlistPath, bool macos = false)
|
||||
{
|
||||
// #if UNITY_2020_1_OR_NEWER
|
||||
// var macosXCodePlistPath =
|
||||
// $"{pathToBuildProject}/{PlayerSettings.productName}/Info.plist";
|
||||
// #elif UNITY_2019_1_OR_NEWER
|
||||
// var macosXCodePlistPath =
|
||||
// $"{Path.GetDirectoryName(pathToBuildProject)}/{PlayerSettings.productName}/Info.plist";
|
||||
// #endif
|
||||
|
||||
string plistPath;
|
||||
|
||||
if (pathToBuildProject.EndsWith(".app"))
|
||||
{
|
||||
plistPath = $"{pathToBuildProject}/Contents/Info.plist";
|
||||
}
|
||||
else
|
||||
{
|
||||
var macosXCodePlistPath =
|
||||
$"{Path.GetDirectoryName(pathToBuildProject)}/{PlayerSettings.productName}/Info.plist";
|
||||
if (!File.Exists(macosXCodePlistPath))
|
||||
{
|
||||
macosXCodePlistPath = $"{pathToBuildProject}/{PlayerSettings.productName}/Info.plist";
|
||||
}
|
||||
|
||||
plistPath = !macos
|
||||
? pathToBuildProject + "/Info.plist"
|
||||
: macosXCodePlistPath;
|
||||
}
|
||||
|
||||
Debug.Log($"plist path:{plistPath}");
|
||||
|
||||
var plist = new PlistDocument();
|
||||
plist.ReadFromString(File.ReadAllText(plistPath));
|
||||
var rootDic = plist.root;
|
||||
|
||||
var items = new List<string>
|
||||
{
|
||||
"tapsdk",
|
||||
"tapiosdk",
|
||||
"taptap"
|
||||
};
|
||||
|
||||
if (!(rootDic["LSApplicationQueriesSchemes"] is PlistElementArray plistElementList))
|
||||
{
|
||||
plistElementList = rootDic.CreateArray("LSApplicationQueriesSchemes");
|
||||
}
|
||||
|
||||
foreach (var t in items)
|
||||
{
|
||||
plistElementList.AddString(t);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(infoPlistPath)) return false;
|
||||
var dic = (Dictionary<string, object>) Plist.readPlist(infoPlistPath);
|
||||
var taptapId = "";
|
||||
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (item.Key.Equals("taptap"))
|
||||
{
|
||||
var taptapDic = (Dictionary<string, object>) item.Value;
|
||||
foreach (var taptapItem in taptapDic.Where(taptapItem => taptapItem.Key.Equals("client_id")))
|
||||
{
|
||||
taptapId = (string) taptapItem.Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rootDic.SetString(item.Key, item.Value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//添加url
|
||||
var dict = plist.root.AsDict();
|
||||
if (!(dict["CFBundleURLTypes"] is PlistElementArray array))
|
||||
{
|
||||
array = dict.CreateArray("CFBundleURLTypes");
|
||||
}
|
||||
|
||||
if (!macos)
|
||||
{
|
||||
var dict2 = array.AddDict();
|
||||
dict2.SetString("CFBundleURLName", "TapTap");
|
||||
var array2 = dict2.CreateArray("CFBundleURLSchemes");
|
||||
array2.AddString($"tt{taptapId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var dict2 = array.AddDict();
|
||||
dict2.SetString("CFBundleURLName", "TapWeb");
|
||||
var array2 = dict2.CreateArray("CFBundleURLSchemes");
|
||||
array2.AddString($"open-taptap-{taptapId}");
|
||||
}
|
||||
|
||||
Debug.Log("TapSDK change plist Success");
|
||||
File.WriteAllText(plistPath, plist.WriteToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string GetValueFromPlist(string infoPlistPath, string key)
|
||||
{
|
||||
if (infoPlistPath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var dic = (Dictionary<string, object>) Plist.readPlist(infoPlistPath);
|
||||
return (from item in dic where item.Key.Equals(key) select (string) item.Value).FirstOrDefault();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c5475af505e04119831448fe963f9c2c
|
||||
timeCreated: 1617120740
|
|
@ -0,0 +1,74 @@
|
|||
using System.IO;
|
||||
using UnityEditor;
|
||||
# if UNITY_IOS
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace TapTap.Common.Editor
|
||||
{
|
||||
# if UNITY_IOS
|
||||
public static class TapCommonIOSProcessor
|
||||
{
|
||||
// 添加标签,unity导出工程后自动执行该函数
|
||||
[PostProcessBuild(99)]
|
||||
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
|
||||
{
|
||||
if (buildTarget != BuildTarget.iOS) return;
|
||||
|
||||
// 获得工程路径
|
||||
var projPath = TapCommonCompile.GetProjPath(path);
|
||||
var proj = TapCommonCompile.ParseProjPath(projPath);
|
||||
var target = TapCommonCompile.GetUnityTarget(proj);
|
||||
var unityFrameworkTarget = TapCommonCompile.GetUnityFrameworkTarget(proj);
|
||||
|
||||
if (TapCommonCompile.CheckTarget(target))
|
||||
{
|
||||
Debug.LogError("Unity-iPhone is NUll");
|
||||
return;
|
||||
}
|
||||
|
||||
proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
|
||||
proj.AddBuildProperty(unityFrameworkTarget, "OTHER_LDFLAGS", "-ObjC");
|
||||
|
||||
proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
|
||||
proj.SetBuildProperty(target, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
|
||||
proj.SetBuildProperty(target, "SWIFT_VERSION", "5.0");
|
||||
proj.SetBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
|
||||
|
||||
proj.SetBuildProperty(unityFrameworkTarget, "ENABLE_BITCODE", "NO");
|
||||
proj.SetBuildProperty(unityFrameworkTarget, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
|
||||
proj.SetBuildProperty(unityFrameworkTarget, "SWIFT_VERSION", "5.0");
|
||||
proj.SetBuildProperty(unityFrameworkTarget, "CLANG_ENABLE_MODULES", "YES");
|
||||
|
||||
proj.AddFrameworkToProject(unityFrameworkTarget, "MobileCoreServices.framework", false);
|
||||
proj.AddFrameworkToProject(unityFrameworkTarget, "WebKit.framework", false);
|
||||
proj.AddFrameworkToProject(unityFrameworkTarget, "Security.framework", false);
|
||||
proj.AddFrameworkToProject(unityFrameworkTarget, "SystemConfiguration.framework", false);
|
||||
proj.AddFrameworkToProject(unityFrameworkTarget, "CoreTelephony.framework", false);
|
||||
proj.AddFrameworkToProject(unityFrameworkTarget, "SystemConfiguration.framework", false);
|
||||
|
||||
proj.AddFileToBuild(unityFrameworkTarget,
|
||||
proj.AddFile("usr/lib/libc++.tbd", "libc++.tbd", PBXSourceTree.Sdk));
|
||||
|
||||
proj.AddFileToBuild(unityFrameworkTarget,
|
||||
proj.AddFile("usr/lib/libsqlite3.tbd", "libsqlite3.tbd", PBXSourceTree.Sdk));
|
||||
|
||||
if (TapCommonCompile.HandlerIOSSetting(path,
|
||||
Application.dataPath,
|
||||
"TapCommonResource",
|
||||
"com.taptap.tds.common",
|
||||
"Common",
|
||||
new[] {"TapCommonResource.bundle"},
|
||||
target, projPath, proj))
|
||||
{
|
||||
Debug.Log("TapCommon add Bundle Success!");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.LogError("TapCommon add Bundle Failed!");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 28d4870389ed406eac7c8849da60c644
|
||||
timeCreated: 1617120740
|
|
@ -0,0 +1,168 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TapTap.Common.Editor
|
||||
{
|
||||
public class TapFileHelper : System.IDisposable
|
||||
{
|
||||
private string filePath;
|
||||
|
||||
public TapFileHelper(string fPath)
|
||||
{
|
||||
filePath = fPath;
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
Debug.LogError(filePath + "路径下文件不存在");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteBelow(string below, string text)
|
||||
{
|
||||
StreamReader streamReader = new StreamReader(filePath);
|
||||
string all = streamReader.ReadToEnd();
|
||||
streamReader.Close();
|
||||
int beginIndex = all.IndexOf(below, StringComparison.Ordinal);
|
||||
if (beginIndex == -1)
|
||||
{
|
||||
Debug.LogError(filePath + "中没有找到字符串" + below);
|
||||
return;
|
||||
}
|
||||
|
||||
int endIndex = all.LastIndexOf("\n", beginIndex + below.Length, StringComparison.Ordinal);
|
||||
all = all.Substring(0, endIndex) + "\n" + text + "\n" + all.Substring(endIndex);
|
||||
StreamWriter streamWriter = new StreamWriter(filePath);
|
||||
streamWriter.Write(all);
|
||||
streamWriter.Close();
|
||||
}
|
||||
|
||||
public void Replace(string below, string newText)
|
||||
{
|
||||
StreamReader streamReader = new StreamReader(filePath);
|
||||
string all = streamReader.ReadToEnd();
|
||||
streamReader.Close();
|
||||
int beginIndex = all.IndexOf(below, StringComparison.Ordinal);
|
||||
if (beginIndex == -1)
|
||||
{
|
||||
Debug.LogError(filePath + "中没有找到字符串" + below);
|
||||
return;
|
||||
}
|
||||
|
||||
all = all.Replace(below, newText);
|
||||
StreamWriter streamWriter = new StreamWriter(filePath);
|
||||
streamWriter.Write(all);
|
||||
streamWriter.Close();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public static void CopyAndReplaceDirectory(string srcPath, string dstPath)
|
||||
{
|
||||
if (Directory.Exists(dstPath))
|
||||
Directory.Delete(dstPath, true);
|
||||
if (File.Exists(dstPath))
|
||||
File.Delete(dstPath);
|
||||
|
||||
Directory.CreateDirectory(dstPath);
|
||||
|
||||
foreach (var file in Directory.GetFiles(srcPath))
|
||||
File.Copy(file, Path.Combine(dstPath, Path.GetFileName(file)));
|
||||
|
||||
foreach (var dir in Directory.GetDirectories(srcPath))
|
||||
CopyAndReplaceDirectory(dir, Path.Combine(dstPath, Path.GetFileName(dir)));
|
||||
}
|
||||
|
||||
|
||||
public static void DeleteFileBySuffix(string dir, string[] suffix)
|
||||
{
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var file in Directory.GetFiles(dir))
|
||||
{
|
||||
foreach (var suffixName in suffix)
|
||||
{
|
||||
if (file.Contains(suffixName))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string FilterFileByPrefix(string srcPath, string filterName)
|
||||
{
|
||||
if (!Directory.Exists(srcPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var dir in Directory.GetDirectories(srcPath))
|
||||
{
|
||||
string fileName = Path.GetFileName(dir);
|
||||
if (fileName.StartsWith(filterName))
|
||||
{
|
||||
return Path.Combine(srcPath, Path.GetFileName(dir));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FilterFileBySuffix(string srcPath, string suffix)
|
||||
{
|
||||
if (!Directory.Exists(srcPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var dir in Directory.GetDirectories(srcPath))
|
||||
{
|
||||
string fileName = Path.GetFileName(dir);
|
||||
if (fileName.StartsWith(suffix))
|
||||
{
|
||||
return Path.Combine(srcPath, Path.GetFileName(dir));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FileInfo RecursionFilterFile(string dir, string fileName)
|
||||
{
|
||||
List<FileInfo> fileInfoList = new List<FileInfo>();
|
||||
Director(dir, fileInfoList);
|
||||
foreach (FileInfo item in fileInfoList)
|
||||
{
|
||||
if (fileName.Equals(item.Name))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Director(string dir, List<FileInfo> list)
|
||||
{
|
||||
DirectoryInfo d = new DirectoryInfo(dir);
|
||||
FileInfo[] files = d.GetFiles();
|
||||
DirectoryInfo[] directs = d.GetDirectories();
|
||||
foreach (FileInfo f in files)
|
||||
{
|
||||
list.Add(f);
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo dd in directs)
|
||||
{
|
||||
Director(dd.FullName, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d1556fcb81944af6a42170d3e1c99269
|
||||
timeCreated: 1617120740
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "TapTap.Common.Editor",
|
||||
"references": [
|
||||
"GUID:0b3f64ec33f5b4da98a17367a35b82f2"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 616cea76def2d4f059b94440fc8cc03d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d7b757cf9569ee1469081df1e8e79931
|
||||
folderAsset: yes
|
||||
timeCreated: 1533042733
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,267 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="ScrollViewEditor.cs" company="AillieoTech">
|
||||
// Copyright (c) AillieoTech. All rights reserved.
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace TapTap.UI.AillieoTech
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[CustomEditor(typeof(ScrollView))]
|
||||
public class ScrollViewEditor : ScrollRectEditor
|
||||
{
|
||||
private const string bgPath = "UI/Skin/Background.psd";
|
||||
private const string spritePath = "UI/Skin/UISprite.psd";
|
||||
private const string maskPath = "UI/Skin/UIMask.psd";
|
||||
private static Color panelColor = new Color(1f, 1f, 1f, 0.392f);
|
||||
private static Color defaultSelectableColor = new Color(1f, 1f, 1f, 1f);
|
||||
private static Vector2 thinElementSize = new Vector2(160f, 20f);
|
||||
private static Action<GameObject, MenuCommand> PlaceUIElementRoot;
|
||||
|
||||
private SerializedProperty itemTemplate;
|
||||
private SerializedProperty poolSize;
|
||||
private SerializedProperty defaultItemSize;
|
||||
private SerializedProperty layoutType;
|
||||
|
||||
private GUIStyle cachedCaption;
|
||||
|
||||
private GUIStyle caption
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.cachedCaption == null)
|
||||
{
|
||||
this.cachedCaption = new GUIStyle { richText = true, alignment = TextAnchor.MiddleCenter };
|
||||
}
|
||||
|
||||
return this.cachedCaption;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
this.serializedObject.Update();
|
||||
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
EditorGUILayout.LabelField("<b>Additional configs</b>", this.caption);
|
||||
EditorGUILayout.Space();
|
||||
this.DrawConfigInfo();
|
||||
this.serializedObject.ApplyModifiedProperties();
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
EditorGUILayout.LabelField("<b>For original ScrollRect</b>", this.caption);
|
||||
EditorGUILayout.Space();
|
||||
base.OnInspectorGUI();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
protected static void InternalAddScrollView<T>(MenuCommand menuCommand)
|
||||
where T : ScrollView
|
||||
{
|
||||
GetPrivateMethodByReflection();
|
||||
|
||||
GameObject root = CreateUIElementRoot(typeof(T).Name, new Vector2(200, 200));
|
||||
PlaceUIElementRoot?.Invoke(root, menuCommand);
|
||||
|
||||
GameObject viewport = CreateUIObject("Viewport", root);
|
||||
GameObject content = CreateUIObject("Content", viewport);
|
||||
|
||||
var parent = menuCommand.context as GameObject;
|
||||
if (parent != null)
|
||||
{
|
||||
root.transform.SetParent(parent.transform, false);
|
||||
}
|
||||
|
||||
Selection.activeGameObject = root;
|
||||
|
||||
GameObject hScrollbar = CreateScrollbar();
|
||||
hScrollbar.name = "Scrollbar Horizontal";
|
||||
hScrollbar.transform.SetParent(root.transform, false);
|
||||
RectTransform hScrollbarRT = hScrollbar.GetComponent<RectTransform>();
|
||||
hScrollbarRT.anchorMin = Vector2.zero;
|
||||
hScrollbarRT.anchorMax = Vector2.right;
|
||||
hScrollbarRT.pivot = Vector2.zero;
|
||||
hScrollbarRT.sizeDelta = new Vector2(0, hScrollbarRT.sizeDelta.y);
|
||||
|
||||
GameObject vScrollbar = CreateScrollbar();
|
||||
vScrollbar.name = "Scrollbar Vertical";
|
||||
vScrollbar.transform.SetParent(root.transform, false);
|
||||
vScrollbar.GetComponent<Scrollbar>().SetDirection(Scrollbar.Direction.BottomToTop, true);
|
||||
RectTransform vScrollbarRT = vScrollbar.GetComponent<RectTransform>();
|
||||
vScrollbarRT.anchorMin = Vector2.right;
|
||||
vScrollbarRT.anchorMax = Vector2.one;
|
||||
vScrollbarRT.pivot = Vector2.one;
|
||||
vScrollbarRT.sizeDelta = new Vector2(vScrollbarRT.sizeDelta.x, 0);
|
||||
|
||||
RectTransform viewportRect = viewport.GetComponent<RectTransform>();
|
||||
viewportRect.anchorMin = Vector2.zero;
|
||||
viewportRect.anchorMax = Vector2.one;
|
||||
viewportRect.sizeDelta = Vector2.zero;
|
||||
viewportRect.pivot = Vector2.up;
|
||||
|
||||
RectTransform contentRect = content.GetComponent<RectTransform>();
|
||||
contentRect.anchorMin = Vector2.up;
|
||||
contentRect.anchorMax = Vector2.one;
|
||||
contentRect.sizeDelta = new Vector2(0, 300);
|
||||
contentRect.pivot = Vector2.up;
|
||||
|
||||
ScrollView scrollRect = root.AddComponent<T>();
|
||||
scrollRect.content = contentRect;
|
||||
scrollRect.viewport = viewportRect;
|
||||
scrollRect.horizontalScrollbar = hScrollbar.GetComponent<Scrollbar>();
|
||||
scrollRect.verticalScrollbar = vScrollbar.GetComponent<Scrollbar>();
|
||||
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
||||
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
||||
scrollRect.horizontalScrollbarSpacing = -3;
|
||||
scrollRect.verticalScrollbarSpacing = -3;
|
||||
|
||||
Image rootImage = root.AddComponent<Image>();
|
||||
rootImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(bgPath);
|
||||
rootImage.type = Image.Type.Sliced;
|
||||
rootImage.color = panelColor;
|
||||
|
||||
Mask viewportMask = viewport.AddComponent<Mask>();
|
||||
viewportMask.showMaskGraphic = false;
|
||||
|
||||
Image viewportImage = viewport.AddComponent<Image>();
|
||||
viewportImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(maskPath);
|
||||
viewportImage.type = Image.Type.Sliced;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
this.itemTemplate = this.serializedObject.FindProperty("itemTemplate");
|
||||
this.poolSize = this.serializedObject.FindProperty("poolSize");
|
||||
this.defaultItemSize = this.serializedObject.FindProperty("defaultItemSize");
|
||||
this.layoutType = this.serializedObject.FindProperty("layoutType");
|
||||
}
|
||||
|
||||
protected virtual void DrawConfigInfo()
|
||||
{
|
||||
EditorGUILayout.PropertyField(this.itemTemplate);
|
||||
EditorGUILayout.PropertyField(this.poolSize);
|
||||
EditorGUILayout.PropertyField(this.defaultItemSize);
|
||||
this.layoutType.intValue = (int)(ScrollView.ItemLayoutType)EditorGUILayout.EnumPopup("layoutType", (ScrollView.ItemLayoutType)this.layoutType.intValue);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/UI/DynamicScrollView", false, 90)]
|
||||
private static void AddScrollView(MenuCommand menuCommand)
|
||||
{
|
||||
InternalAddScrollView<ScrollView>(menuCommand);
|
||||
}
|
||||
|
||||
private static GameObject CreateScrollbar()
|
||||
{
|
||||
// Create GOs Hierarchy
|
||||
GameObject scrollbarRoot = CreateUIElementRoot("Scrollbar", thinElementSize);
|
||||
GameObject sliderArea = CreateUIObject("Sliding Area", scrollbarRoot);
|
||||
GameObject handle = CreateUIObject("Handle", sliderArea);
|
||||
|
||||
Image bgImage = scrollbarRoot.AddComponent<Image>();
|
||||
bgImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(bgPath);
|
||||
bgImage.type = Image.Type.Sliced;
|
||||
bgImage.color = defaultSelectableColor;
|
||||
|
||||
Image handleImage = handle.AddComponent<Image>();
|
||||
handleImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(spritePath);
|
||||
handleImage.type = Image.Type.Sliced;
|
||||
handleImage.color = defaultSelectableColor;
|
||||
|
||||
RectTransform sliderAreaRect = sliderArea.GetComponent<RectTransform>();
|
||||
sliderAreaRect.sizeDelta = new Vector2(-20, -20);
|
||||
sliderAreaRect.anchorMin = Vector2.zero;
|
||||
sliderAreaRect.anchorMax = Vector2.one;
|
||||
|
||||
RectTransform handleRect = handle.GetComponent<RectTransform>();
|
||||
handleRect.sizeDelta = new Vector2(20, 20);
|
||||
|
||||
Scrollbar scrollbar = scrollbarRoot.AddComponent<Scrollbar>();
|
||||
scrollbar.handleRect = handleRect;
|
||||
scrollbar.targetGraphic = handleImage;
|
||||
SetDefaultColorTransitionValues(scrollbar);
|
||||
|
||||
return scrollbarRoot;
|
||||
}
|
||||
|
||||
private static GameObject CreateUIElementRoot(string name, Vector2 size)
|
||||
{
|
||||
var child = new GameObject(name);
|
||||
RectTransform rectTransform = child.AddComponent<RectTransform>();
|
||||
rectTransform.sizeDelta = size;
|
||||
return child;
|
||||
}
|
||||
|
||||
private static GameObject CreateUIObject(string name, GameObject parent)
|
||||
{
|
||||
var go = new GameObject(name);
|
||||
go.AddComponent<RectTransform>();
|
||||
SetParentAndAlign(go, parent);
|
||||
return go;
|
||||
}
|
||||
|
||||
private static void SetParentAndAlign(GameObject child, GameObject parent)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
child.transform.SetParent(parent.transform, false);
|
||||
SetLayerRecursively(child, parent.layer);
|
||||
}
|
||||
|
||||
private static void SetLayerRecursively(GameObject go, int layer)
|
||||
{
|
||||
go.layer = layer;
|
||||
Transform t = go.transform;
|
||||
for (var i = 0; i < t.childCount; i++)
|
||||
{
|
||||
SetLayerRecursively(t.GetChild(i).gameObject, layer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetDefaultColorTransitionValues(Selectable slider)
|
||||
{
|
||||
ColorBlock colors = slider.colors;
|
||||
colors.highlightedColor = new Color(0.882f, 0.882f, 0.882f);
|
||||
colors.pressedColor = new Color(0.698f, 0.698f, 0.698f);
|
||||
colors.disabledColor = new Color(0.521f, 0.521f, 0.521f);
|
||||
}
|
||||
|
||||
private static void GetPrivateMethodByReflection()
|
||||
{
|
||||
if (PlaceUIElementRoot == null)
|
||||
{
|
||||
Assembly uiEditorAssembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.FirstOrDefault(asm => asm.GetName().Name == "UnityEditor.UI");
|
||||
if (uiEditorAssembly != null)
|
||||
{
|
||||
Type menuOptionType = uiEditorAssembly.GetType("UnityEditor.UI.MenuOptions");
|
||||
if (menuOptionType != null)
|
||||
{
|
||||
MethodInfo miPlaceUIElementRoot = menuOptionType.GetMethod(
|
||||
"PlaceUIElementRoot",
|
||||
BindingFlags.NonPublic | BindingFlags.Static);
|
||||
if (miPlaceUIElementRoot != null)
|
||||
{
|
||||
PlaceUIElementRoot = Delegate.CreateDelegate(
|
||||
typeof(Action<GameObject, MenuCommand>),
|
||||
miPlaceUIElementRoot)
|
||||
as Action<GameObject, MenuCommand>;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8518bb829bc508049a52f0606b4f43a5
|
||||
timeCreated: 1533042733
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,34 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="ScrollViewExEditor.cs" company="AillieoTech">
|
||||
// Copyright (c) AillieoTech. All rights reserved.
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace TapTap.UI.AillieoTech
|
||||
{
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor(typeof(ScrollViewEx))]
|
||||
public class ScrollViewExEditor : ScrollViewEditor
|
||||
{
|
||||
private SerializedProperty pageSize;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
this.pageSize = this.serializedObject.FindProperty("pageSize");
|
||||
}
|
||||
|
||||
protected override void DrawConfigInfo()
|
||||
{
|
||||
base.DrawConfigInfo();
|
||||
EditorGUILayout.PropertyField(this.pageSize);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/UI/DynamicScrollViewEx", false, 90)]
|
||||
private static void AddScrollViewEx(MenuCommand menuCommand)
|
||||
{
|
||||
InternalAddScrollView<ScrollViewEx>(menuCommand);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 12cd1055a4162f842842a60918857100
|
||||
timeCreated: 1533042733
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "TapTap.UI.Editor",
|
||||
"references": [
|
||||
"GUID:0b3f64ec33f5b4da98a17367a35b82f2"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d577628a069ab4cdc87654cc7ac4b6a4
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 64083c9579506486096d4c0d2a2a8932
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a2d6d99aa661049e6a8c5c365f940e5d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using TapTap.Common.Editor;
|
||||
|
||||
namespace TapTap.Common.Mobile.Editor {
|
||||
public class TapCommonMobileProcessBuild : SDKLinkProcessBuild {
|
||||
public override int callbackOrder => 0;
|
||||
|
||||
public override string LinkPath => "TapTap/Common/link.xml";
|
||||
|
||||
public override LinkedAssembly[] LinkedAssemblies => new LinkedAssembly[] {
|
||||
new LinkedAssembly { Fullname = "TapTap.Common.Runtime" },
|
||||
new LinkedAssembly { Fullname = "TapTap.Common.Mobile.Runtime" }
|
||||
};
|
||||
|
||||
public override Func<BuildReport, bool> IsTargetPlatform => (report) => {
|
||||
return BuildTargetUtils.IsSupportMobile(report.summary.platform);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2f0b99f7553794a8791cee0ebb2c953a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "TapTap.Common.Mobile.Editor",
|
||||
"references": [
|
||||
"GUID:616cea76def2d4f059b94440fc8cc03d"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 747e53b1749584bae9386571797e5eb5
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 23fedb802d153432e9b7e8e2dca2d3f4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d613cbf7e66b4849b75f0c17665043d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7665fa69688034f88b96e3926a190a78
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,80 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e01d04d4b428e45508e87e973497dbe5
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 0
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: ARM64
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f0fa75c5d7ce549c08ab2fb6353034b8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,80 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 495d1cc3f857842969280c751449b7b9
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 0
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2cb022b37682044e79bd0db5efd0a371
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,80 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 31dfb9eef734041ab91abbac30e8fc0e
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 0
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8357dd3b84a964d1595e1977d6d63177
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
public class EngineBridge
|
||||
{
|
||||
private static volatile EngineBridge _sInstance;
|
||||
|
||||
private readonly IBridge _bridge;
|
||||
|
||||
private static readonly object Locker = new object();
|
||||
|
||||
public static EngineBridge GetInstance()
|
||||
{
|
||||
lock (Locker)
|
||||
{
|
||||
if (_sInstance == null)
|
||||
{
|
||||
_sInstance = new EngineBridge();
|
||||
}
|
||||
}
|
||||
|
||||
return _sInstance;
|
||||
}
|
||||
|
||||
private EngineBridge()
|
||||
{
|
||||
if (Platform.IsAndroid())
|
||||
{
|
||||
_bridge = BridgeAndroid.GetInstance();
|
||||
}
|
||||
else if (Platform.IsIOS())
|
||||
{
|
||||
_bridge = BridgeIOS.GetInstance();
|
||||
}
|
||||
}
|
||||
|
||||
public void Register(string serviceClzName, string serviceImplName)
|
||||
{
|
||||
_bridge?.Register(serviceClzName, serviceImplName);
|
||||
}
|
||||
|
||||
public void CallHandler(Command command)
|
||||
{
|
||||
_bridge?.Call(command);
|
||||
}
|
||||
|
||||
public void CallHandler(Command command, Action<Result> action)
|
||||
{
|
||||
_bridge?.Call(command, action);
|
||||
}
|
||||
|
||||
public Task<Result> Emit(Command command)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<Result>();
|
||||
CallHandler(command, result =>
|
||||
{
|
||||
tcs.TrySetResult(result);
|
||||
});
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
public static bool CheckResult(Result result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(result.content);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a59ea35d6e5c450194ab8bd34973ae7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
public class BridgeAndroid : IBridge
|
||||
{
|
||||
private string bridgeJavaClz = "com.tds.common.bridge.Bridge";
|
||||
|
||||
private string instanceMethod = "getInstance";
|
||||
|
||||
private string registerHandlerMethod = "registerHandler";
|
||||
|
||||
private string callHandlerMethod = "callHandler";
|
||||
|
||||
private string initMethod = "init";
|
||||
|
||||
private string registerMethod = "register";
|
||||
|
||||
private readonly AndroidJavaObject _mAndroidBridge;
|
||||
|
||||
private static readonly BridgeAndroid SInstance = new BridgeAndroid();
|
||||
|
||||
public static BridgeAndroid GetInstance()
|
||||
{
|
||||
return SInstance;
|
||||
}
|
||||
|
||||
private BridgeAndroid()
|
||||
{
|
||||
var mCurrentActivity =
|
||||
new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
|
||||
_mAndroidBridge = new AndroidJavaClass(bridgeJavaClz).CallStatic<AndroidJavaObject>(instanceMethod);
|
||||
_mAndroidBridge.Call(initMethod, mCurrentActivity);
|
||||
}
|
||||
|
||||
public void Register(string serviceClzName, string serviceImplName)
|
||||
{
|
||||
if (_mAndroidBridge == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var serviceClass = new AndroidJavaClass(serviceClzName);
|
||||
var serviceImpl = new AndroidJavaObject(serviceImplName);
|
||||
_mAndroidBridge.Call(registerMethod, serviceClass, serviceImpl);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log("register Failed:" + e);
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
public void Call(Command command, Action<Result> action)
|
||||
{
|
||||
_mAndroidBridge?.Call(registerHandlerMethod, command.ToJSON(), new BridgeCallback(action));
|
||||
}
|
||||
|
||||
public void Call(Command command)
|
||||
{
|
||||
_mAndroidBridge?.Call(callHandlerMethod, command.ToJSON());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a30539bf2c5c4b9e891293fc7bd563b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
|
||||
public class BridgeCallback : AndroidJavaProxy
|
||||
{
|
||||
Action<Result> callback;
|
||||
|
||||
public BridgeCallback(Action<Result> action) :
|
||||
base(new AndroidJavaClass("com.tds.common.bridge.BridgeCallback"))
|
||||
{
|
||||
this.callback = action;
|
||||
}
|
||||
|
||||
public override AndroidJavaObject Invoke(string method, object[] args)
|
||||
{
|
||||
if (method.Equals("onResult"))
|
||||
{
|
||||
if (args[0] is string)
|
||||
{
|
||||
string result = (string)(args[0]);
|
||||
callback(new Result(result));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0c7e2835d962a4a4997c93212b4a1171
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,91 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
public class BridgeIOS : IBridge
|
||||
{
|
||||
private static readonly BridgeIOS SInstance = new BridgeIOS();
|
||||
|
||||
private readonly ConcurrentDictionary<string, Action<Result>> dic;
|
||||
|
||||
public static BridgeIOS GetInstance()
|
||||
{
|
||||
return SInstance;
|
||||
}
|
||||
|
||||
private BridgeIOS()
|
||||
{
|
||||
dic = new ConcurrentDictionary<string, Action<Result>>();
|
||||
}
|
||||
|
||||
private ConcurrentDictionary<string, Action<Result>> GetConcurrentDictionary()
|
||||
{
|
||||
return dic;
|
||||
}
|
||||
|
||||
private delegate void EngineBridgeDelegate(string result);
|
||||
|
||||
[AOT.MonoPInvokeCallbackAttribute(typeof(EngineBridgeDelegate))]
|
||||
static void engineBridgeDelegate(string resultJson)
|
||||
{
|
||||
var result = new Result(resultJson);
|
||||
|
||||
var actionDic = GetInstance().GetConcurrentDictionary();
|
||||
|
||||
Action<Result> action = null;
|
||||
|
||||
if (actionDic != null && actionDic.ContainsKey(result.callbackId))
|
||||
{
|
||||
action = actionDic[result.callbackId];
|
||||
}
|
||||
|
||||
if (action != null)
|
||||
{
|
||||
action(result);
|
||||
if (result.onceTime && BridgeIOS.GetInstance().GetConcurrentDictionary()
|
||||
.TryRemove(result.callbackId, out Action<Result> outAction))
|
||||
{
|
||||
Debug.Log($"TapSDK resolved current Action:{result.callbackId}");
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"TapSDK iOS BridgeAction last Count:{BridgeIOS.GetInstance().GetConcurrentDictionary().Count}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Register(string serviceClz, string serviceImp)
|
||||
{
|
||||
//IOS无需注册
|
||||
}
|
||||
|
||||
public void Call(Command command)
|
||||
{
|
||||
#if UNITY_IOS
|
||||
callHandler(command.ToJSON());
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Call(Command command, Action<Result> action)
|
||||
{
|
||||
if (!command.callback || string.IsNullOrEmpty(command.callbackId)) return;
|
||||
if (!dic.ContainsKey(command.callbackId))
|
||||
{
|
||||
dic.GetOrAdd(command.callbackId, action);
|
||||
}
|
||||
#if UNITY_IOS
|
||||
registerHandler(command.ToJSON(), engineBridgeDelegate);
|
||||
#endif
|
||||
}
|
||||
#if UNITY_IOS
|
||||
[DllImport("__Internal")]
|
||||
private static extern void callHandler(string command);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void registerHandler(string command, EngineBridgeDelegate engineBridgeDelegate);
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f5a68a7cfba514945b6fba56b7086ea8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,119 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
[SerializeField] public string service;
|
||||
[SerializeField] public string method;
|
||||
[SerializeField] public string args;
|
||||
[SerializeField] public bool callback;
|
||||
[SerializeField] public string callbackId;
|
||||
[SerializeField] public bool onceTime;
|
||||
|
||||
public Command()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Command(string json)
|
||||
{
|
||||
JsonUtility.FromJsonOverwrite(json, this);
|
||||
}
|
||||
|
||||
public string ToJSON()
|
||||
{
|
||||
return JsonUtility.ToJson(this);
|
||||
}
|
||||
|
||||
public Command(string service, string method, bool callback, Dictionary<string, object> dic)
|
||||
{
|
||||
this.args = dic == null ? null : Json.Serialize(dic);
|
||||
this.service = service;
|
||||
this.method = method;
|
||||
this.callback = callback;
|
||||
this.callbackId = this.callback ? TapUUID.UUID() : null;
|
||||
}
|
||||
|
||||
public Command(string service, string method, bool callback, bool onceTime, Dictionary<string, object> dic)
|
||||
{
|
||||
this.args = dic == null ? null : Json.Serialize(dic);
|
||||
this.service = service;
|
||||
this.method = method;
|
||||
this.callback = callback;
|
||||
this.callbackId = this.callback ? TapUUID.UUID() : null;
|
||||
this.onceTime = onceTime;
|
||||
}
|
||||
|
||||
public class Builder
|
||||
{
|
||||
private string service;
|
||||
|
||||
private string method;
|
||||
|
||||
private bool callback;
|
||||
|
||||
private string callbackId;
|
||||
|
||||
private bool onceTime;
|
||||
|
||||
private Dictionary<string, object> args;
|
||||
|
||||
public Builder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Builder Service(string service)
|
||||
{
|
||||
this.service = service;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder Method(string method)
|
||||
{
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder OnceTime(bool onceTime)
|
||||
{
|
||||
this.onceTime = onceTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder Args(Dictionary<string, object> dic)
|
||||
{
|
||||
this.args = dic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder Args(string key, object value)
|
||||
{
|
||||
if (this.args == null)
|
||||
{
|
||||
this.args = new Dictionary<string, object>();
|
||||
}
|
||||
if(value is Dictionary<string,object>)
|
||||
{
|
||||
value = Json.Serialize(value);
|
||||
}
|
||||
this.args.Add(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder Callback(bool callback)
|
||||
{
|
||||
this.callback = callback;
|
||||
this.callbackId = this.callback ? TapUUID.UUID() : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command CommandBuilder()
|
||||
{
|
||||
return new Command(this.service, this.method, this.callback, this.onceTime, this.args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1270e5e2ef8de406c877f8c7b0ba8bca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
namespace TapTap.Common
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const string VersionKey = "Engine-Version";
|
||||
|
||||
public const string PlatformKey = "Engine-Platform";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89331e94880b1436bb7c6286193d6e1c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
public interface IBridge
|
||||
{
|
||||
void Register(string serviceClzName, string serviceImplName);
|
||||
|
||||
void Call(Command command);
|
||||
|
||||
void Call(Command command, Action<Result> action);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 772dceb95dc5a432a8ac9f9152693bde
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
public interface ITapCommon
|
||||
{
|
||||
void Init(TapConfig config);
|
||||
|
||||
void GetRegionCode(Action<bool> callback);
|
||||
void GetDeviceId(Action<string> callback);
|
||||
void GetDeviceType(Action<int> callback);
|
||||
|
||||
void IsTapTapInstalled(Action<bool> callback);
|
||||
|
||||
void IsTapTapGlobalInstalled(Action<bool> callback);
|
||||
|
||||
void UpdateGameInTapTap(string appId, Action<bool> callback);
|
||||
|
||||
void UpdateGameInTapGlobal(string appId, Action<bool> callback);
|
||||
|
||||
void OpenReviewInTapTap(string appId, Action<bool> callback);
|
||||
|
||||
void OpenReviewInTapGlobal(string appId, Action<bool> callback);
|
||||
|
||||
void SetLanguage(TapLanguage language);
|
||||
|
||||
void SetXua();
|
||||
|
||||
void RegisterProperties(string key, ITapPropertiesProxy proxy);
|
||||
|
||||
void UseNativeDataInCore(bool enable);
|
||||
void SetDurationStatisticsEnabled(bool enable);
|
||||
|
||||
void AddHost(string host, string replaceHost);
|
||||
|
||||
Task<bool> UpdateGameAndFailToWebInTapTap(string appId);
|
||||
|
||||
Task<bool> UpdateGameAndFailToWebInTapGlobal(string appId);
|
||||
|
||||
Task<bool> UpdateGameAndFailToWebInTapTap(string appId, string webUrl);
|
||||
|
||||
Task<bool> UpdateGameAndFailToWebInTapGlobal(string appId, string webUrl);
|
||||
|
||||
Task<bool> OpenWebDownloadUrlOfTapTap(string appId);
|
||||
|
||||
Task<bool> OpenWebDownloadUrlOfTapGlobal(string appId);
|
||||
|
||||
Task<bool> OpenWebDownloadUrl(string url);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class CommonRegionWrapper
|
||||
{
|
||||
public bool isMainland;
|
||||
|
||||
public CommonRegionWrapper(string json)
|
||||
{
|
||||
Dictionary<string, object> dic = Json.Deserialize(json) as Dictionary<string, object>;
|
||||
isMainland = SafeDictionary.GetValue<bool>(dic, "isMainland");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fce5579d1046b41d998725853e4acecb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
[Serializable]
|
||||
public class Result
|
||||
{
|
||||
public static int RESULT_SUCCESS = 0;
|
||||
|
||||
public static int RESULT_ERROR = -1;
|
||||
|
||||
[SerializeField] public int code;
|
||||
|
||||
[SerializeField] public string message;
|
||||
|
||||
[SerializeField] public string content;
|
||||
|
||||
[SerializeField] public string callbackId;
|
||||
|
||||
[SerializeField] public bool onceTime;
|
||||
|
||||
public Result()
|
||||
{
|
||||
}
|
||||
|
||||
public Result(string json)
|
||||
{
|
||||
JsonUtility.FromJsonOverwrite(json, this);
|
||||
}
|
||||
|
||||
public string ToJSON()
|
||||
{
|
||||
return JsonUtility.ToJson(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 02e98ca9db68c4e439977af38833877d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,589 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using LC.Newtonsoft.Json;
|
||||
using TapTap.Common.Internal.Http;
|
||||
|
||||
namespace TapTap.Common
|
||||
{
|
||||
public class TapCommonImpl : ITapCommon
|
||||
{
|
||||
private static readonly string TAP_COMMON_SERVICE = "TDSCommonService";
|
||||
|
||||
private readonly AndroidJavaObject _proxyServiceImpl;
|
||||
|
||||
private readonly ConcurrentDictionary<string, ITapPropertiesProxy> _propertiesProxies;
|
||||
|
||||
public TapHttpClient HttpClient {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
private TapCommonImpl()
|
||||
{
|
||||
EngineBridge.GetInstance().Register("com.tds.common.wrapper.TDSCommonService",
|
||||
"com.tds.common.wrapper.TDSCommonServiceImpl");
|
||||
|
||||
_proxyServiceImpl = new AndroidJavaObject("com.tds.common.wrapper.TDSCommonServiceImpl");
|
||||
|
||||
_propertiesProxies = new ConcurrentDictionary<string, ITapPropertiesProxy>();
|
||||
}
|
||||
|
||||
private static volatile TapCommonImpl _sInstance;
|
||||
|
||||
private static readonly object Locker = new object();
|
||||
|
||||
public static TapCommonImpl GetInstance()
|
||||
{
|
||||
lock (Locker)
|
||||
{
|
||||
if (_sInstance == null)
|
||||
{
|
||||
_sInstance = new TapCommonImpl();
|
||||
}
|
||||
}
|
||||
|
||||
return _sInstance;
|
||||
}
|
||||
|
||||
public void Init(TapConfig config)
|
||||
{
|
||||
var commandBuilder = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("initWithConfig")
|
||||
.Args("initWithConfig", JsonConvert.SerializeObject(config.ToDict()))
|
||||
.Args("versionName", Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
|
||||
var command = commandBuilder.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command);
|
||||
|
||||
HttpClient = new TapHttpClient(config.ClientID, config.ClientToken, config.ServerURL);
|
||||
}
|
||||
|
||||
public void GetDeviceId(Action<string> callback){
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("getDeviceId").Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
EngineBridge.GetInstance().CallHandler(command, (result) =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback("error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback("error");
|
||||
return;
|
||||
}
|
||||
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<string>(dic, "deviceId"));
|
||||
});
|
||||
}
|
||||
|
||||
public void GetDeviceType(Action<int> callback){
|
||||
if (Platform.IsAndroid()){
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("getDeviceType").Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
EngineBridge.GetInstance().CallHandler(command, (result) =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<int>(dic, "deviceType"));
|
||||
});
|
||||
}else{
|
||||
callback?.Invoke((int)com.taptap.tapsdk.bindings.csharp.DeviceType.Local);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetXua()
|
||||
{
|
||||
try
|
||||
{
|
||||
var xua = new Dictionary<string, string>
|
||||
{
|
||||
{Constants.VersionKey, Assembly.GetExecutingAssembly().GetName().Version.ToString()},
|
||||
{Constants.PlatformKey, "Unity"}
|
||||
};
|
||||
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("setXUA")
|
||||
.Args("setXUA", Json.Serialize(xua)).CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"exception:{e}");
|
||||
}
|
||||
}
|
||||
|
||||
public void GetRegionCode(Action<bool> callback)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("getRegionCode").Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
EngineBridge.GetInstance().CallHandler(command, (result) =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var wrapper = new CommonRegionWrapper(result.content);
|
||||
callback(wrapper.isMainland);
|
||||
});
|
||||
}
|
||||
|
||||
public void IsTapTapInstalled(Action<bool> callback)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("isTapTapInstalled")
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command, (result) =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var dlc = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<bool>(dlc, "isTapTapInstalled"));
|
||||
});
|
||||
}
|
||||
|
||||
public void IsTapTapGlobalInstalled(Action<bool> callback)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("isTapGlobalInstalled")
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command, (result) =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var dlc = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<bool>(dlc, "isTapGlobalInstalled"));
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateGameInTapTap(string appId, Action<bool> callback)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("updateGameInTapTap")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command, (result) =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var dlc = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<bool>(dlc, "updateGameInTapTap"));
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateGameInTapGlobal(string appId, Action<bool> callback)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("updateGameInTapGlobal")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command, result =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var dlc = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<bool>(dlc, "updateGameInTapGlobal"));
|
||||
});
|
||||
}
|
||||
|
||||
public void OpenReviewInTapTap(string appId, Action<bool> callback)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("openReviewInTapTap")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command, result =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var dlc = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<bool>(dlc, "openReviewInTapTap"));
|
||||
});
|
||||
}
|
||||
|
||||
public void OpenReviewInTapGlobal(string appId, Action<bool> callback)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("openReviewInTapGlobal")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command, result =>
|
||||
{
|
||||
if (result.code != Result.RESULT_SUCCESS)
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(result.content))
|
||||
{
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var dlc = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
callback(SafeDictionary.GetValue<bool>(dlc, "openReviewInTapGlobal"));
|
||||
});
|
||||
}
|
||||
|
||||
public void SetLanguage(TapLanguage language)
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("setPreferredLanguage")
|
||||
.Args("preferredLanguage", (int) language)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command);
|
||||
}
|
||||
|
||||
|
||||
public void RegisterProperties(string key, ITapPropertiesProxy proxy)
|
||||
{
|
||||
if (Platform.IsAndroid())
|
||||
{
|
||||
_proxyServiceImpl?.Call("registerProperties", key, new TapPropertiesProxy(proxy));
|
||||
}
|
||||
else if (Platform.IsIOS())
|
||||
{
|
||||
#if UNITY_IOS
|
||||
if (_propertiesProxies.TryAdd(key, proxy))
|
||||
{
|
||||
Debug.Log($"register Properties:{Json.Serialize(_propertiesProxies)}");
|
||||
registerProperties(key, TapPropertiesDelegateProxy);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Debug.Log($"registerProperty:{key == null} value:{proxy == null}");
|
||||
}
|
||||
public void UseNativeDataInCore(bool enable)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("useNativeDataInCore")
|
||||
.Args("useNativeDataInCore", enable)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command);
|
||||
|
||||
command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("setDurationStatisticsEnabled")
|
||||
.Args("setDurationStatisticsEnabled", enable)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogErrorFormat("useNativeDataInCore & setDurationStatisticsEnabled error:{0}\n{1}", e.Message, e.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDurationStatisticsEnabled(bool enable)
|
||||
{
|
||||
Debug.Log($"SetDurationStatisticsEnabled:{enable}");
|
||||
TapTap.Common.TapCommon.DisableDurationStatistics = !enable;
|
||||
}
|
||||
|
||||
#if UNITY_IOS
|
||||
private delegate string TapPropertiesDelegate(string key);
|
||||
|
||||
[AOT.MonoPInvokeCallbackAttribute(typeof(TapPropertiesDelegate))]
|
||||
private static string TapPropertiesDelegateProxy(string key)
|
||||
{
|
||||
Debug.Log($"key:{key} register Properties:{Json.Serialize(_sInstance._propertiesProxies)}");
|
||||
var proxy = _sInstance._propertiesProxies[key];
|
||||
return proxy?.GetProperties();
|
||||
}
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void registerProperties(string key, TapPropertiesDelegate propertiesDelegate);
|
||||
#endif
|
||||
|
||||
|
||||
public void AddHost(string host, string replaceHost)
|
||||
{
|
||||
Debug.LogFormat($"addHost host:{host} replaceHost:{replaceHost}");
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("addReplacedHostPair")
|
||||
.Args("hostToBeReplaced", host)
|
||||
.Args("replacedHost", replaceHost)
|
||||
.CommandBuilder();
|
||||
|
||||
EngineBridge.GetInstance().CallHandler(command);
|
||||
}
|
||||
|
||||
private static void CheckPlatformSupport()
|
||||
{
|
||||
if (Platform.IsIOS())
|
||||
{
|
||||
throw new TapException(-1, "iOS Platform dont support current func");
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckResult(Result result)
|
||||
{
|
||||
if (!EngineBridge.CheckResult(result))
|
||||
{
|
||||
throw new TapException(-1, $"TapBridge dont support this Command:{result.message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateGameAndFailToWebInTapTap(string appId)
|
||||
{
|
||||
CheckPlatformSupport();
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("updateGameAndFailToWebInTapTap")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
var result = await EngineBridge.GetInstance().Emit(command);
|
||||
CheckResult(result);
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
return SafeDictionary.GetValue<bool>(dic, "result");
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateGameAndFailToWebInTapGlobal(string appId)
|
||||
{
|
||||
CheckPlatformSupport();
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("updateGameAndFailToWebInTapGlobal")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
var result = await EngineBridge.GetInstance().Emit(command);
|
||||
CheckResult(result);
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
return SafeDictionary.GetValue<bool>(dic, "result");
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateGameAndFailToWebInTapTap(string appId, string webUrl)
|
||||
{
|
||||
CheckPlatformSupport();
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("updateGameAndFailToWebInTapTapWithWebUrl")
|
||||
.Args("appId", appId)
|
||||
.Args("webUrl", webUrl)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
var result = await EngineBridge.GetInstance().Emit(command);
|
||||
CheckResult(result);
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
return SafeDictionary.GetValue<bool>(dic, "result");
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateGameAndFailToWebInTapGlobal(string appId, string webUrl)
|
||||
{
|
||||
CheckPlatformSupport();
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("updateGameAndFailToWebInTapGlobalWithWebUrl")
|
||||
.Args("appId", appId)
|
||||
.Args("webUrl", webUrl)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
var result = await EngineBridge.GetInstance().Emit(command);
|
||||
CheckResult(result);
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
return SafeDictionary.GetValue<bool>(dic, "result");
|
||||
}
|
||||
|
||||
public async Task<bool> OpenWebDownloadUrlOfTapTap(string appId)
|
||||
{
|
||||
CheckPlatformSupport();
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("openWebDownloadUrlOfTapTap")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
var result = await EngineBridge.GetInstance().Emit(command);
|
||||
CheckResult(result);
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
return SafeDictionary.GetValue<bool>(dic, "result");
|
||||
}
|
||||
|
||||
public async Task<bool> OpenWebDownloadUrlOfTapGlobal(string appId)
|
||||
{
|
||||
CheckPlatformSupport();
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("openWebDownloadUrlOfTapGlobal")
|
||||
.Args("appId", appId)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
var result = await EngineBridge.GetInstance().Emit(command);
|
||||
CheckResult(result);
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
return SafeDictionary.GetValue<bool>(dic, "result");
|
||||
}
|
||||
|
||||
public async Task<bool> OpenWebDownloadUrl(string url)
|
||||
{
|
||||
CheckPlatformSupport();
|
||||
var command = new Command.Builder()
|
||||
.Service(TAP_COMMON_SERVICE)
|
||||
.Method("openWebDownloadUrl")
|
||||
.Args("appId", url)
|
||||
.Callback(true)
|
||||
.OnceTime(true)
|
||||
.CommandBuilder();
|
||||
|
||||
var result = await EngineBridge.GetInstance().Emit(command);
|
||||
CheckResult(result);
|
||||
var dic = Json.Deserialize(result.content) as Dictionary<string, object>;
|
||||
return SafeDictionary.GetValue<bool>(dic, "result");
|
||||
}
|
||||
|
||||
private class TapPropertiesProxy : AndroidJavaProxy
|
||||
{
|
||||
private readonly ITapPropertiesProxy _properties;
|
||||
|
||||
public TapPropertiesProxy(ITapPropertiesProxy properties) :
|
||||
base(new AndroidJavaClass("com.tds.common.wrapper.TapPropertiesProxy"))
|
||||
{
|
||||
_properties = properties;
|
||||
}
|
||||
|
||||
public override AndroidJavaObject Invoke(string methodName, object[] args)
|
||||
{
|
||||
return _properties != null
|
||||
? new AndroidJavaObject("java.lang.String", _properties.GetProperties())
|
||||
: base.Invoke(methodName, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1d8e2920a836a48d59ea5221ded9af59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,125 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TapTap.Common.Internal;
|
||||
|
||||
namespace TapTap.Common.Mobile
|
||||
{
|
||||
public class TapCommonMobile : ITapCommonPlatform
|
||||
{
|
||||
public void Init(TapConfig config)
|
||||
{
|
||||
TapCommon.UseNativeDataInCore(false);
|
||||
TapCommonImpl.GetInstance().Init(config);
|
||||
}
|
||||
|
||||
public void GetDeviceId(Action<string> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().GetDeviceId(callback);
|
||||
}
|
||||
|
||||
public void GetDeviceType(Action<int> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().GetDeviceType(callback);
|
||||
}
|
||||
|
||||
public void GetRegionCode(Action<bool> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().GetRegionCode(callback);
|
||||
}
|
||||
|
||||
public void IsTapTapInstalled(Action<bool> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().IsTapTapInstalled(callback);
|
||||
}
|
||||
|
||||
public void IsTapTapGlobalInstalled(Action<bool> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().IsTapTapGlobalInstalled(callback);
|
||||
}
|
||||
|
||||
public void UpdateGameInTapTap(string appId, Action<bool> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().UpdateGameInTapTap(appId, callback);
|
||||
}
|
||||
|
||||
public void UpdateGameInTapGlobal(string appId, Action<bool> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().UpdateGameInTapGlobal(appId, callback);
|
||||
}
|
||||
|
||||
public void OpenReviewInTapTap(string appId, Action<bool> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().OpenReviewInTapTap(appId, callback);
|
||||
}
|
||||
|
||||
public void OpenReviewInTapGlobal(string appId, Action<bool> callback)
|
||||
{
|
||||
TapCommonImpl.GetInstance().OpenReviewInTapGlobal(appId, callback);
|
||||
}
|
||||
|
||||
public void SetXua()
|
||||
{
|
||||
TapCommonImpl.GetInstance().SetXua();
|
||||
}
|
||||
|
||||
public void SetLanguage(TapLanguage language)
|
||||
{
|
||||
TapCommonImpl.GetInstance().SetLanguage(language);
|
||||
}
|
||||
|
||||
public void RegisterProperties(string key, ITapPropertiesProxy proxy)
|
||||
{
|
||||
TapCommonImpl.GetInstance().RegisterProperties(key, proxy);
|
||||
}
|
||||
|
||||
public void UseNativeDataInCore(bool enable)
|
||||
{
|
||||
TapCommonImpl.GetInstance().UseNativeDataInCore(enable);
|
||||
}
|
||||
|
||||
public void SetDurationStatisticsEnabled(bool enable)
|
||||
{
|
||||
TapCommonImpl.GetInstance().SetDurationStatisticsEnabled(enable);
|
||||
}
|
||||
|
||||
public void AddHost(string host, string replaceHost)
|
||||
{
|
||||
TapCommonImpl.GetInstance().AddHost(host, replaceHost);
|
||||
}
|
||||
|
||||
public Task<bool> UpdateGameAndFailToWebInTapTap(string appId)
|
||||
{
|
||||
return TapCommonImpl.GetInstance().UpdateGameAndFailToWebInTapTap(appId);
|
||||
}
|
||||
|
||||
public Task<bool> UpdateGameAndFailToWebInTapGlobal(string appId)
|
||||
{
|
||||
return TapCommonImpl.GetInstance().UpdateGameAndFailToWebInTapGlobal(appId);
|
||||
}
|
||||
|
||||
public Task<bool> UpdateGameAndFailToWebInTapTap(string appId, string webUrl)
|
||||
{
|
||||
return TapCommonImpl.GetInstance().UpdateGameAndFailToWebInTapTap(appId, webUrl);
|
||||
}
|
||||
|
||||
public Task<bool> UpdateGameAndFailToWebInTapGlobal(string appId, string webUrl)
|
||||
{
|
||||
return TapCommonImpl.GetInstance().UpdateGameAndFailToWebInTapGlobal(appId, webUrl);
|
||||
}
|
||||
|
||||
public Task<bool> OpenWebDownloadUrlOfTapTap(string appId)
|
||||
{
|
||||
return TapCommonImpl.GetInstance().OpenWebDownloadUrlOfTapTap(appId);
|
||||
}
|
||||
|
||||
public Task<bool> OpenWebDownloadUrlOfTapGlobal(string appId)
|
||||
{
|
||||
return TapCommonImpl.GetInstance().OpenWebDownloadUrlOfTapGlobal(appId);
|
||||
}
|
||||
|
||||
public Task<bool> OpenWebDownloadUrl(string url)
|
||||
{
|
||||
return TapCommonImpl.GetInstance().OpenWebDownloadUrl(url);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1b2a0081fb3044394b8a026d786e4024
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "TapTap.Common.Mobile.Runtime",
|
||||
"references": [
|
||||
"GUID:0b3f64ec33f5b4da98a17367a35b82f2"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Android",
|
||||
"iOS"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 43c632eee0a6f42cdaf21080b154f3a1
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
namespace TapTap.Common
|
||||
{
|
||||
public class TapUUID
|
||||
{
|
||||
public static string UUID(){
|
||||
return System.Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f6eea7b0d0fc4a05b8681af19423c6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 72ddac62e7598413680ccc6ef4858979
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c40d795a083b457fa3d923415533822c
|
||||
timeCreated: 1616744098
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9c15be9bece843a4b6998999a603f389
|
||||
timeCreated: 1616744107
|
Binary file not shown.
|
@ -0,0 +1,32 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 185482ed3679f42e89ade5947bbe092d
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 73b3691a973514db19fd1e16fe5a6ba4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,81 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e71a490d240664c03ac26831af61700d
|
||||
folderAsset: yes
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 0
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 0
|
||||
Exclude Win64: 0
|
||||
Exclude iOS: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
DefaultValueInitialized: true
|
||||
OS: OSX
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<<< HEAD:Assets/TapTap/Common/Plugins/MacOS/tds_core.framework/Headers.meta
|
||||
guid: 8371d753a0e4c4befb31d4f190bb6ce4
|
||||
========
|
||||
guid: 28c5ee5fa1ba94d9a8343d3614d34cef
|
||||
>>>>>>>> feat/xd-tap-login:Assets/TapTap/Common/Plugins/MacOS/tds_core.framework/Resources.meta
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// Created by 甘尧 on 2023/7/7.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tapsdk::platform {
|
||||
|
||||
enum class DeviceType {
|
||||
Local,
|
||||
Sandbox,
|
||||
Cloud
|
||||
};
|
||||
|
||||
class Window {
|
||||
public:
|
||||
// 当 App 进入前台
|
||||
static void OnForeground();
|
||||
// 当 App 进入后台
|
||||
static void OnBackground();
|
||||
};
|
||||
|
||||
class Device {
|
||||
public:
|
||||
static void SetCurrent(const std::shared_ptr<Device> &device);
|
||||
static std::shared_ptr<Device> GetCurrent();
|
||||
|
||||
virtual ~Device() = default;
|
||||
|
||||
// 当前 Device ID
|
||||
virtual std::string GetDeviceID() = 0;
|
||||
// 缓存目录
|
||||
virtual std::string GetCacheDir() = 0;
|
||||
// CA 证书目录 (可选)
|
||||
virtual std::string GetCaCertDir() = 0;
|
||||
// 设备类型
|
||||
virtual DeviceType GetDeviceType();
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 79e571ceda3ec4319935dd13c243fb24
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tapsdk {
|
||||
|
||||
class TDSUser;
|
||||
|
||||
enum class Region : int {
|
||||
CN = 0,
|
||||
Global
|
||||
};
|
||||
|
||||
class TDSUser {
|
||||
public:
|
||||
static void SetCurrent(const std::shared_ptr<TDSUser>& user);
|
||||
static std::shared_ptr<TDSUser> GetCurrent();
|
||||
|
||||
TDSUser(const std::string& user_id = {});
|
||||
|
||||
virtual ~TDSUser() = default;
|
||||
|
||||
virtual std::string GetUserId();
|
||||
virtual std::string GetUserName() = 0;
|
||||
virtual bool ContainTapInfo() = 0;
|
||||
private:
|
||||
std::string user_id;
|
||||
};
|
||||
|
||||
class Game {
|
||||
public:
|
||||
static void SetCurrent(const std::shared_ptr<Game> &game);
|
||||
static std::shared_ptr<Game> GetCurrent();
|
||||
|
||||
virtual ~Game() = default;
|
||||
|
||||
// 游戏 Game ID
|
||||
virtual std::string GetGameID() = 0;
|
||||
|
||||
// 游戏包名/Bundle ID
|
||||
virtual std::string GetPackageName() = 0;
|
||||
};
|
||||
|
||||
struct Config {
|
||||
bool enable_duration_statistics = false;
|
||||
Region region = Region::CN;
|
||||
};
|
||||
|
||||
bool Init(const Config &config);
|
||||
|
||||
} // namespace tapsdk
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 19201ef530430481f93f19752c30b0a1
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 28c5ee5fa1ba94d9a8343d3614d34cef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>tds_core</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.taptap.tapsdk</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string></string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string></string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 620a006473d4e4f70ab7e9225821f923
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 66f4b6bfb60014034892e2ce0dcdb36e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1f5b2af7d9c384c0a8491862c55e1090
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8e15b89c7af4a41e8bd275f401fa3086
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// Created by 甘尧 on 2023/7/7.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tapsdk::platform {
|
||||
|
||||
enum class DeviceType {
|
||||
Local,
|
||||
Sandbox,
|
||||
Cloud
|
||||
};
|
||||
|
||||
class Window {
|
||||
public:
|
||||
// 当 App 进入前台
|
||||
static void OnForeground();
|
||||
// 当 App 进入后台
|
||||
static void OnBackground();
|
||||
};
|
||||
|
||||
class Device {
|
||||
public:
|
||||
static void SetCurrent(const std::shared_ptr<Device> &device);
|
||||
static std::shared_ptr<Device> GetCurrent();
|
||||
|
||||
virtual ~Device() = default;
|
||||
|
||||
// 当前 Device ID
|
||||
virtual std::string GetDeviceID() = 0;
|
||||
// 缓存目录
|
||||
virtual std::string GetCacheDir() = 0;
|
||||
// CA 证书目录 (可选)
|
||||
virtual std::string GetCaCertDir() = 0;
|
||||
// 设备类型
|
||||
virtual DeviceType GetDeviceType();
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1640c043947d1436797b23ddf7bb3f67
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tapsdk {
|
||||
|
||||
class TDSUser;
|
||||
|
||||
enum class Region : int {
|
||||
CN = 0,
|
||||
Global
|
||||
};
|
||||
|
||||
class TDSUser {
|
||||
public:
|
||||
static void SetCurrent(const std::shared_ptr<TDSUser>& user);
|
||||
static std::shared_ptr<TDSUser> GetCurrent();
|
||||
|
||||
TDSUser(const std::string& user_id = {});
|
||||
|
||||
virtual ~TDSUser() = default;
|
||||
|
||||
virtual std::string GetUserId();
|
||||
virtual std::string GetUserName() = 0;
|
||||
virtual bool ContainTapInfo() = 0;
|
||||
private:
|
||||
std::string user_id;
|
||||
};
|
||||
|
||||
class Game {
|
||||
public:
|
||||
static void SetCurrent(const std::shared_ptr<Game> &game);
|
||||
static std::shared_ptr<Game> GetCurrent();
|
||||
|
||||
virtual ~Game() = default;
|
||||
|
||||
// 游戏 Game ID
|
||||
virtual std::string GetGameID() = 0;
|
||||
|
||||
// 游戏包名/Bundle ID
|
||||
virtual std::string GetPackageName() = 0;
|
||||
};
|
||||
|
||||
struct Config {
|
||||
bool enable_duration_statistics = false;
|
||||
Region region = Region::CN;
|
||||
};
|
||||
|
||||
bool Init(const Config &config);
|
||||
|
||||
} // namespace tapsdk
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 597774ef282ac49c18af7ae975cb4fd7
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd9a234c699bf4c9e98e712487c51967
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>tds_core</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.taptap.tapsdk</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string></string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string></string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 528eb212cd91f41bfae2a61109fc536f
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue